1 // ========================================================================
2 // Copyright 2006 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 // ========================================================================
14 package org.mortbay.jetty.handler.rewrite;
15 
16 import junit.framework.TestCase;
17 
18 import org.mortbay.io.bio.StringEndPoint;
19 import org.mortbay.jetty.Connector;
20 import org.mortbay.jetty.HttpConnection;
21 import org.mortbay.jetty.LocalConnector;
22 import org.mortbay.jetty.Request;
23 import org.mortbay.jetty.Response;
24 import org.mortbay.jetty.Server;
25 
26 public abstract class AbstractRuleTestCase extends TestCase
27 {
28     protected Server _server=new Server();
29     protected LocalConnector _connector;
30     protected StringEndPoint _endpoint=new StringEndPoint();
31     protected HttpConnection _connection;
32 
33     protected Request _request;
34     protected Response _response;
35 
36     protected boolean _isSecure = false;
37 
setUp()38     public void setUp() throws Exception
39     {
40         start();
41     }
42 
tearDown()43     public void tearDown() throws Exception
44     {
45         stop();
46     }
47 
start()48     public void start() throws Exception
49     {
50         _connector = new LocalConnector() {
51             public boolean isConfidential(Request request)
52             {
53                 return _isSecure;
54             }
55         };
56 
57         _server.setConnectors(new Connector[]{_connector});
58         _server.start();
59         reset();
60     }
61 
stop()62     public void stop() throws Exception
63     {
64         _server.stop();
65         _request = null;
66         _response = null;
67     }
68 
reset()69     public void reset()
70     {
71         _connection = new HttpConnection(_connector,_endpoint,_server);
72         _request = new Request(_connection);
73         _response = new Response(_connection);
74 
75         _request.setRequestURI("/test/");
76     }
77 }
78