Tests that exercise the HTTP request.
| Method from org.apache.cactus.sample.servlet.unit.TestHttpRequest Detail: |
public void beginGetPathTranslated(WebRequest theRequest) {
theRequest.setURL("jakarta.apache.org", "/mywebapp", "/myservlet",
"/test1/test2", "PARAM1=value1");
}
Verify that HttpServletRequestWrapper.getPathTranslated()
takes into account the simulated URL (if any). |
public void beginSendUserDataAndReadWithObjectInputStream(WebRequest theRequest) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject("Test with a String object");
oos.flush();
theRequest.setUserData(new ByteArrayInputStream(baos.toByteArray()));
theRequest.setContentType("application/octet-stream");
}
Verify that we can send arbitrary data in the request body and read the
data back on the server side using an ObjectInputStream. |
public void beginSendUserDataAndReadWithReader(WebRequest theRequest) {
ByteArrayInputStream bais = new ByteArrayInputStream(
"< data >some data to send in the body< /data >".getBytes());
theRequest.setUserData(bais);
theRequest.setContentType("text/xml");
}
Verify that we can send arbitrary data in the request body and read the
data back on the server side using a Reader. |
public void testGetPathTranslated() {
String nativePathInfo = File.separator + "test1" + File.separator
+ "test2";
String pathTranslated = request.getPathTranslated();
// Should be null if getRealPath("/") is null
if (request.getRealPath("/") == null)
{
assertNull("Should have been null", pathTranslated);
}
else
{
assertNotNull("Should not be null", pathTranslated);
assertTrue("Should end with [" + nativePathInfo + "] but got ["
+ pathTranslated + "] instead",
pathTranslated.endsWith(nativePathInfo));
}
}
Verify that HttpServletRequestWrapper.getPathTranslated()
takes into account the simulated URL (if any) or null in situations
where the servlet container cannot determine a valid file path for
these methods, such as when the web application is executed from an
archive, on a remote file system not accessible locally, or in a
database (see section SRV.4.5 of the Servlet 2.3 spec). |
public void testRemoteClientCheck() {
request.setRemoteIPAddress("192.168.0.1");
request.setRemoteHostName("atlantis");
request.setRemoteUser("george");
assertEquals("192.168.0.1", request.getRemoteAddr());
assertEquals("atlantis", request.getRemoteHost());
assertEquals("george", request.getRemoteUser());
}
Verify that we can simulate the client remote IP address and the client
remote host name. |
public void testSendUserDataAndReadWithObjectInputStream() throws Exception {
InputStream in = request.getInputStream();
ObjectInputStream ois = new ObjectInputStream(in);
String data = (String) ois.readObject();
assertNotNull(data);
assertEquals("Test with a String object", data);
}
Verify that we can send arbitrary data in the request body and read the
data back on the server side using an ObjectInputStream. |
public void testSendUserDataAndReadWithReader() throws Exception {
String buffer;
StringBuffer body = new StringBuffer();
BufferedReader reader = request.getReader();
while ((buffer = reader.readLine()) != null)
{
body.append(buffer);
}
assertEquals("< data >some data to send in the body< /data >",
body.toString());
assertEquals("text/xml", request.getContentType());
}
Verify that we can send arbitrary data in the request body and read the
data back on the server side using a Reader. |