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.Collections;
29  import java.util.List;
30  import java.util.Properties;
31  
32  import javax.servlet.ServletException;
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  
36  import org.mortbay.jetty.Server;
37  import org.mortbay.jetty.handler.AbstractHandler;
38  import org.mortbay.jetty.handler.DefaultHandler;
39  import org.mortbay.jetty.handler.HandlerList;
40  import org.mortbay.jetty.handler.ResourceHandler;
41  
42  /**
43   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5064">MNG-5064</a>.
44   * 
45   * @author Benjamin Bentmann
46   */
47  public class MavenITmng5064SuppressSnapshotUpdatesTest
48      extends AbstractMavenIntegrationTestCase
49  {
50  
51      public MavenITmng5064SuppressSnapshotUpdatesTest()
52      {
53          super( "[3.0.4,)" );
54      }
55  
56      /**
57       * Verify that snapshot updates can be completely suppressed via the CLI arg -nsu. The initial retrieval of a
58       * missing snapshot should not be suppressed though.
59       */
60      public void testit()
61          throws Exception
62      {
63          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5064" );
64  
65          String metadataUri = "org/apache/maven/its/mng5064/dep/0.1-SNAPSHOT/maven-metadata.xml";
66  
67          final List requestedUris = Collections.synchronizedList( new ArrayList() );
68  
69          AbstractHandler logHandler = new AbstractHandler()
70          {
71              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
72                  throws IOException, ServletException
73              {
74                  if ( request.getRequestURI().startsWith( "/repo/" ) )
75                  {
76                      requestedUris.add( request.getRequestURI().substring( 6 ) );
77                  }
78              }
79          };
80  
81          ResourceHandler repoHandler = new ResourceHandler();
82          repoHandler.setResourceBase( testDir.getAbsolutePath() );
83  
84          HandlerList handlerList = new HandlerList();
85          handlerList.addHandler( logHandler );
86          handlerList.addHandler( repoHandler );
87          handlerList.addHandler( new DefaultHandler() );
88  
89          Server server = new Server( 0 );
90          server.setHandler( handlerList );
91          server.start();
92  
93          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
94          try
95          {
96              verifier.setAutoclean( false );
97              verifier.deleteDirectory( "target" );
98              verifier.deleteArtifacts( "org.apache.maven.its.mng5064" );
99              Properties filterProps = verifier.newDefaultFilterProperties();
100             filterProps.setProperty( "@port@", Integer.toString( server.getConnectors()[0].getLocalPort() ) );
101             verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
102             verifier.getCliOptions().add( "-nsu" );
103             verifier.getCliOptions().add( "-s" );
104             verifier.getCliOptions().add( "settings.xml" );
105 
106             verifier.setLogFileName( "log-1.txt" );
107             verifier.executeGoal( "validate" );
108             verifier.verifyErrorFreeLog();
109 
110             List classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
111             assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
112             assertTrue( requestedUris.toString(), requestedUris.contains( metadataUri ) );
113 
114             requestedUris.clear();
115 
116             verifier.setLogFileName( "log-2.txt" );
117             verifier.executeGoal( "validate" );
118             verifier.verifyErrorFreeLog();
119 
120             classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
121             assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
122             assertFalse( requestedUris.toString(), requestedUris.contains( metadataUri ) );
123         }
124         finally
125         {
126             verifier.resetStreams();
127             server.stop();
128         }
129     }
130 
131 }