use of com.mockrunner.mock.web.MockHttpServletResponse in project geode by apache.
the class CommonTests method testGetSession2.
@Test
public void testGetSession2() throws Exception {
doFilter();
HttpSession session1 = ((HttpServletRequest) getFilteredRequest()).getSession();
MockHttpServletResponse response = getWebMockObjectFactory().getMockResponse();
Cookie cookie = (Cookie) response.getCookies().get(0);
getWebMockObjectFactory().getMockRequest().addCookie(cookie);
doFilter();
HttpSession session2 = ((HttpServletRequest) getFilteredRequest()).getSession();
assertEquals("Session objects across requests should be the same", session1, session2);
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project cayenne by apache.
the class CayenneFilterTest method testDoFilter.
@Test
public void testDoFilter() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
CayenneFilter filter = new CayenneFilter();
filter.init(config);
CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector().getInstance(RequestHandler.class);
assertEquals(0, handler.getStarted());
assertEquals(0, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(1, handler.getStarted());
assertEquals(1, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(2, handler.getStarted());
assertEquals(2, handler.getEnded());
}
use of com.mockrunner.mock.web.MockHttpServletResponse in project cayenne by apache.
the class ServletContextHandlerTest method testRequestStart_bindContext.
@Test
public void testRequestStart_bindContext() {
Module module = binder -> {
binder.bind(DataChannel.class).to(MockDataChannel.class);
binder.bind(ObjectContextFactory.class).toInstance(new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return mock(ObjectContext.class);
}
public ObjectContext createContext() {
return mock(ObjectContext.class);
}
});
};
Injector injector = DIBootstrap.createInjector(module);
SessionContextRequestHandler handler = new SessionContextRequestHandler();
injector.injectMembers(handler);
MockHttpSession session = new MockHttpSession();
BaseContext.bindThreadObjectContext(null);
try {
MockHttpServletRequest request1 = new MockHttpServletRequest();
MockHttpServletResponse response1 = new MockHttpServletResponse();
request1.setSession(session);
handler.requestStart(request1, response1);
ObjectContext c1 = BaseContext.getThreadObjectContext();
assertNotNull(c1);
handler.requestEnd(request1, response1);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
MockHttpServletRequest request2 = new MockHttpServletRequest();
MockHttpServletResponse response2 = new MockHttpServletResponse();
request2.setSession(session);
handler.requestStart(request2, response2);
ObjectContext c2 = BaseContext.getThreadObjectContext();
assertSame(c1, c2);
handler.requestEnd(request2, response2);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
MockHttpServletRequest request3 = new MockHttpServletRequest();
MockHttpServletResponse response3 = new MockHttpServletResponse();
request3.setSession(new MockHttpSession());
handler.requestStart(request3, response3);
ObjectContext c3 = BaseContext.getThreadObjectContext();
assertNotNull(c3);
assertNotSame(c1, c3);
handler.requestEnd(request3, response3);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
} finally {
BaseContext.bindThreadObjectContext(null);
}
}
Aggregations