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: TestPartitioningInterceptor.java,v 1.1 2003/02/02 05:29:31 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.server.intercept.impl; 23 24 import junit.framework.*; 25 26 import juju.reattore.server.intercept.impl.*; 27 import juju.reattore.server.intercept.*; 28 import juju.reattore.io.ByteSource; 29 import juju.reattore.protocol.http.*; 30 import test.juju.reattore.core.intercept.impl.*; 31 32 public class TestPartitioningInterceptor 33 extends TestCase { 34 35 private PartitioningInterceptor inter = new PartitioningInterceptor(); 36 37 private MockHttpResponse resp = new MockHttpResponse(); 38 private MockHttpRequest req; 39 40 private MockInterceptor one = new MockInterceptor(); 41 private MockInterceptor two = new MockInterceptor(); 42 private MockInterceptor three = new MockInterceptor(); 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 void setup() { 52 inter.add("/one/", one); 53 inter.add("/two/", two); 54 inter.add("/three/", three); 55 } 56 57 public void testPath() { 58 setup(); 59 assertEquals(true, go("/one/y")); 60 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 61 62 assertEquals(1, one.getNumHits()); 63 assertEquals("y", one.getRequestedPath()); 64 65 66 assertEquals(true, go("/one/foo/bar")); 67 68 assertEquals(2, one.getNumHits()); 69 assertEquals("foo/bar", one.getRequestedPath()); 70 } 71 72 public void testFirst() { 73 setup(); 74 assertEquals(true, go("/one/y")); 75 76 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 77 78 assertEquals(1, one.getNumHits()); 79 assertEquals(0, two.getNumHits()); 80 assertEquals(0, three.getNumHits()); 81 } 82 83 public void testSecond() { 84 setup(); 85 assertEquals(true, go("/two/y")); 86 87 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 88 89 assertEquals(0, one.getNumHits()); 90 assertEquals(1, two.getNumHits()); 91 assertEquals(0, three.getNumHits()); 92 } 93 94 public void testThird() { 95 setup(); 96 assertEquals(true, go("/three/y")); 97 98 assertEquals(HttpResponse.SC_OK, resp.getStatus()); 99 100 assertEquals(0, one.getNumHits()); 101 assertEquals(0, two.getNumHits()); 102 assertEquals(1, three.getNumHits()); 103 } 104 105 public void testMiss() { 106 setup(); 107 assertEquals(false, go("/abc")); 108 109 assertTrue(HttpResponse.SC_OK != resp.getStatus()); 110 111 assertEquals(0, one.getNumHits()); 112 assertEquals(0, two.getNumHits()); 113 assertEquals(0, three.getNumHits()); 114 } 115 116 public static Test suite() { 117 return new TestSuite(TestPartitioningInterceptor.class); 118 } 119 }

This page was automatically generated by Maven