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.util.ArrayList;
28  import java.util.List;
29  import java.util.Properties;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  import org.mortbay.jetty.Handler;
35  import org.mortbay.jetty.Request;
36  import org.mortbay.jetty.Server;
37  import org.mortbay.jetty.handler.AbstractHandler;
38  
39  /**
40   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4555">MNG-4555</a>.
41   * 
42   * @author Benjamin Bentmann
43   */
44  public class MavenITmng4555MetaversionResolutionOfflineTest
45      extends AbstractMavenIntegrationTestCase
46  {
47  
48      public MavenITmng4555MetaversionResolutionOfflineTest()
49      {
50          super( "[2.0.3,3.0-alpha-1),[3.0-beta-1,)" );
51      }
52  
53      /**
54       * Verify that resolution of the metaversion RELEASE respects offline mode.
55       */
56      public void testit()
57          throws Exception
58      {
59          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4555" );
60  
61          final List uris = new ArrayList();
62  
63          Handler repoHandler = new AbstractHandler()
64          {
65              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
66                  throws IOException
67              {
68                  String uri = request.getRequestURI();
69  
70                  if ( uri.startsWith( "/repo/org/apache/maven/its/mng4555" ) )
71                  {
72                      uris.add( uri.substring( 34 ) );
73                  }
74  
75                  response.setStatus( HttpServletResponse.SC_NOT_FOUND );
76                  ( (Request) request ).setHandled( true );
77              }
78          };
79  
80          Server server = new Server( 0 );
81          server.setHandler( repoHandler );
82          server.start();
83  
84          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
85          verifier.setAutoclean( false );
86          verifier.deleteDirectory( "target" );
87          verifier.deleteArtifacts( "org.apache.maven.its.mng4555" );
88          try
89          {
90              Properties filterProps = verifier.newDefaultFilterProperties();
91              filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) );
92              verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
93              verifier.getCliOptions().add( "--offline" );
94              verifier.getCliOptions().add( "--settings" );
95              verifier.getCliOptions().add( "settings.xml" );
96              verifier.executeGoal( "validate" );
97          }
98          catch ( VerificationException e )
99          {
100             // expected
101         }
102         finally
103         {
104             verifier.resetStreams();
105             server.stop();
106         }
107 
108         assertTrue( uris.toString(), uris.isEmpty() );
109     }
110 
111 }