Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7f45a8d9d07f6078d2059c30cd074b9ee2935a79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
//  ========================================================================
//  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.rewrite.handler;

import org.eclipse.jetty.io.bio.StringEndPoint;
import org.eclipse.jetty.server.BlockingHttpConnection;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.AbstractHttpConnection;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.junit.After;

public abstract class AbstractRuleTestCase
{
    protected Server _server = new Server();
    protected LocalConnector _connector;
    protected StringEndPoint _endpoint = new StringEndPoint();
    protected AbstractHttpConnection _connection;
    protected Request _request;
    protected Response _response;
    protected boolean _isSecure = false;

    @After
    public void stopServer() throws Exception
    {
        stop();
    }

    protected void start(final boolean isSecure) throws Exception
    {
        _connector = new LocalConnector()
        {
            public boolean isConfidential(Request request)
            {
                return isSecure;
            }
        };
        _server.setConnectors(new Connector[]{_connector});
        _server.start();
        reset();
    }

    protected void stop() throws Exception
    {
        _server.stop();
        _server.join();
        _request = null;
        _response = null;
    }

    protected void reset()
    {
        _connection = new BlockingHttpConnection(_connector, _endpoint, _server);
        _request = new Request(_connection);
        _response = new Response(_connection);
        _request.setRequestURI("/test/");
    }
}

Back to the top