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-4500">MNG-4500</a>.
44   * 
45   * @author Benjamin Bentmann
46   */
47  public class MavenITmng4500NoUpdateOfTimestampedSnapshotsTest
48      extends AbstractMavenIntegrationTestCase
49  {
50  
51      public MavenITmng4500NoUpdateOfTimestampedSnapshotsTest()
52      {
53          super( "[2.0.3,3.0-alpha-1),[3.0-alpha-6,)" );
54      }
55  
56      /**
57       * Test that timestamped snapshots are treated as immutable, i.e. Maven should never check for updates of them
58       * once downloaded from a remote repo regardless of the update policy.
59       */
60      public void testit()
61          throws Exception
62      {
63          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4500" );
64  
65          String pomUri = "/repo/org/apache/maven/its/mng4500/dep/0.1-SNAPSHOT/dep-0.1-20091219.230823-1.pom";
66          String jarUri = "/repo/org/apache/maven/its/mng4500/dep/0.1-SNAPSHOT/dep-0.1-20091219.230823-1.jar";
67  
68          final List requestedUris = Collections.synchronizedList( new ArrayList() );
69  
70          AbstractHandler logHandler = new AbstractHandler()
71          {
72              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
73                  throws IOException, ServletException
74              {
75                  requestedUris.add( request.getRequestURI() );
76              }
77          };
78  
79          ResourceHandler repoHandler = new ResourceHandler();
80          repoHandler.setResourceBase( testDir.getAbsolutePath() );
81  
82          HandlerList handlerList = new HandlerList();
83          handlerList.addHandler( logHandler );
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          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
92          try
93          {
94              verifier.setAutoclean( false );
95              verifier.deleteDirectory( "target" );
96              verifier.deleteArtifacts( "org.apache.maven.its.mng4500" );
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 
103             verifier.setLogFileName( "log-1.txt" );
104             verifier.executeGoal( "validate" );
105             verifier.verifyErrorFreeLog();
106 
107             List classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
108             assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
109             assertTrue( requestedUris.toString(), requestedUris.contains( pomUri ) );
110             assertTrue( requestedUris.toString(), requestedUris.contains( jarUri ) );
111 
112             requestedUris.clear();
113 
114             verifier.setLogFileName( "log-2.txt" );
115             verifier.executeGoal( "validate" );
116             verifier.verifyErrorFreeLog();
117 
118             classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
119             assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
120             assertFalse( requestedUris.toString(), requestedUris.contains( pomUri ) );
121             assertFalse( requestedUris.toString(), requestedUris.contains( jarUri ) );
122         }
123         finally
124         {
125             verifier.resetStreams();
126             server.stop();
127         }
128     }
129 
130 }