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.Wagon;
23  import org.codehaus.plexus.PlexusTestCase;
24  import org.eclipse.jetty.server.Server;
25  import org.eclipse.jetty.server.ServerConnector;
26  import org.eclipse.jetty.server.handler.ResourceHandler;
27  import org.eclipse.jetty.servlet.ServletContextHandler;
28  
29  /**
30   * User: jdumay Date: 24/01/2008 Time: 18:15:53
31   */
32  public abstract class HttpWagonHttpServerTestCase
33      extends PlexusTestCase
34  {
35      private Server server;
36  
37      protected ResourceHandler resourceHandler;
38  
39      protected ServletContextHandler context;
40  
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45          server = new Server( 0 );
46  
47          context = new ServletContextHandler( ServletContextHandler.SESSIONS );
48          resourceHandler = new ResourceHandler();
49          context.setHandler( resourceHandler );
50          server.setHandler( context );
51      }
52  
53      protected Wagon getWagon()
54          throws Exception
55      {
56          return (Wagon) lookup( HttpWagon.ROLE );
57      }
58  
59      protected void startServer()
60          throws Exception
61      {
62          server.start();
63      }
64  
65      protected void stopServer()
66          throws Exception
67      {
68          server.stop();
69      }
70      
71      protected final int getPort()
72      {
73          return ((ServerConnector) server.getConnectors()[0]).getLocalPort();
74      }
75      
76  }