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: TestStartLineParser.java,v 1.3 2003/02/18 04:11:48 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.protocol.http.impl; 23 24 import junit.framework.*; 25 import org.apache.commons.logging.*; 26 27 import juju.reattore.io.impl.*; 28 import juju.reattore.protocol.http.impl.StartLineParser; 29 import juju.reattore.protocol.http.ParseException; 30 31 public class TestStartLineParser 32 extends TestCase 33 implements StartLineParser.Callback { 34 35 private StartLineParser pa = new StartLineParser(); 36 37 private String cbMethod; 38 private String cbPath; 39 private String cbQuery; 40 private String cbVersion; 41 42 public void onStartLine(String method, String path, String query, 43 String version) { 44 45 cbMethod = method; 46 cbPath = path; 47 cbQuery = query; 48 cbVersion = version; 49 } 50 51 private boolean add(String in) 52 throws Exception { 53 54 return pa.add(new PushbackByteSource(new ByteSourceSink(in.getBytes()))); 55 } 56 57 private void expect(String method, String path, String query, String version) { 58 assertEquals(method, pa.getMethod()); 59 assertEquals(path, pa.getPath()); 60 assertEquals(query, pa.getQuery()); 61 assertEquals(version, pa.getVersion()); 62 } 63 64 public void testReset() 65 throws Exception { 66 67 assertEquals(true, add("GET / HTTP/1.1\r\n")); 68 69 expect("GET", "/", "", "HTTP/1.1"); 70 71 pa.reset(); 72 expect("", "", "", ""); 73 } 74 75 public void testBasic() 76 throws Exception { 77 78 assertEquals(true, add("GET /path?query HTTP/1.0\r\n")); 79 80 expect("GET", "/path", "query", "HTTP/1.0"); 81 } 82 83 public void testPartial() 84 throws Exception { 85 86 assertEquals(false, add("GET / HTT")); 87 assertEquals(true, add("P/0.9\r\n")); 88 89 expect("GET", "/", "", "HTTP/0.9"); 90 } 91 92 public void testNoVersion() 93 throws Exception { 94 95 assertEquals(true, add("GET /path?query\r\n")); 96 97 expect("GET", "/path", "query", ""); 98 } 99 100 public void testNoVersion2() 101 throws Exception { 102 103 assertEquals(true, add("GET /path\r\n")); 104 105 expect("GET", "/path", "", ""); 106 } 107 108 public void testPartialOnEOL() 109 throws Exception { 110 111 assertEquals(false, add("GET / HTTP/1.1\r")); 112 assertEquals(true, add("\n")); 113 114 expect("GET", "/", "", "HTTP/1.1"); 115 } 116 117 public void testParseError() 118 throws Exception { 119 120 boolean threw = false; 121 122 try { 123 add("GET /\rABC"); 124 } 125 catch (ParseException ex) { 126 threw = true; 127 } 128 129 assertEquals(true, threw); 130 } 131 132 public void testDecode() 133 throws Exception { 134 135 assertEquals(true, add("GET /foo%20bar?a+b%20c HTTP/1.1\r\n")); 136 137 expect("GET", "/foo bar", "a b c", "HTTP/1.1"); 138 } 139 140 public void testCallback() 141 throws Exception { 142 143 pa.setCallback(this); 144 assertEquals(true, add("GET /foo%20bar?a+b%20c HTTP/1.1\r\n")); 145 146 assertEquals("GET", cbMethod); 147 assertEquals("/foo bar", cbPath); 148 assertEquals("a b c", cbQuery); 149 assertEquals("HTTP/1.1", cbVersion); 150 } 151 152 public void testPipeline() 153 throws Exception { 154 155 assertEquals(true, add("GET /path?query HTTP/1.0\r\n")); 156 157 expect("GET", "/path", "query", "HTTP/1.0"); 158 159 assertEquals(true, add("GET /foo HTTP/0.9\r\n")); 160 161 expect("GET", "/foo", "", "HTTP/0.9"); 162 } 163 164 public static Test suite() { 165 return new TestSuite(TestStartLineParser.class); 166 } 167 }

This page was automatically generated by Maven