View Javadoc

1   package org.apache.maven.wagon.providers.http;
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 java.io.File;
23  
24  import org.apache.maven.wagon.FileTestUtils;
25  import org.apache.maven.wagon.TransferFailedException;
26  import org.apache.maven.wagon.Wagon;
27  import org.apache.maven.wagon.repository.Repository;
28  import org.mortbay.jetty.servlet.ServletHolder;
29  
30  /**
31   * User: jdumay Date: 24/01/2008 Time: 17:17:34
32   */
33  public class HttpWagonTimeoutTest
34      extends HttpWagonHttpServerTestCase
35  {
36      protected void setUp()
37          throws Exception
38      {
39          super.setUp();
40          ServletHolder servlets = new ServletHolder( new WaitForeverServlet() );
41          context.addServlet( servlets, "/*" );
42          startServer();
43      }
44  
45      public void testGetTimeout()
46          throws Exception
47      {
48          Exception thrown = null;
49  
50          try
51          {
52              Wagon wagon = getWagon();
53              wagon.setTimeout( 1000 );
54  
55              Repository testRepository = new Repository();
56              testRepository.setUrl( "http://localhost:" + httpServerPort );
57  
58              wagon.connect( testRepository );
59  
60              File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
61              destFile.deleteOnExit();
62  
63              wagon.get( "/timeoutfile", destFile );
64  
65              wagon.disconnect();
66          }
67          catch ( Exception e )
68          {
69              thrown = e;
70          }
71          finally
72          {
73              stopServer();
74          }
75  
76          assertNotNull( thrown );
77          assertEquals( TransferFailedException.class, thrown.getClass() );
78      }
79  
80      public void testResourceExits()
81          throws Exception
82      {
83          Exception thrown = null;
84  
85          try
86          {
87              Wagon wagon = getWagon();
88              wagon.setTimeout( 1000 );
89  
90              Repository testRepository = new Repository();
91              testRepository.setUrl( "http://localhost:" + httpServerPort );
92  
93              wagon.connect( testRepository );
94  
95              wagon.resourceExists( "/timeoutfile" );
96  
97              wagon.disconnect();
98          }
99          catch ( Exception e )
100         {
101             thrown = e;
102         }
103         finally
104         {
105             stopServer();
106         }
107 
108         assertNotNull( thrown );
109         assertEquals( TransferFailedException.class, thrown.getClass() );
110     }
111 
112     public void testGetFileList()
113         throws Exception
114     {
115         Exception thrown = null;
116 
117         try
118         {
119             Wagon wagon = getWagon();
120             wagon.setTimeout( 1000 );
121 
122             Repository testRepository = new Repository();
123             testRepository.setUrl( "http://localhost:" + httpServerPort );
124 
125             wagon.connect( testRepository );
126 
127             wagon.getFileList( "/timeoutfile" );
128 
129             wagon.disconnect();
130         }
131         catch ( Exception e )
132         {
133             thrown = e;
134         }
135         finally
136         {
137             stopServer();
138         }
139 
140         assertNotNull( thrown );
141         assertEquals( TransferFailedException.class, thrown.getClass() );
142     }
143 
144     public void testPutTimeout()
145         throws Exception
146     {
147         Exception thrown = null;
148 
149         try
150         {
151             Wagon wagon = getWagon();
152             wagon.setTimeout( 1000 );
153 
154             Repository testRepository = new Repository();
155             testRepository.setUrl( "http://localhost:" + httpServerPort );
156 
157             wagon.connect( testRepository );
158 
159             File destFile = File.createTempFile( "Hello", null );
160             destFile.deleteOnExit();
161 
162             wagon.put( destFile, "/timeoutfile" );
163 
164             wagon.disconnect();
165         }
166         catch ( Exception e )
167         {
168             thrown = e;
169         }
170         finally
171         {
172             stopServer();
173         }
174 
175         assertNotNull( thrown );
176         assertEquals( TransferFailedException.class, thrown.getClass() );
177     }
178 
179 }