1   package org.apache.maven.doxia.linkcheck;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.doxia.linkcheck.model.LinkcheckFile;
23  import org.apache.maven.doxia.linkcheck.model.LinkcheckModel;
24  import org.codehaus.plexus.PlexusTestCase;
25  
26  import java.io.File;
27  import java.util.HashMap;
28  import java.util.Iterator;
29  import java.util.Map;
30  
31  /**
32   * @author Ben Walding
33   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
34   * @version $Id: LinkCheckTest.java 800044 2009-08-02 12:28:50Z vsiveton $
35   */
36  public class AnchorLinkTest
37      extends PlexusTestCase
38  {
39      /**
40       * @throws Exception
41       */
42      public void testScan()
43          throws Exception
44      {
45          LinkCheck lc = (LinkCheck) lookup( LinkCheck.ROLE );
46          assertNotNull( lc );
47  
48          lc.setOnline( true ); // TODO: check if online
49  
50          lc.setBasedir( new File( getBasedir(), "src/test/resources/anchorTest" ) ); // TODO
51  
52          lc.setReportOutput( new File( getBasedir(), "target/linkcheck/anchorTest/linkcheck.xml" ) );
53  
54          lc.setReportOutputEncoding( "UTF-8" );
55  
56          lc.setLinkCheckCache( new File( getBasedir(), "target/linkcheck/anchorTest/linkcheck.cache" ) ); // TODO
57  
58          String[] excludes = new String[]
59          {
60              "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/",
61              "http://cvs.apache.org/viewcvs.cgi/mavenzz/"
62          };
63  
64          lc.setExcludedLinks( excludes );
65  
66          LinkcheckModel result = lc.execute();
67  
68          Iterator iter = result.getFiles().iterator();
69  
70          Map map = new HashMap();
71  
72          while ( iter.hasNext() )
73          {
74              LinkcheckFile ftc = (LinkcheckFile) iter.next();
75              map.put( ftc.getRelativePath(), ftc );
76          }
77  
78          assertEquals( "files.size()", 1, result.getFiles().size() );
79  
80          LinkcheckFile ftc = check( map, "testAnchor.html", 1 );
81  
82          //System.out.println("anchor test " + ftc.getResults());
83  
84          assertEquals( "Should have matched!", 1, ftc.getSuccessful() );
85          assertEquals( "Should have no failures!", 0, ftc.getUnsuccessful() );
86      }
87  
88      private LinkcheckFile check( Map map, String name, int linkCount )
89      {
90          LinkcheckFile ftc = (LinkcheckFile) map.get( name );
91  
92          assertNotNull( name + " = null!", ftc );
93  
94          assertEquals( name + ".getResults().size()", linkCount, ftc.getResults().size() );
95  
96          return ftc;
97      }
98  }