1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: TestVelocityInterceptor.java,v 1.2 2003/02/17 04:17:28 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.server.intercept.impl; 23 24 import java.io.IOException; 25 26 import junit.framework.*; 27 28 import juju.reattore.server.intercept.impl.*; 29 import juju.reattore.server.intercept.*; 30 import juju.reattore.io.ByteSource; 31 import juju.reattore.protocol.http.*; 32 import test.juju.reattore.core.intercept.impl.*; 33 34 public class TestVelocityInterceptor 35 extends TestCase { 36 37 private static final String PATH = "tests/test/juju/reattore/server/intercept/impl/testvelocityinterceptor.vm"; 38 39 private VelocityInterceptor inter = new VelocityInterceptor(); 40 41 private MockHttpResponse resp = new MockHttpResponse(); 42 private MockHttpRequest req; 43 44 private boolean go(String path) { 45 req = new MockHttpRequest("foo", path); 46 resp.setStatus(123); 47 48 return inter.process(req, resp); 49 } 50 51 private String getBody() 52 throws IOException { 53 54 ByteSource body = resp.getBody(); 55 byte[] ab = new byte[body.remaining()]; 56 57 assertEquals(body.remaining(), body.get(ab, 0, ab.length)); 58 59 return new String(ab); 60 } 61 62 public void testBasic() 63 throws Exception { 64 65 assertEquals(true, go(PATH)); 66 67 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 68 69 String body = getBody(); 70 71 String expect = 72 "A simple test of the Velocity interceptor.\n" 73 + "\n" 74 + "Path: " + PATH + "\n" 75 + "Method: foo\n" 76 + "\n" 77 + "Status: 123\n"; 78 79 assertEquals(expect, body); 80 } 81 82 public void testNegative() { 83 assertEquals(false, go(PATH + "Yeah")); 84 85 assertTrue(HttpResponse.SC_OK != resp.getStatus()); 86 assertEquals(HttpResponse.SC_NOT_FOUND, resp.getStatus()); 87 } 88 89 public void testLockedPath() 90 throws Exception { 91 92 inter.setLockedPath(PATH); 93 94 assertEquals(true, go(PATH + "Yeah")); 95 96 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 97 98 String body = getBody(); 99 100 String expect = 101 "A simple test of the Velocity interceptor.\n" 102 + "\n" 103 + "Path: " + PATH + "Yeah\n" 104 + "Method: foo\n" 105 + "\n" 106 + "Status: 123\n"; 107 108 assertEquals(expect, body); 109 } 110 111 public static Test suite() { 112 return new TestSuite(TestVelocityInterceptor.class); 113 } 114 }

This page was automatically generated by Maven