View Javadoc

1   package org.apache.maven.it;
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.it.Verifier;
23  import org.apache.maven.it.util.ResourceExtractor;
24  
25  import java.io.File;
26  import java.net.InetAddress;
27  import java.util.List;
28  import java.util.Properties;
29  
30  import org.mortbay.jetty.Handler;
31  import org.mortbay.jetty.Server;
32  import org.mortbay.jetty.handler.DefaultHandler;
33  import org.mortbay.jetty.handler.HandlerList;
34  import org.mortbay.jetty.handler.ResourceHandler;
35  
36  /**
37   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4991">MNG-4991</a>.
38   * 
39   * @author Benjamin Bentmann
40   */
41  public class MavenITmng4991NonProxyHostsTest
42      extends AbstractMavenIntegrationTestCase
43  {
44  
45      public MavenITmng4991NonProxyHostsTest()
46      {
47          super( "[2.0.3,3.0-alpha-1),[3.0.3,)" );
48      }
49  
50      /**
51       * Verify that the nonProxyHosts settings is respected.
52       */
53      public void testit()
54          throws Exception
55      {
56          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4991" );
57  
58          ResourceHandler resourceHandler = new ResourceHandler();
59          resourceHandler.setResourceBase( new File( testDir, "repo" ).getAbsolutePath() );
60  
61          HandlerList handlers = new HandlerList();
62          handlers.setHandlers( new Handler[] { resourceHandler, new DefaultHandler() } );
63  
64          Server server = new Server( 0 );
65          server.setHandler( handlers );
66          server.start();
67  
68          /*
69           * NOTE: To guard against automatic fallback to direct connection when the proxy is unreachable, we set up
70           * a dummy proxy as trap to catch the erroneous proxy usage in all cases.
71           */
72          Server proxy = new Server( 0 );
73          proxy.setHandler( new DefaultHandler() );
74          proxy.start();
75  
76          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
77          try
78          {
79              verifier.setAutoclean( false );
80              verifier.deleteDirectory( "target" );
81              verifier.deleteArtifacts( "org.apache.maven.its.mng4991" );
82              Properties filterProps = verifier.newDefaultFilterProperties();
83              filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) );
84              filterProps.setProperty( "@proxyPort@", Integer.toString( proxy.getConnectors()[0].getLocalPort() ) );
85              filterProps.setProperty( "@localhost@", InetAddress.getLocalHost().getCanonicalHostName() );
86              verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
87              verifier.getCliOptions().add( "-s" );
88              verifier.getCliOptions().add( "settings.xml" );
89              verifier.executeGoal( "validate" );
90              verifier.verifyErrorFreeLog();
91          }
92          finally
93          {
94              verifier.resetStreams();
95              server.stop();
96              proxy.stop();
97          }
98  
99          List compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
100 
101         assertTrue( compile.toString(), compile.contains( "dep-0.1.jar" ) );
102     }
103 
104 }