1 package org.apache.maven.wagon.providers.http;
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.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
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 }