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 org.apache.maven.wagon.FileTestUtils;
23  import org.apache.maven.wagon.TransferFailedException;
24  import org.apache.maven.wagon.Wagon;
25  import org.apache.maven.wagon.authorization.AuthorizationException;
26  import org.apache.maven.wagon.repository.Repository;
27  import org.mortbay.jetty.servlet.ServletHolder;
28  
29  import java.io.File;
30  
31  /**
32   * User: jdumay Date: 24/01/2008 Time: 17:17:34
33   */
34  public class HttpWagonReasonPhraseTest
35      extends HttpWagonHttpServerTestCase
36  {
37      protected void setUp()
38          throws Exception
39      {
40          super.setUp();
41          ServletHolder servlets = new ServletHolder( new ErrorWithReasonPhaseServlet() );
42          context.addServlet( servlets, "/*" );
43          startServer();
44      }
45  
46      public void testGetReasonPhase401()
47          throws Exception
48      {
49          Exception thrown = null;
50  
51          try
52          {
53              Wagon wagon = getWagon();
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( "/401", 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( AuthorizationException.class, thrown.getClass() );
78          assertTrue( thrown.getMessage().contains( ErrorWithReasonPhaseServlet.REASON ) );
79      }
80  
81      public void testGetReasonPhase403()
82          throws Exception
83      {
84          Exception thrown = null;
85  
86          try
87          {
88              Wagon wagon = getWagon();
89  
90              Repository testRepository = new Repository();
91              testRepository.setUrl( "http://localhost:" + httpServerPort );
92  
93              wagon.connect( testRepository );
94  
95              File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
96              destFile.deleteOnExit();
97  
98              wagon.get( "/403", destFile );
99  
100             wagon.disconnect();
101         }
102         catch ( Exception e )
103         {
104             thrown = e;
105         }
106         finally
107         {
108             stopServer();
109         }
110 
111         assertNotNull( thrown );
112         assertEquals( AuthorizationException.class, thrown.getClass() );
113         assertTrue( thrown.getMessage().contains( ErrorWithReasonPhaseServlet.REASON ) );
114     }
115 
116 
117     public void testGetReasonPhase407()
118         throws Exception
119     {
120         Exception thrown = null;
121 
122         try
123         {
124             Wagon wagon = getWagon();
125 
126             Repository testRepository = new Repository();
127             testRepository.setUrl( "http://localhost:" + httpServerPort );
128 
129             wagon.connect( testRepository );
130 
131             File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
132             destFile.deleteOnExit();
133 
134             wagon.get( "/407", destFile );
135 
136             wagon.disconnect();
137         }
138         catch ( Exception e )
139         {
140             thrown = e;
141         }
142         finally
143         {
144             stopServer();
145         }
146 
147         assertNotNull( thrown );
148         assertEquals( AuthorizationException.class, thrown.getClass() );
149         assertTrue( thrown.getMessage().contains( ErrorWithReasonPhaseServlet.REASON ) );
150     }
151 
152     public void testGetReasonPhase500()
153         throws Exception
154     {
155         Exception thrown = null;
156 
157         try
158         {
159             Wagon wagon = getWagon();
160 
161             Repository testRepository = new Repository();
162             testRepository.setUrl( "http://localhost:" + httpServerPort );
163 
164             wagon.connect( testRepository );
165 
166             File destFile = FileTestUtils.createUniqueFile( getName(), getName() );
167             destFile.deleteOnExit();
168 
169             wagon.get( "/500", destFile );
170 
171             wagon.disconnect();
172         }
173         catch ( Exception e )
174         {
175             thrown = e;
176         }
177         finally
178         {
179             stopServer();
180         }
181 
182         assertNotNull( thrown );
183         assertEquals( TransferFailedException.class, thrown.getClass() );
184         assertTrue( thrown.getMessage().contains( ErrorWithReasonPhaseServlet.REASON ) );
185     }
186 }