use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testGetLastAccessedTime2.
/**
* Test that repeated accesses update the last accessed time
*/
@Test
public void testGetLastAccessedTime2() throws Exception {
// Setup
CallbackServlet s = (CallbackServlet) getServlet();
s.setCallback(new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) {
request.getSession();
}
});
doFilter();
HttpServletRequest request = (HttpServletRequest) getFilteredRequest();
long lastAccess = request.getSession().getLastAccessedTime();
assertTrue("Session should have a non-zero last access time", lastAccess > 0);
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
MockHttpServletRequest mRequest = getWebMockObjectFactory().createMockRequest();
mRequest.setRequestURL("/test/foo/bar");
mRequest.setContextPath(CONTEXT_PATH);
mRequest.addCookie(cookie);
getWebMockObjectFactory().addRequestWrapper(mRequest);
Thread.sleep(50);
doFilter();
assertTrue("Last access time should be changing", request.getSession().getLastAccessedTime() > lastAccess);
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testIsNew2.
/**
* Subsequent calls should not return true
*/
@Test
public void testIsNew2() throws Exception {
// Setup
CallbackServlet s = (CallbackServlet) getServlet();
s.setCallback(new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) {
request.getSession();
}
});
doFilter();
HttpServletRequest request = (HttpServletRequest) getFilteredRequest();
request.getSession();
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
MockHttpServletRequest mRequest = getWebMockObjectFactory().createMockRequest();
mRequest.setRequestURL("/test/foo/bar");
mRequest.setContextPath(CONTEXT_PATH);
mRequest.addCookie(cookie);
getWebMockObjectFactory().addRequestWrapper(mRequest);
doFilter();
request = (HttpServletRequest) getFilteredRequest();
HttpSession s1 = request.getSession();
assertFalse("Subsequent isNew() calls should be false", request.getSession().isNew());
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testGetId2.
/**
* Test that multiple calls from the same client return the same session id
*/
@Test
public void testGetId2() throws Exception {
doFilter();
String sessionId = ((HttpServletRequest) getFilteredRequest()).getSession().getId();
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
getWebMockObjectFactory().getMockRequest().addCookie(cookie);
doFilter();
assertEquals("Session Ids should be the same", sessionId, ((HttpServletRequest) getFilteredRequest()).getSession().getId());
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testGetCreationTime2.
/**
* Test that multiple calls from the same client don't change the creation time.
*/
@Test
public void testGetCreationTime2() throws Exception {
doFilter();
long creationTime = ((HttpServletRequest) getFilteredRequest()).getSession().getCreationTime();
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
getWebMockObjectFactory().getMockRequest().addCookie(cookie);
doFilter();
assertEquals("Session creation time should be the same", creationTime, ((HttpServletRequest) getFilteredRequest()).getSession().getCreationTime());
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testGetAttributeSession2.
/**
* Are attributes preserved across client requests?
*/
@Test
public void testGetAttributeSession2() throws Exception {
doFilter();
((HttpServletRequest) getFilteredRequest()).getSession().setAttribute("foo", "bar");
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
getWebMockObjectFactory().getMockRequest().addCookie(cookie);
doFilter();
HttpServletRequest request = (HttpServletRequest) getFilteredRequest();
assertEquals("bar", request.getSession().getAttribute("foo"));
}
Aggregations