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 MavenITmng5064SuppressSnapshotUpdatesTest
45 extends AbstractMavenIntegrationTestCase
46 {
47
48 public MavenITmng5064SuppressSnapshotUpdatesTest()
49 {
50 super( "[3.0.4,)" );
51 }
52
53
54
55
56
57
58
59 public void testit()
60 throws Exception
61 {
62 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5064" );
63
64 String metadataUri = "org/apache/maven/its/mng5064/dep/0.1-SNAPSHOT/maven-metadata.xml";
65
66 final List<String> requestedUris = Collections.synchronizedList( new ArrayList<String>() );
67
68 AbstractHandler logHandler = new AbstractHandler()
69 {
70 @Override
71 public void handle( String target, Request baseRequest, HttpServletRequest request,
72 HttpServletResponse response )
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 if ( server.isFailed() )
97 {
98 fail( "Couldn't bind the server socket to a free port!" );
99 }
100 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
101 System.out.println( "Bound server socket to the port " + port );
102 verifier.setAutoclean( false );
103 verifier.deleteDirectory( "target" );
104 verifier.deleteArtifacts( "org.apache.maven.its.mng5064" );
105 Properties filterProps = verifier.newDefaultFilterProperties();
106 filterProps.setProperty( "@port@", Integer.toString( port ) );
107 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
108 verifier.addCliOption( "-nsu" );
109 verifier.addCliOption( "-s" );
110 verifier.addCliOption( "settings.xml" );
111
112 verifier.setLogFileName( "log-1.txt" );
113 verifier.executeGoal( "validate" );
114 verifier.verifyErrorFreeLog();
115
116 List<String> classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
117 assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
118 assertTrue( requestedUris.toString(), requestedUris.contains( metadataUri ) );
119
120 requestedUris.clear();
121
122 verifier.setLogFileName( "log-2.txt" );
123 verifier.executeGoal( "validate" );
124 verifier.verifyErrorFreeLog();
125
126 classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
127 assertTrue( classpath.toString(), classpath.contains( "dep-0.1-SNAPSHOT.jar" ) );
128 assertFalse( requestedUris.toString(), requestedUris.contains( metadataUri ) );
129 }
130 finally
131 {
132 verifier.resetStreams();
133 server.stop();
134 server.join();
135 }
136 }
137 }