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.util.Properties;
24  
25  import org.apache.maven.it.Verifier;
26  import org.apache.maven.it.util.ResourceExtractor;
27  import org.mortbay.jetty.Server;
28  import org.mortbay.jetty.handler.DefaultHandler;
29  import org.mortbay.jetty.handler.HandlerList;
30  import org.mortbay.jetty.handler.ResourceHandler;
31  import org.mortbay.jetty.security.Constraint;
32  import org.mortbay.jetty.security.ConstraintMapping;
33  import org.mortbay.jetty.security.HashUserRealm;
34  import org.mortbay.jetty.security.SecurityHandler;
35  
36  /**
37   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4068">MNG-4068</a>.
38   * 
39   * @author Benjamin Bentmann
40   * @version $Id: MavenITmng4068AuthenticatedMirrorTest.java 981712 2010-08-03 00:36:19Z bentmann $
41   */
42  public class MavenITmng4068AuthenticatedMirrorTest
43      extends AbstractMavenIntegrationTestCase
44  {
45  
46      private File testDir;
47  
48      private Server server;
49  
50      private int port;
51  
52      public MavenITmng4068AuthenticatedMirrorTest()
53      {
54          super( ALL_MAVEN_VERSIONS );
55      }
56  
57      public void setUp()
58          throws Exception
59      {
60          super.setUp();
61  
62          testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4068" );
63  
64          Constraint constraint = new Constraint();
65          constraint.setName( Constraint.__BASIC_AUTH );
66          constraint.setRoles( new String[] { "user" } );
67          constraint.setAuthenticate( true );
68  
69          ConstraintMapping constraintMapping = new ConstraintMapping();
70          constraintMapping.setConstraint( constraint );
71          constraintMapping.setPathSpec( "/*" );
72  
73          HashUserRealm userRealm = new HashUserRealm( "TestRealm" );
74          userRealm.put( "testuser", "testtest" );
75          userRealm.addUserToRole( "testuser", "user" );
76  
77          SecurityHandler securityHandler = new SecurityHandler();
78          securityHandler.setUserRealm( userRealm );
79          securityHandler.setConstraintMappings( new ConstraintMapping[] { constraintMapping } );
80  
81          ResourceHandler repoHandler = new ResourceHandler();
82          repoHandler.setResourceBase( new File( testDir, "repo" ).getAbsolutePath() );
83  
84          HandlerList handlerList = new HandlerList();
85          handlerList.addHandler( securityHandler );
86          handlerList.addHandler( repoHandler );
87          handlerList.addHandler( new DefaultHandler() );
88  
89          server = new Server( 0 );
90          server.setHandler( handlerList );
91          server.start();
92  
93          port = server.getConnectors()[0].getLocalPort();
94      }
95  
96      protected void tearDown()
97          throws Exception
98      {
99          if ( server != null )
100         {
101             server.stop();
102             server = null;
103         }
104 
105         super.tearDown();
106     }
107 
108     /**
109      * Test that downloading of release/snapshot artifacts from an authenticated mirror works. This basically boils down
110      * to using the proper id for the mirrored repository when looking up the credentials.
111      */
112     public void testit()
113         throws Exception
114     {
115         Properties filterProps = new Properties();
116         filterProps.setProperty( "@mirrorPort@", Integer.toString( port ) );
117 
118         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
119         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
120         verifier.setAutoclean( false );
121         verifier.deleteArtifacts( "org.apache.maven.its.mng4068" );
122         verifier.getCliOptions().add( "--settings" );
123         verifier.getCliOptions().add( "settings.xml" );
124         verifier.executeGoal( "validate" );
125         verifier.verifyErrorFreeLog();
126         verifier.resetStreams();
127 
128         verifier.assertArtifactPresent( "org.apache.maven.its.mng4068", "a", "0.1", "jar" );
129         verifier.assertArtifactPresent( "org.apache.maven.its.mng4068", "b", "0.1-SNAPSHOT", "jar" );
130     }
131 
132 }