1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23 import org.eclipse.jetty.server.NetworkConnector;
24 import org.eclipse.jetty.server.Request;
25 import org.eclipse.jetty.server.Server;
26 import org.eclipse.jetty.server.handler.AbstractHandler;
27 import org.eclipse.jetty.server.handler.DefaultHandler;
28 import org.eclipse.jetty.server.handler.HandlerList;
29 import org.eclipse.jetty.server.handler.ResourceHandler;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import java.io.File;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Properties;
38
39
40
41
42
43
44 public class MavenITmng4500NoUpdateOfTimestampedSnapshotsTest
45 extends AbstractMavenIntegrationTestCase
46 {
47
48 public MavenITmng4500NoUpdateOfTimestampedSnapshotsTest()
49 {
50 super( "[2.0.3,3.0-alpha-1),[3.0-alpha-6,)" );
51 }
52
53
54
55
56
57
58
59 public void testit()
60 throws Exception
61 {
62 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4500" );
63
64 String pomUri = "/repo/org/apache/maven/its/mng4500/dep/0.1-SNAPSHOT/dep-0.1-20091219.230823-1.pom";
65 String jarUri = "/repo/org/apache/maven/its/mng4500/dep/0.1-SNAPSHOT/dep-0.1-20091219.230823-1.jar";
66
67 final List<String> requestedUris = Collections.synchronizedList( new ArrayList<String>() );
68
69 AbstractHandler logHandler = new AbstractHandler()
70 {
71 @Override
72 public void handle( String target, Request baseRequest, HttpServletRequest request,
73 HttpServletResponse response )
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
90 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
91 try
92 {
93 server.start();
94 if ( server.isFailed() )
95 {
96 fail( "Couldn't bind the server socket to a free port!" );
97 }
98 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
99 System.out.println( "Bound server socket to the port " + port );
100 verifier.setAutoclean( false );
101 verifier.deleteDirectory( "target" );
102 verifier.deleteArtifacts( "org.apache.maven.its.mng4500" );
103 Properties filterProps = verifier.newDefaultFilterProperties();
104 filterProps.setProperty( "@port@", Integer.toString( port ) );
105 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
106 verifier.addCliOption( "-s" );
107 verifier.addCliOption( "settings.xml" );
108
109 verifier.setLogFileName( "log-1.txt" );
110 verifier.executeGoal( "validate" );
111 verifier.verifyErrorFreeLog();
112
113 List<String> classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
114 assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
115 assertTrue( requestedUris.toString(), requestedUris.contains( pomUri ) );
116 assertTrue( requestedUris.toString(), requestedUris.contains( jarUri ) );
117
118 requestedUris.clear();
119
120 verifier.setLogFileName( "log-2.txt" );
121 verifier.executeGoal( "validate" );
122 verifier.verifyErrorFreeLog();
123
124 classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
125 assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
126 assertFalse( requestedUris.toString(), requestedUris.contains( pomUri ) );
127 assertFalse( requestedUris.toString(), requestedUris.contains( jarUri ) );
128 }
129 finally
130 {
131 verifier.resetStreams();
132 server.stop();
133 server.join();
134 }
135 }
136 }