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 java.io.File;
23  import java.net.InetAddress;
24  import java.util.Properties;
25  
26  import org.apache.maven.it.util.ResourceExtractor;
27  import org.mortbay.jetty.Handler;
28  import org.mortbay.jetty.Server;
29  import org.mortbay.jetty.handler.DefaultHandler;
30  import org.mortbay.jetty.handler.HandlerList;
31  import org.mortbay.jetty.handler.ResourceHandler;
32  
33  /**
34   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2387">MNG-2387</a>.
35   * 
36   * @author Brett Porter
37   * @version $Id: MavenITmng2387InactiveProxyTest.java 981712 2010-08-03 00:36:19Z bentmann $
38   */
39  public class MavenITmng2387InactiveProxyTest
40      extends AbstractMavenIntegrationTestCase
41  {
42      private Server server;
43  
44      private int port;
45  
46      private Server proxyServer;
47  
48      private int proxyPort;
49  
50      private File testDir;
51  
52      public MavenITmng2387InactiveProxyTest()
53      {
54          super( "[2.0.11,2.1.0-M1),[2.1.0,)" ); // 2.0.11+, 2.1.0+
55      }
56  
57      public void setUp()
58          throws Exception
59      {
60          testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2387" );
61  
62          ResourceHandler resourceHandler = new ResourceHandler();
63          resourceHandler.setResourceBase( new File( testDir, "repo" ).getAbsolutePath() );
64  
65          HandlerList handlers = new HandlerList();
66          handlers.setHandlers( new Handler[] { resourceHandler, new DefaultHandler() } );
67  
68          server = new Server( 0 );
69          server.setHandler( handlers );
70          server.start();
71  
72          port = server.getConnectors()[0].getLocalPort();
73  
74          resourceHandler = new ResourceHandler();
75          resourceHandler.setResourceBase( new File( testDir, "proxy" ).getAbsolutePath() );
76  
77          handlers = new HandlerList();
78          handlers.setHandlers( new Handler[] { resourceHandler, new DefaultHandler() } );
79  
80          proxyServer = new Server( 0 );
81          proxyServer.setHandler( handlers );
82          proxyServer.start();
83  
84          proxyPort = proxyServer.getConnectors()[0].getLocalPort();
85      }
86  
87      protected void tearDown()
88          throws Exception
89      {
90          super.tearDown();
91  
92          if ( server != null )
93          {
94              server.stop();
95              server = null;
96          }
97          if ( proxyServer != null )
98          {
99              proxyServer.stop();
100             proxyServer = null;
101         }
102     }
103 
104     /**
105      * Test that no proxy is used if none of the configured proxies is actually set as active.
106      */
107     public void testit()
108         throws Exception
109     {
110         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
111         
112         Properties properties = verifier.newDefaultFilterProperties();        
113         properties.setProperty( "@host@", InetAddress.getLocalHost().getCanonicalHostName() );
114         properties.setProperty( "@port@", Integer.toString( port ) );
115         properties.setProperty( "@proxyPort@", Integer.toString( proxyPort ) );
116         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", properties );
117 
118         verifier.setAutoclean( false );
119         verifier.deleteArtifacts( "org.apache.maven.its.mng2387" );
120         verifier.getCliOptions().add( "--settings" );
121         verifier.getCliOptions().add( "settings.xml" );
122         verifier.executeGoal( "validate" );
123         verifier.verifyErrorFreeLog();
124         verifier.resetStreams();
125 
126         verifier.assertArtifactPresent( "org.apache.maven.its.mng2387", "a", "0.1", "jar" );
127     }
128 
129 }