/** * Creates the {@link com.mockrunner.mock.web.MockHttpSession} using <code>new</code>. * This method can be overridden to return a subclass of {@link com.mockrunner.mock.web.MockHttpSession}. * @return the {@link com.mockrunner.mock.web.MockHttpSession} */ public MockHttpSession createMockSession() { return new MockHttpSession(); }
/** * Creates the {@link com.mockrunner.mock.web.MockHttpSession} using <code>new</code>. * This method can be overridden to return a subclass of {@link com.mockrunner.mock.web.MockHttpSession}. * @return the {@link com.mockrunner.mock.web.MockHttpSession} */ public MockHttpSession createMockSession() { return new MockHttpSession(); }
/** * Creates the {@link com.mockrunner.mock.web.MockHttpSession} using <code>new</code>. * This method can be overridden to return a subclass of {@link com.mockrunner.mock.web.MockHttpSession}. * @return the {@link com.mockrunner.mock.web.MockHttpSession} */ public MockHttpSession createMockSession() { return new MockHttpSession(); }
@Override @Before public void setUp() throws Exception { super.setUp(); ComponentsTestUtil.setImplementation(WebContextFactory.class, WebContextFactoryImpl.class); User dummy = createNiceMock(User.class); expect(dummy.getName()).andReturn("admin"); expect(dummy.getPassword()).andReturn("admin"); mocks = new Object[]{dummy}; replay(mocks); MockHttpSession session = new MockHttpSession(); MockHttpServletRequest req = new MockHttpServletRequest(); req.setSession(session); MgnlContext.setInstance(ContextFactory.getInstance().createWebContext(req, null, null)); ((UserContextImpl) MgnlContext.getInstance()).login(MockUtil.createSubject(dummy)); }
@Override @Before public void setUp() throws Exception { super.setUp(); super.setAutoStart(true); ComponentsTestUtil.setImplementation(WebContextFactory.class, WebContextFactoryImpl.class); User dummy = createNiceMock(User.class); expect(dummy.getName()).andReturn("admin"); expect(dummy.getPassword()).andReturn("admin"); mocks = new Object[]{dummy}; replay(mocks); MockHttpSession session = new MockHttpSession(); MockHttpServletRequest req = new MockHttpServletRequest(); req.setSession(session); MgnlContext.setInstance(ContextFactory.getInstance().createWebContext(req, null, null)); ((UserContextImpl) MgnlContext.getInstance()).login(MockUtil.createSubject(dummy)); }
@Test public void testServletProvidersWhenWebContextSet() { // GIVEN MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpSession session = new MockHttpSession(); request.setSession(session); MockWebContext webContext = new MockWebContext(); webContext.setRequest(request); webContext.setResponse(response); MgnlContext.setInstance(webContext); GuiceComponentProvider provider = createComponentProviderWithSingleImplementation(MockSingletonWithContextProviders.class); // WHEN MockSingletonWithContextProviders component = provider.getComponent(MockSingletonWithContextProviders.class); // THEN assertSame(request, component.requestProvider.get()); assertSame(session, component.sessionProvider.get()); assertSame(response, component.responseProvider.get()); }
@Test public void testSessionScope() { // GIVEN MockWebContext webContext = new MockWebContext(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(new MockHttpSession()); webContext.setRequest(request); MgnlContext.setInstance(webContext); GuiceComponentProvider provider = createComponentProviderWithSingleImplementation(MockSessionScopedObject.class); // WHEN MockSessionScopedObject component = provider.getComponent(MockSessionScopedObject.class); // THEN assertNotNull(component); assertSame(component, provider.getComponent(MockSessionScopedObject.class)); // WHEN we switch request webContext = new MockWebContext(); request = new MockHttpServletRequest(); webContext.setRequest(request); request.setSession(new MockHttpSession()); MgnlContext.setInstance(webContext); // THEN we get a new object MockSessionScopedObject component2 = provider.getComponent(MockSessionScopedObject.class); assertNotNull(component2); assertNotSame(component2, component); }