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.Deque;
33 import java.util.Properties;
34 import java.util.concurrent.ConcurrentLinkedDeque;
35
36
37
38
39
40
41 public class MavenITmng4555MetaversionResolutionOfflineTest
42 extends AbstractMavenIntegrationTestCase
43 {
44
45 public MavenITmng4555MetaversionResolutionOfflineTest()
46 {
47 super( "[2.0.3,3.0-alpha-1),[3.0-beta-1,)" );
48 }
49
50
51
52
53
54
55 public void testit()
56 throws Exception
57 {
58 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4555" );
59
60 final Deque<String> uris = new ConcurrentLinkedDeque<>();
61
62 Handler repoHandler = new AbstractHandler()
63 {
64 @Override
65 public void handle( String target, Request baseRequest, HttpServletRequest request,
66 HttpServletResponse response )
67 {
68 String uri = request.getRequestURI();
69
70 if ( uri.startsWith( "/repo/org/apache/maven/its/mng4555" ) )
71 {
72 uris.add( uri.substring( 34 ) );
73 }
74
75 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
76 ( (Request) request ).setHandled( true );
77 }
78 };
79
80 Server server = new Server( 0 );
81 server.setHandler( repoHandler );
82 server.start();
83
84 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
85 verifier.setAutoclean( false );
86 verifier.deleteDirectory( "target" );
87 verifier.deleteArtifacts( "org.apache.maven.its.mng4555" );
88 try
89 {
90 if ( server.isFailed() )
91 {
92 fail( "Couldn't bind the server socket to a free port!" );
93 }
94 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
95 System.out.println( "Bound server socket to the port " + port );
96 Properties filterProps = verifier.newDefaultFilterProperties();
97 filterProps.setProperty( "@port@", Integer.toString( port ) );
98 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
99 verifier.addCliOption( "--offline" );
100 verifier.addCliOption( "--settings" );
101 verifier.addCliOption( "settings.xml" );
102 verifier.executeGoal( "validate" );
103 }
104 catch ( VerificationException e )
105 {
106
107 }
108 finally
109 {
110 verifier.resetStreams();
111 server.stop();
112 server.join();
113 }
114
115 assertTrue( uris.toString(), uris.isEmpty() );
116 }
117 }