Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.6.1
-
None
-
None
Description
I have a servlet which operates using POST, taking parameters off the URL (GET style), and the processes the body of the request (POST style).
i.e. my users post to the URL /foo?foo=bar with a bunch of data as the body of the post.
it seems impossible to do this using cactus (and therefore impossible to test my servlet). Note that the servlet does not rely on the parameter being in the URL, simply that the parameter is set in the received request. To demonstrate the behaviour, I have written a test case, one of which I would like to pass (or both!), so that I use the functionality provided.
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
public class CactusTest extends ServletTestCase
{
public void beginTest(WebRequest webRequest)
{
webRequest.addParameter("foo", "bar", "GET");
webRequest.setUserData(new ByteArrayInputStream(new byte[]
));
}
public void testTest() throws IOException
{ assertEquals("Parameter not set", "bar", request.getParameter("foo")); assertEquals("Should be able to read data", 'C', request.getInputStream().read()); } public void beginPostTest(WebRequest webRequest)
{
webRequest.addParameter("foo", "bar", "POST");
webRequest.setUserData(new ByteArrayInputStream(new byte[]
));
}
public void testPostTest() throws IOException
{ assertEquals("Parameter not set", "bar", request.getParameter("foo")); assertEquals("Should be able to read data", 1, request.getInputStream().read()); }}