1 package org.apache.maven.plugin.linkcheck.validation;
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
27 import junit.framework.TestCase;
28
29 /**
30 * @author <a href="bwalding@apache.org">Ben Walding</a>
31 * @author <a href="aheritier@apache.org">Arnaud Heritier</a>
32 * @version $Id: HTTPLinkValidatorTest.java 532339 2007-04-25 12:28:56Z ltheussl $
33 */
34 public class HTTPLinkValidatorTest extends TestCase
35 {
36 private LinkValidator hlv;
37
38 private boolean mavenOnline = Boolean.getBoolean( "maven.mode.online" );
39
40
41
42
43
44
45 protected void setUp() throws Exception
46 {
47 super.setUp();
48
49 BasicConfigurator.configure();
50 Logger.getLogger( "org.apache.maven.plugin.linkcheck" ).setLevel( Level.DEBUG );
51 }
52
53 public void testValidateLink() throws Exception
54 {
55 if ( this.mavenOnline )
56 {
57 this.hlv =
58 new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ),
59 System.getProperty( "maven.linkcheck.proxy.host" ),
60 System.getProperty( "maven.linkcheck.proxy.port" ),
61 System.getProperty( "maven.linkcheck.proxy.username" ),
62 System.getProperty( "maven.linkcheck.proxy.password" ),
63 System.getProperty( "maven.linkcheck.proxy.ntlm.host" ),
64 System.getProperty( "maven.linkcheck.proxy.ntlm.domain" ) );
65
66 assertEquals( LinkValidationResult.VALID, checkLink( "http://www.apache.org" ).getStatus() );
67 assertEquals( LinkValidationResult.ERROR, checkLink( "http://www.example.com>);" ).getStatus() );
68 }
69 else
70 {
71 this.hlv = new OfflineHTTPLinkValidator();
72
73 assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.apache.org" ).getStatus() );
74 assertEquals( LinkValidationResult.WARNING, checkLink( "http://www.example.com>);" ).getStatus() );
75
76 }
77 }
78
79 protected LinkValidationResult checkLink( String link ) throws Exception
80 {
81
82 LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link );
83 return this.hlv.validateLink( lvi );
84 }
85
86 }