use of com.mockrunner.mock.web.MockHttpServletRequest in project geode by apache.
the class CommonTests method testIsRequestedSessionIdFromCookie.
@Test
public void testIsRequestedSessionIdFromCookie() {
MockHttpServletRequest mRequest = getWebMockObjectFactory().getMockRequest();
Cookie c = new Cookie("JSESSIONID", "1-GF");
mRequest.addCookie(c);
doFilter();
HttpServletRequest request = (HttpServletRequest) getFilteredRequest();
request.getSession();
assertTrue(request.isRequestedSessionIdFromCookie());
}
use of com.mockrunner.mock.web.MockHttpServletRequest 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.MockHttpServletRequest 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.MockHttpServletRequest in project geode by apache.
the class CommonTests method testIsRequestedSessionIdFromURL.
@Test
public void testIsRequestedSessionIdFromURL() {
MockHttpServletRequest mRequest = getWebMockObjectFactory().getMockRequest();
mRequest.setRequestURL("/foo/bar;jsessionid=1");
doFilter();
HttpServletRequest request = (HttpServletRequest) getFilteredRequest();
request.getSession();
assertFalse("Session ID should not be from cookie", request.isRequestedSessionIdFromCookie());
assertTrue("Session ID should be from URL", request.isRequestedSessionIdFromURL());
}
use of com.mockrunner.mock.web.MockHttpServletRequest in project cayenne by apache.
the class HessianServiceTest method testGetSession.
@Test
public void testGetSession() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(Constants.SERVER_ROP_EVENT_BRIDGE_FACTORY_PROPERTY, MockEventBridgeFactory.class.getName());
ObjectContextFactory factory = new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return null;
}
public ObjectContext createContext() {
return null;
}
};
HessianService service = new HessianService(factory, map);
MockHttpServletRequest request = new MockHttpServletRequest();
HttpSession session = new MockHttpSession();
request.setSession(session);
// for some reason need to call this to get session activated in the
// mock request
request.getSession();
try {
ServiceContext.begin(request, null, null, null);
assertSame(session, service.getSession(false));
} finally {
ServiceContext.end();
}
}
Aggregations