I need an example of trying to mock an httpsession.
If I do not provide a implementation, the test fails
on the call to request.getSession(true)
Can someone point me to a test which uses a mock
httpsession?
Thanks!
I tried to setup a mock for the http session but it
fails with the following message:
.F
Time: 0.16
There was 1 failure:
1)
testDoGet(com.alcoadirect.jsso.SimpleServletTest)junit.framework.AssertionFailedError:
mockHttpServletRequest: Unexpected call:
getSession(<true>)
Expected one of:
getParameter(< = email>) [not called]
getParameter(< = password>) [not called]
getSession(< = true>) [not called]
at com.mockobjects.dynamic.Mock.invoke(Mock.java:91)
at $Proxy0.getSession(Unknown Source)
at
com.alcoadirect.jsso.initializers.AlcoaDirectSession.login(AlcoaDirectSession.java:150)
at
com.alcoadirect.jsso.SimpleServlet.doPost(SimpleServlet.java:26)
at
com.alcoadirect.jsso.SimpleServlet.doGet(SimpleServlet.java:19)
at
com.alcoadirect.jsso.SimpleServletTest.testDoGet(SimpleServletTest.java:81)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
at
com.alcoadirect.jsso.SimpleServletTest.main(SimpleServletTest.java:36)
FAILURES!!!
Tests run: 1, Failures: 1, Errors: 0
Here is the code that I invented.
Mock mockHttpServletRequest = new
Mock(HttpServletRequest.class);
Mock mockHttpServletResponse = new
OrderedMock(HttpServletResponse.class, "Response with
non-default name");
Mock mockHttpSession = new Mock(HttpSession.class);
mockHttpServletRequest.expectAndReturn(
"getParameter", "email", "phi...@al..." );
mockHttpServletRequest.expectAndReturn(
"getParameter", "password", "on3job" );
mockHttpServletRequest.expectAndReturn(
"getSession","true",mockHttpSession );
|