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