Package com.volantis.shared.net.http

Examples of com.volantis.shared.net.http.HttpServerMock


    private HttpServerMock serverMock;

    protected void setUp() throws Exception {
        super.setUp();

        serverMock = new HttpServerMock();
    }
View Full Code Here


    private HttpServerMock serverMock;

    protected void setUp() throws Exception {
        super.setUp();

        serverMock = new HttpServerMock();
    }
View Full Code Here

        inputServerPort = serverMock.getServerPort();
        outputServerPort = inputServerPort;
    }

    private HttpServerMock createServerMock() throws IOException {
        HttpServerMock serverMock = new HttpServerMock();
        servers.add(serverMock);
        return serverMock;
    }
View Full Code Here

    // javadoc inherited from superclass
    protected void tearDown() throws Exception {
        Category.getRoot().removeAllAppenders();
        for (int i = 0; i < servers.size(); i++) {
            HttpServerMock httpServerMock = (HttpServerMock) servers.get(i);
            httpServerMock.close();
        }
        inputServerPort = -1;
        outputServerPort = -1;
    }
View Full Code Here

        redirectServers[0] = serverMock;

        String path = "/mantis/Mantis_Login.jsp";
        for (int i = 1; i < maxRedirects + 1; i++) {

            HttpServerMock redirectServerMock = createServerMock();
            redirectServers[i] = redirectServerMock;
            int redirectServerPort = redirectServerMock.getServerPort();

            HttpServerMock redirectingServerMock = redirectServers[i - 1];
            int redirectingServerPort = redirectingServerMock.getServerPort();
            String[] expectedRequest = new String[]{
                "GET " + path + " HTTP/1.1",
                "User-Agent: Jakarta Commons-HttpClient/3.0.1",
                getHostHeader(redirectingServerPort),
            };

                String[] redirectContent1 = new String[]{
                    "HTTP/1.0 301 OK",
                    "Content-Type: text/plain",
                    "Content-Length: 99",
                "Location: http://localhost:" + redirectServerPort +
                    "/welcome.jsp",
                    "Set-Cookie: BROWSER=Netscape; domain=localhost; path=/",
                    "",
                    "<p>We will be redirected so should never see this</p>"
                };

            redirectingServerMock.addTransaction(expectedRequest,
                    redirectContent1);

            path = "/welcome.jsp";
            }
