1   package org.apache.maven.plugin.linkcheck.validation;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
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       * (non-Javadoc)
42       * 
43       * @see junit.framework.TestCase#setUp()
44       */
45      protected void setUp() throws Exception
46      {
47          super.setUp();
48          // Setup log4J (We are in a forked JVM for tests)
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  }