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.ServletException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.File;
33 import java.io.IOException;
34 import java.util.Properties;
35
36
37
38
39
40
41
42 public class MavenITmng5175WagonHttpTest
43 extends AbstractMavenIntegrationTestCase
44 {
45 private Server server;
46
47 private int port;
48
49 public MavenITmng5175WagonHttpTest()
50 {
51 super( "[3.0.4,)" );
52 }
53
54 @Override
55 protected void setUp()
56 throws Exception
57 {
58 Handler handler = new AbstractHandler()
59 {
60 @Override
61 public void handle( String target, Request baseRequest, HttpServletRequest request,
62 HttpServletResponse response )
63 throws IOException, ServletException
64 {
65 try
66 {
67
68 Thread.sleep( 100 );
69 }
70 catch ( InterruptedException e )
71 {
72 throw new ServletException( e.getMessage() );
73 }
74 response.setContentType( "text/plain" );
75 response.setStatus( HttpServletResponse.SC_OK );
76 response.getWriter().println( "some content" );
77 response.getWriter().println();
78
79 ( (Request) request ).setHandled( true );
80 }
81 };
82
83 server = new Server( 0 );
84 server.setHandler( handler );
85 server.start();
86 if ( server.isFailed() )
87 {
88 fail( "Couldn't bind the server socket to a free port!" );
89 }
90 port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
91 System.out.println( "Bound server socket to the port " + port );
92 }
93
94 @Override
95 protected void tearDown()
96 throws Exception
97 {
98 if ( server != null )
99 {
100 server.stop();
101 server.join();
102 }
103 }
104
105
106
107
108
109
110
111 public void testmng5175_ReadTimeOutFromSettings()
112 throws Exception
113 {
114 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5175" );
115
116 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
117
118 Properties filterProps = new Properties();
119 filterProps.setProperty( "@port@", Integer.toString( port ) );
120
121 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
122
123 verifier.addCliOption( "-U" );
124 verifier.addCliOption( "--settings" );
125 verifier.addCliOption( "settings.xml" );
126 verifier.addCliOption( "--fail-never" );
127 verifier.addCliOption( "--errors" );
128 verifier.setMavenDebug( true );
129 verifier.executeGoal( "validate" );
130
131 verifier.verifyTextInLog(
132 "Could not transfer artifact org.apache.maven.its.mng5175:fake-dependency:pom:1.0-SNAPSHOT" );
133 verifier.verifyTextInLog( "Read timed out" );
134 verifier.resetStreams();
135 }
136 }