1 20 package org.apache.cactus.sample.servlet.unit; 21 22 import org.apache.cactus.ServletTestCase; 23 import org.apache.cactus.WebRequest; 24 25 30 public class TestSetURL extends ServletTestCase 31 { 32 39 public void beginSimulatedURLBasics(WebRequest theRequest) 40 { 41 theRequest.setURL("jakarta.apache.org", "", "/test/test.jsp", null, 42 null); 43 } 44 45 49 public void testSimulatedURLBasics() 50 { 51 assertEquals("/test/test.jsp", request.getRequestURI()); 52 assertEquals("jakarta.apache.org", request.getServerName()); 53 assertEquals(80, request.getServerPort()); 54 assertEquals("", request.getContextPath()); 55 } 56 57 59 65 public void beginSimulatedURL1(WebRequest theRequest) 66 { 67 theRequest.setURL("jakarta.apache.org", "/mywebapp", "/test/test.jsp", 68 null, null); 69 } 70 71 74 public void testSimulatedURL1() 75 { 76 assertEquals("/mywebapp/test/test.jsp", request.getRequestURI()); 77 assertEquals("jakarta.apache.org", request.getServerName()); 78 assertEquals(80, request.getServerPort()); 79 assertEquals("/mywebapp", request.getContextPath()); 80 } 81 82 84 90 public void beginSimulatedURL2(WebRequest theRequest) 91 { 92 theRequest.setURL("jakarta.apache.org", "/catalog", "/lawn", 93 "/index.html", null); 94 } 95 96 99 public void testSimulatedURL2() 100 { 101 assertEquals("jakarta.apache.org", request.getServerName()); 102 assertEquals("/catalog/lawn/index.html", request.getRequestURI()); 103 assertEquals(80, request.getServerPort()); 104 assertEquals("/catalog", request.getContextPath()); 105 assertEquals("/lawn", request.getServletPath()); 106 assertEquals("/index.html", request.getPathInfo()); 107 } 108 109 111 117 public void beginSimulatedURL3(WebRequest theRequest) 118 { 119 theRequest.setURL("jakarta.apache.org", "/catalog", "/garden", 120 "/implements/", null); 121 } 122 123 126 public void testSimulatedURL3() 127 { 128 assertEquals("jakarta.apache.org", request.getServerName()); 129 assertEquals("/catalog/garden/implements/", request.getRequestURI()); 130 assertEquals(80, request.getServerPort()); 131 assertEquals("/catalog", request.getContextPath()); 132 assertEquals("/garden", request.getServletPath()); 133 assertEquals("/implements/", request.getPathInfo()); 134 } 135 136 138 144 public void beginSimulatedURL4(WebRequest theRequest) 145 { 146 theRequest.setURL("jakarta.apache.org", "/catalog", 147 "/help/feedback.jsp", null, null); 148 } 149 150 153 public void testSimulatedURL4() 154 { 155 assertEquals("jakarta.apache.org", request.getServerName()); 156 assertEquals("/catalog/help/feedback.jsp", request.getRequestURI()); 157 assertEquals(80, request.getServerPort()); 158 assertEquals("/catalog", request.getContextPath()); 159 assertEquals("/help/feedback.jsp", request.getServletPath()); 160 } 161 162 164 172 public void beginSimulatedURL5(WebRequest theRequest) 173 { 174 theRequest.setURL("jakarta.apache.org", "/catalog", 175 "/help/feedback.jsp", null, "PARAM1=param1&PARAM2=&PARAM3=param3"); 176 } 177 178 183 public void testSimulatedURL5() 184 { 185 assertEquals("jakarta.apache.org", request.getServerName()); 186 assertEquals("/catalog/help/feedback.jsp", request.getRequestURI()); 187 assertEquals(80, request.getServerPort()); 188 assertEquals("/catalog", request.getContextPath()); 189 assertEquals("/help/feedback.jsp", request.getServletPath()); 190 assertEquals("PARAM1=param1&PARAM2=&PARAM3=param3", 191 request.getQueryString()); 192 assertEquals(request.getParameter("PARAM1"), "param1"); 193 assertEquals(request.getParameter("PARAM2"), ""); 194 assertEquals(request.getParameter("PARAM3"), "param3"); 195 } 196 197 199 206 public void beginSimulatedURLNullValues(WebRequest theRequest) 207 { 208 theRequest.setURL(null, null, null, null, null); 209 } 210 211 215 public void testSimulatedURLNullValues() 216 { 217 assertNotNull(request.getServerName()); 218 assertTrue(request.getServerPort() > 0); 219 assertNotNull(request.getContextPath()); 220 assertNotNull(request.getServletPath()); 221 assertNull(request.getPathInfo()); 222 assertNull(request.getQueryString()); 223 } 224 } 225 | Popular Tags |