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.Handler;
24 import org.eclipse.jetty.server.NetworkConnector;
25 import org.eclipse.jetty.server.Request;
26 import org.eclipse.jetty.server.Server;
27 import org.eclipse.jetty.server.handler.AbstractHandler;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.io.File;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
35 import java.util.Properties;
36
37
38
39
40
41
42
43 public class MavenITmng4348NoUnnecessaryRepositoryAccessTest
44 extends AbstractMavenIntegrationTestCase
45 {
46
47 public MavenITmng4348NoUnnecessaryRepositoryAccessTest()
48 {
49 super( ALL_MAVEN_VERSIONS );
50 }
51
52
53
54
55
56
57
58 public void testit()
59 throws Exception
60 {
61 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4348" );
62
63 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
64
65 final List<String> requestedUris = Collections.synchronizedList( new ArrayList<String>() );
66
67 Handler repoHandler = new AbstractHandler()
68 {
69 @Override
70 public void handle( String target, Request baseRequest, HttpServletRequest request,
71 HttpServletResponse response )
72 {
73 System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
74
75
76 if ( request.getRequestURI().startsWith( "/org/apache/maven/its/mng4348" ) )
77 {
78 requestedUris.add( request.getRequestURI() );
79 }
80
81 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
82
83 ( (Request) request ).setHandled( true );
84 }
85 };
86
87 Server server = new Server( 0 );
88 server.setHandler( repoHandler );
89
90 try
91 {
92 server.start();
93 if ( server.isFailed() )
94 {
95 fail( "Couldn't bind the server socket to a free port!" );
96 }
97 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
98 System.out.println( "Bound server socket to the port " + port );
99 verifier.setAutoclean( false );
100 verifier.deleteArtifacts( "org.apache.maven.its.mng4348" );
101 verifier.deleteDirectory( "target" );
102 Properties filterProps = verifier.newDefaultFilterProperties();
103 filterProps.setProperty( "@port@", Integer.toString( port ) );
104 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
105 verifier.addCliOption( "--settings" );
106 verifier.addCliOption( "settings.xml" );
107 verifier.executeGoal( "validate" );
108 verifier.verifyErrorFreeLog();
109 verifier.resetStreams();
110 }
111 finally
112 {
113 server.stop();
114 server.join();
115 }
116
117 verifier.assertFilePresent( "target/touch.txt" );
118 assertEquals( new ArrayList<String>(), requestedUris );
119 }
120 }