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.Server;
26 import org.eclipse.jetty.server.handler.DefaultHandler;
27 import org.eclipse.jetty.server.handler.HandlerList;
28 import org.eclipse.jetty.server.handler.ResourceHandler;
29
30 import java.io.File;
31 import java.net.InetAddress;
32 import java.util.Properties;
33
34
35
36
37
38
39
40 public class MavenITmng2387InactiveProxyTest
41 extends AbstractMavenIntegrationTestCase
42 {
43 private Server server;
44
45 private int port;
46
47 private Server proxyServer;
48
49 private int proxyPort;
50
51 private File testDir;
52
53 public MavenITmng2387InactiveProxyTest()
54 {
55 super( "[2.0.11,2.1.0-M1),[2.1.0,)" );
56 }
57
58 @Override
59 protected void setUp()
60 throws Exception
61 {
62 testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2387" );
63
64 ResourceHandler resourceHandler = new ResourceHandler();
65 resourceHandler.setResourceBase( new File( testDir, "repo" ).getAbsolutePath() );
66
67 HandlerList handlers = new HandlerList();
68 handlers.setHandlers( new Handler[] { resourceHandler, new DefaultHandler() } );
69
70 server = new Server( 0 );
71 server.setHandler( handlers );
72 server.start();
73 if ( server.isFailed() )
74 {
75 fail( "Couldn't bind the server socket to a free port!" );
76 }
77 port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
78 System.out.println( "Bound server socket to the HTTP port " + port );
79
80 resourceHandler = new ResourceHandler();
81 resourceHandler.setResourceBase( new File( testDir, "proxy" ).getAbsolutePath() );
82
83 handlers = new HandlerList();
84 handlers.setHandlers( new Handler[] { resourceHandler, new DefaultHandler() } );
85
86 proxyServer = new Server( 0 );
87 proxyServer.setHandler( handlers );
88 proxyServer.start();
89 if ( proxyServer.isFailed() )
90 {
91 fail( "Couldn't bind the server socket to a free port!" );
92 }
93 proxyPort = ( (NetworkConnector) proxyServer.getConnectors()[0] ).getLocalPort();
94 System.out.println( "Bound server socket to the HTTPS port " + port );
95 }
96
97 @Override
98 protected void tearDown()
99 throws Exception
100 {
101 if ( server != null )
102 {
103 server.stop();
104 server.join();
105 }
106 if ( proxyServer != null )
107 {
108 proxyServer.stop();
109 proxyServer.join();
110 }
111 }
112
113
114
115
116
117
118 public void testit()
119 throws Exception
120 {
121 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
122
123 Properties properties = verifier.newDefaultFilterProperties();
124 properties.setProperty( "@host@", InetAddress.getLoopbackAddress().getCanonicalHostName() );
125 properties.setProperty( "@port@", Integer.toString( port ) );
126 properties.setProperty( "@proxyPort@", Integer.toString( proxyPort ) );
127 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", properties );
128
129 verifier.setAutoclean( false );
130 verifier.deleteArtifacts( "org.apache.maven.its.mng2387" );
131 verifier.addCliOption( "--settings" );
132 verifier.addCliOption( "settings.xml" );
133 verifier.executeGoal( "validate" );
134 verifier.verifyErrorFreeLog();
135 verifier.resetStreams();
136
137 verifier.assertArtifactPresent( "org.apache.maven.its.mng2387", "a", "0.1", "jar" );
138 }
139 }