View Javadoc

1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  import org.mortbay.jetty.Handler;
24  import org.mortbay.jetty.Request;
25  import org.mortbay.jetty.Server;
26  import org.mortbay.jetty.handler.AbstractHandler;
27  
28  import javax.servlet.ServletException;
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  import java.io.File;
32  import java.io.IOException;
33  import java.util.Properties;
34  
35  /**
36   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5175">MNG-5175</a>.
37   * test correct integration of wagon http: read time out configuration from settings.xml
38   *
39   * @version $Id: MavenITmng5175WagonHttpTest.java 1213420 2011-12-12 20:30:00Z olamy $
40   */
41  public class MavenITmng5175WagonHttpTest
42      extends AbstractMavenIntegrationTestCase
43  {
44      private Server server;
45  
46      private int port;
47  
48      public MavenITmng5175WagonHttpTest()
49      {
50          super( "[3.0.4,)" ); // 3.0.4+
51      }
52  
53      public void setUp()
54          throws Exception
55      {
56          Handler handler = new AbstractHandler()
57          {
58              public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
59                  throws IOException, ServletException
60              {
61                  try
62                  {
63                      Thread.sleep( 15 );
64                  }
65                  catch ( InterruptedException e )
66                  {
67                      throw new ServletException( e.getMessage() );
68                  }
69                  response.setContentType( "text/plain" );
70                  response.setStatus( HttpServletResponse.SC_OK );
71                  response.getWriter().println( "some content" );
72                  response.getWriter().println();
73  
74                  ( (Request) request ).setHandled( true );
75              }
76          };
77  
78          server = new Server( 0 );
79          server.setHandler( handler );
80          server.start();
81  
82          port = server.getConnectors()[0].getLocalPort();
83      }
84  
85      protected void tearDown()
86          throws Exception
87      {
88          super.tearDown();
89  
90          if ( server != null )
91          {
92              server.stop();
93              server = null;
94          }
95      }
96  
97      /**
98       * Test that the read time out from settings is used.
99       * basically use a 1ms time out and wait a bit in the handler
100      */
101     public void testmng5175_ReadTimeOutFromSettings()
102         throws Exception
103     {
104         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5175" );
105 
106         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
107 
108         Properties filterProps = new Properties();
109         filterProps.setProperty( "@port@", Integer.toString( port ) );
110 
111         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
112 
113         verifier.getCliOptions().add( "-U" );
114         verifier.getCliOptions().add( "--settings" );
115         verifier.getCliOptions().add( "settings.xml" );
116         //verifier.
117         verifier.executeGoal( "validate" );
118 
119         verifier.verifyTextInLog( "Read timed out" );
120         verifier.resetStreams();
121 
122 
123     }
124 
125 
126 }