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.io.IOException;
27  import java.io.PrintWriter;
28  import java.util.Properties;
29  
30  import org.mortbay.jetty.Server;
31  import org.mortbay.jetty.handler.DefaultHandler;
32  import org.mortbay.jetty.handler.HandlerList;
33  import org.mortbay.jetty.handler.ResourceHandler;
34  import org.mortbay.jetty.security.Constraint;
35  import org.mortbay.jetty.security.ConstraintMapping;
36  import org.mortbay.jetty.security.HashUserRealm;
37  import org.mortbay.jetty.security.SecurityHandler;
38  
39  /**
40   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4729">MNG-4729</a>.
41   * 
42   * @author Benjamin Bentmann
43   */
44  public class MavenITmng4729MirrorProxyAuthUsedByProjectBuilderTest
45      extends AbstractMavenIntegrationTestCase
46  {
47  
48      public MavenITmng4729MirrorProxyAuthUsedByProjectBuilderTest()
49      {
50          super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
51      }
52  
53      /**
54       * Test that the 2.x project builder obeys the network settings (mirror, proxy, auth) when building remote POMs
55       * and discovering additional repositories.
56       */
57      public void testit()
58          throws Exception
59      {
60          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4729" );
61  
62          Constraint constraint = new Constraint();
63          constraint.setName( Constraint.__BASIC_AUTH );
64          constraint.setRoles( new String[] { "user" } );
65          constraint.setAuthenticate( true );
66  
67          ConstraintMapping constraintMapping = new ConstraintMapping();
68          constraintMapping.setConstraint( constraint );
69          constraintMapping.setPathSpec( "/*" );
70  
71          HashUserRealm userRealm = new HashUserRealm( "TestRealm" );
72          userRealm.put( "testuser", "testtest" );
73          userRealm.addUserToRole( "testuser", "user" );
74  
75          SecurityHandler securityHandler = new SecurityHandler();
76          securityHandler.setUserRealm( userRealm );
77          securityHandler.setConstraintMappings( new ConstraintMapping[] { constraintMapping } );
78  
79          ResourceHandler repoHandler = new ResourceHandler();
80          repoHandler.setResourceBase( testDir.getAbsolutePath() );
81  
82          HandlerList handlerList = new HandlerList();
83          handlerList.addHandler( securityHandler );
84          handlerList.addHandler( repoHandler );
85          handlerList.addHandler( new DefaultHandler() );
86  
87          Server server = new Server( 0 );
88          server.setHandler( handlerList );
89          server.start();
90  
91          try
92          {
93              Verifier verifier = newVerifier( testDir.getAbsolutePath() );
94              verifier.setAutoclean( false );
95              verifier.deleteDirectory( "target" );
96              verifier.deleteArtifacts( "org.apache.maven.its.mng4729" );
97              Properties filterProps = verifier.newDefaultFilterProperties();
98              filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) );
99              verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
100             verifier.getCliOptions().add( "-s" );
101             verifier.getCliOptions().add( "settings.xml" );
102             verifier.executeGoal( "validate" );
103             verifier.verifyErrorFreeLog();
104             verifier.resetStreams();
105 
106             Properties props = verifier.loadProperties( "target/pom.properties" );
107             assertEquals( "PASSED", props.get( "org.apache.maven.its.mng4729:a:jar:0.1.project.name" ) );
108         }
109         finally
110         {
111             server.stop();
112         }
113     }
114 
115 }