Package test.juju.reattore.server.intercept.impl

Source Code of test.juju.reattore.server.intercept.impl.TestVelocityInterceptor

/*  Reattore HTTP Server

    Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    $Id: TestVelocityInterceptor.java,v 1.2 2003/02/17 04:17:28 michaelh Exp $
*/

package test.juju.reattore.server.intercept.impl;

import java.io.IOException;

import junit.framework.*;

import juju.reattore.server.intercept.impl.*;
import juju.reattore.server.intercept.*;
import juju.reattore.io.ByteSource;
import juju.reattore.protocol.http.*;
import test.juju.reattore.core.intercept.impl.*;

public class TestVelocityInterceptor
    extends TestCase {

    private static final String PATH = "tests/test/juju/reattore/server/intercept/impl/testvelocityinterceptor.vm";

    private VelocityInterceptor inter = new VelocityInterceptor();

    private MockHttpResponse resp = new MockHttpResponse();
    private MockHttpRequest req;

    private boolean go(String path) {
        req = new MockHttpRequest("foo", path);
        resp.setStatus(123);

        return inter.process(req, resp);
    }

    private String getBody()
        throws IOException {

        ByteSource body = resp.getBody();
        byte[] ab = new byte[body.remaining()];

        assertEquals(body.remaining(), body.get(ab, 0, ab.length));

        return new String(ab);
    }

    public void testBasic()
        throws Exception {

        assertEquals(true, go(PATH));

        assertEquals(HttpResponse.SC_OK, resp.getStatus());
 
        String body = getBody();

        String expect =
            "A simple test of the Velocity interceptor.\n"
            + "\n"
            + "Path: " + PATH + "\n"
            + "Method: foo\n"
            + "\n"
            + "Status: 123\n";

        assertEquals(expect, body);
    }

    public void testNegative() {
        assertEquals(false, go(PATH + "Yeah"));

        assertTrue(HttpResponse.SC_OK != resp.getStatus());
        assertEquals(HttpResponse.SC_NOT_FOUND, resp.getStatus());
    }

    public void testLockedPath()
        throws Exception {

        inter.setLockedPath(PATH);

        assertEquals(true, go(PATH + "Yeah"));

        assertEquals(HttpResponse.SC_OK, resp.getStatus());
 
        String body = getBody();

        String expect =
            "A simple test of the Velocity interceptor.\n"
            + "\n"
            + "Path: " + PATH + "Yeah\n"
            + "Method: foo\n"
            + "\n"
            + "Status: 123\n";

        assertEquals(expect, body);
    }

    public static Test suite() {
        return new TestSuite(TestVelocityInterceptor.class);
    }
}
TOP

Related Classes of test.juju.reattore.server.intercept.impl.TestVelocityInterceptor

TOP
Copyright © 2018 www.massapi.com. 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.