1 package org.apache.maven.plugin.linkcheck;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.log4j.BasicConfigurator;
22 import org.apache.log4j.Level;
23 import org.apache.log4j.Logger;
24
25 import java.io.File;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.Map;
29
30 import junit.framework.TestCase;
31
32 /**
33 * @author Ben Walding
34 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
35 */
36 public class LinkCheckTest extends TestCase
37 {
38 String baseDir;
39
40
41
42
43
44
45 protected void setUp() throws Exception
46 {
47 super.setUp();
48 this.baseDir = System.getProperty( "basedir" );
49
50 BasicConfigurator.configure();
51 Logger.getLogger( "org.apache.maven.plugin.linkcheck" ).setLevel( Level.DEBUG );
52 }
53
54 public void testScan() throws Exception
55 {
56 File f = new File( this.baseDir + "/src/test-resources" );
57 LinkCheck lc = new LinkCheck();
58 lc.setBasedir( f );
59 lc.setOutput( new File( this.baseDir + "/target/linkcheck.xml" ) );
60 lc.setOutputEncoding( "ISO8859-1" );
61 lc.setCache( System.getProperty( "maven.linkcheck.cache" ) );
62 lc.setExclude( "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/,"
63 + "http://cvs.apache.org/viewcvs.cgi/mavenzz/" );
64 lc.doExecute();
65
66 Iterator iter = lc.getFiles().iterator();
67 Map map = new HashMap();
68 while ( iter.hasNext() )
69 {
70 FileToCheck ftc = (FileToCheck) iter.next();
71 map.put( ftc.getName(), ftc );
72 }
73
74 assertEquals( "files.size()", 8, lc.getFiles().size() );
75
76 check( map, "nolink.html", 0 );
77 check( map, "test-resources/nolink.html", 0 );
78 check( map, "test-resources/test1/test1.html", 2 );
79 check( map, "test-resources/test1/test2.html", 0 );
80 check( map, "test1/test1.html", 1 );
81 check( map, "testA.html", 3 );
82
83
84 String fileName = "testExcludes.html";
85 check( map, fileName, 2 );
86
87 FileToCheck ftc = (FileToCheck) map.get( fileName );
88 assertEquals( "Excluded links", 2, ftc.getSuccessful() );
89
90
91
92 check( map, "index-all.html", 805 );
93
94 }
95
96 private void check( Map map, String name, int linkCount )
97 {
98 FileToCheck ftc;
99
100 ftc = (FileToCheck) map.get( name );
101 assertNotNull( name, ftc );
102
103 assertEquals( name + ".getLinks().size()", linkCount, ftc.getResults().size() );
104 }
105
106 }