|
From: <lau...@ma...> - 2002-04-22 17:26:47
|
Hi,
I'm having a hard time wrapping my head around this MO concept. I think I
need some help. I'm writing a general purpose parameter parser for servlets.
Basically, I want the servlet to validate that all required parameters are
part of the request. So in my parser tests, I want to use a mock object (a
MockHttpServletRequest) to implement the request parameter of my method.
Now, my test looks like this:
/*
* Test for ParameterParser
*/
package ca.masq.servlet;
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
import javax.servlet.http.HttpServletRequest;
import com.mockobjects.*;
import com.mockobjects.*;
import com.mockobjects.util.TestCaseMo;
import com.mockobjects.servlet.MockHttpServletRequest;
public class ParameterParser_UnitTest extends TestCaseMo {
ParameterParser parser;
MockHttpServletRequest servletRequest;
public ParameterParser_UnitTest(java.lang.String testName) {
super(testName);
}
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(ParameterParser_UnitTest.class);
return suite;
}
public void setUp() {
servletRequest = new MockHttpServletRequest();
}
public void testCreateWithNullRequest() {
try {
parser = new ParameterParser(new String[] {"foo"}, null);
fail("Exception expected");
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
}
.
.
.
/*
* No error occurs here.
*/
public void testNoMissingParameters() {
String[] requiredParams = { "param1", "param2", "param3" };
servletRequest.setupAddParameter("param1", "value1");
servletRequest.setupAddParameter("param2", "value2");
servletRequest.setupAddParameter("param3", "value3");
parser = new ParameterParser(requiredParams, servletRequest);
assertTrue("Required parameter missing", parser.getMissingParameters() == null);
}
}
in the testNoMissingParameters() method, I get an error. This kinda tells me
that I'm not setting up the servlet properly. Am I correct in my assessment?
What am I not understanding at this point?
Thanks,
L
--
Laurent Duperval <mailto:lau...@ma...>
You won't strain your eyes if you look at the bright side of things
--Winston Churchill
|