View Full Code Here

     *
     * @throws Exception
     */
    public void testCyclicalRedirect() throws Exception {

        HttpServerMock redirectServerMock = createServerMock();

        int redirectServerPort = redirectServerMock.getServerPort();
        String[] redirectContent1 = new String[]{
            "HTTP/1.0 301 OK",
            "Content-Type: text/plain",
            "Content-Length: 99",
            "Location: http://localhost:" + redirectServerPort +
                "/welcome.jsp",
            "Set-Cookie: BROWSER=Netscape; domain=localhost; path=/",
            "",
            "<p>We will be redirected so should never see this</p>"
        };

        // Redirect from the server to the redirect server.
        serverMock.addTransaction(null, redirectContent1);

        String[] redirectContent2 = new String[]{
            "HTTP/1.0 301 OK",
            "Content-Type: text/plain",
            "Content-Length: 99",
            "Location: http://localhost:" + inputServerPort + "/welcome.jsp",
            "Set-Cookie: BROWSER=Netscape; domain=localhost; path=/",
            "",
            "<p>We will be redirected so should never see this</p>"
        };

        // Redirect back from the redirect server to the original server.
        redirectServerMock.addTransaction(null, redirectContent2);

        // Redirect from the original server back to the redirect server.
        serverMock.addTransaction(null, redirectContent1);

            XMLPipelineConfiguration config = createPipelineConfiguration();
View Full Code Here

     * @throws Exception if an error occurs
     */
    public void testSimpleRedirect() throws Exception {
        // redirect status codes are 301, 302 and 307

        HttpServerMock redirectServerMock1 = createServerMock();
        HttpServerMock redirectServerMock2 = createServerMock();
        HttpServerMock redirectServerMock3 = createServerMock();

        String[] redirectContent1 = new String[]{
            "HTTP/1.0 301 OK",
            "Content-Type: text/plain",
            "Content-Length: 99",
            "Age: 1",
            "Location: " + redirectServerMock1.getURLAsString("/welcome.jsp"),
            "Set-Cookie: BROWSER=Netscape; domain=localhost; path=/",
            "",
            "<p>We will be redirected so should never see this</p>"
        };
        serverMock.addTransaction(null, redirectContent1);

        String[] redirectContent2 = new String[]{
            "HTTP/1.0 302 OK",
            "Content-Type: text/wml",
            "Content-Length: 88",
            "Age: 1",
            "Location: " + redirectServerMock2.getURLAsString("/hello.jsp"),
            "Set-Cookie: DEVICE=PC; domain=localhost; path=/; secure",
            "",
            "<p>Again we will be redirected so should never see this</p>"
        };
        redirectServerMock1.addTransaction(null, redirectContent2);

        String[] redirectContent3 = new String[]{
            "HTTP/1.0 307 OK",
            "Content-Type: text/xml",
            "Content-Length: 77",
            "Age: 1",
            "Location: " + redirectServerMock3.getURLAsString("/my.jsp"),
            "Set-Cookie: DEVICE=PALM; domain=localhost; path=/",
            "",
            "<p>Again we will be redirected so should never see this</p>"
        };
        redirectServerMock2.addTransaction(null, redirectContent3);

        String[] finalContent = new String[]{
            "HTTP/1.0 200 OK",
            "Content-Type: text/html",
            "Content-Length: 543",
            "Age: 1",
            "Set-Cookie: DEVICE=NOKIA; domain=localhost; path=/",
            "",
            "<html>",
            "<p>Should see this</p>",
            "<a href=\"fred.jsp\"/>",
            "</html>"
        };
        redirectServerMock3.addTransaction(null, finalContent);

        outputServerPort = redirectServerMock3.getServerPort();

            XMLPipelineConfiguration config = createPipelineConfiguration();
            XMLPipelineContext context =
                pipelineFactory.createPipelineContext(config,
                            createRootEnvironmentInteraction());
View Full Code Here

     *
     * @throws Exception if an error occurs
     */
    public void testFollowRedirectSwitchedOffInline() throws Exception {

        HttpServerMock redirectServerMock = createServerMock();

        int redirectServerPort = redirectServerMock.getServerPort();
        String[] redirectContent1 = new String[]{
            "HTTP/1.0 301 OK",
            "Content-Type: text/plain",
            "Content-Length: 46",
            "Age: 1",
            "Location: http://localhost:" + redirectServerPort +
                "/welcome.jsp",
            "",
            "<p>Ignoring redirects so should see this</p>"
        };

        serverMock.addTransaction(null, redirectContent1);

        String[] redirectContent2 = new String[]{
            "HTTP/1.0 302 OK",
            "Content-Type: text/wml",
            "Content-Length: 88",
            "Age: 1",
            "Set-Cookie: DEVICE=PC; domain=localhost; path=/; secure",
            "",
            "<p>As we are not following redirects we should not see this</p>"
        };
        redirectServerMock.addTransaction(null, redirectContent2);

            XMLPipelineConfiguration config = createPipelineConfiguration();
            XMLPipelineContext context =
                pipelineFactory.createPipelineContext(config,
                            createRootEnvironmentInteraction());
View Full Code Here

    private StringWriter writer;

    protected void setUp() throws Exception {
        super.setUp();

        serverMock = new HttpServerMock();

        writer = new StringWriter();

        XMLPipelineFactory factory = XMLPipelineFactory.getDefaultInstance();
        XMLPipelineFilter filter = createPipelineFilter(factory,
View Full Code Here

        // =====================================================================
        //   Create Mocks
        // =====================================================================

        HttpServerMock serverMock = new HttpServerMock();

        // =====================================================================
        //   Set Expectations
        // =====================================================================

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        ProtocolSocketChannelFactory factory =
                new ProtocolSocketChannelFactory(Period.INDEFINITELY);

        String host = "localhost";
        int port = serverMock.getServerPort();
        Socket socket = factory.createSocket(host, port);
        socket.close();
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.HttpServerMock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.