Search in sources :

Example 1 with MockHttpServletResponse

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);
}
Also used : MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 2 with MockHttpServletResponse

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());
}
Also used : MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(com.mockrunner.mock.web.MockHttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with MockHttpServletResponse

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());
}
Also used : Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with MockHttpServletResponse

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());
}
Also used : Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 5 with MockHttpServletResponse

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"));
}
Also used : Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)8 Test (org.junit.Test)8 Cookie (javax.servlet.http.Cookie)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 MockHttpSession (com.mockrunner.mock.web.MockHttpSession)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 MockFilterChain (com.mockrunner.mock.web.MockFilterChain)1 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)1 MockServletContext (com.mockrunner.mock.web.MockServletContext)1 BaseContext (org.apache.cayenne.BaseContext)1 DataChannel (org.apache.cayenne.DataChannel)1 MockDataChannel (org.apache.cayenne.MockDataChannel)1 ObjectContext (org.apache.cayenne.ObjectContext)1 CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)1 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)1 DIBootstrap (org.apache.cayenne.di.DIBootstrap)1 Injector (org.apache.cayenne.di.Injector)1 Module (org.apache.cayenne.di.Module)1