Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockHttpSession


      }
    }.runTest();
  }

  public void testUpdateAccessedAttributes() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    Object value = attrs.getAttribute(KEY, RequestAttributes.SCOPE_SESSION);
    assertSame(VALUE, value);
View Full Code Here


      // expected
    }
  }

  public void testSetSessionScopedAttribute() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION);
    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }
View Full Code Here

    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }

  public void testSetSessionScopedAttributeAfterCompletion() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    attrs.requestCompleted();
    request.close();
    attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION);
    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }
View Full Code Here

    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }

  public void testSetGlobalSessionScopedAttribute() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_GLOBAL_SESSION);
    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }
View Full Code Here

    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }

  public void testSetGlobalSessionScopedAttributeAfterCompletion() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    attrs.requestCompleted();
    request.close();
    attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_GLOBAL_SESSION);
    Object value = session.getAttribute(KEY);
    assertSame(VALUE, value);
  }
View Full Code Here

    mockRequest.verify();
  }

  public void testRemoveSessionScopedAttribute() throws Exception {
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(KEY, VALUE);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes attrs = new ServletRequestAttributes(request);
    attrs.removeAttribute(KEY, RequestAttributes.SCOPE_SESSION);
    Object value = session.getAttribute(KEY);
    assertNull(value);
  }
View Full Code Here

    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
    reader.loadBeanDefinitions(new ClassPathResource("sessionScopeTests.xml", getClass()));
  }

  public void testGetFromScope() throws Exception {
    MockHttpSession session = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);

    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {
      String name = "sessionScopedObject";
      assertNull(session.getAttribute(name));
      TestBean bean = (TestBean) this.beanFactory.getBean(name);
      assertEquals(session.getAttribute(name), bean);
      assertSame(bean, this.beanFactory.getBean(name));
    }
    finally {
      RequestContextHolder.setRequestAttributes(null);
    }
View Full Code Here

      RequestContextHolder.setRequestAttributes(null);
    }
  }

  public void testDestructionAtSessionTermination() throws Exception {
    MockHttpSession session = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);

    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {
      String name = "sessionScopedDisposableObject";
      assertNull(session.getAttribute(name));
      DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
      assertEquals(session.getAttribute(name), bean);
      assertSame(bean, this.beanFactory.getBean(name));

      requestAttributes.requestCompleted();
      session.invalidate();
      assertTrue(bean.wasDestroyed());
    }
    finally {
      RequestContextHolder.setRequestAttributes(null);
    }
View Full Code Here

  }

  private void doTestDestructionWithSessionSerialization(boolean beanNameReset) throws Exception {
    Serializable serializedState = null;

    MockHttpSession session = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);

    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {
      String name = "sessionScopedDisposableObject";
      assertNull(session.getAttribute(name));
      DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
      assertEquals(session.getAttribute(name), bean);
      assertSame(bean, this.beanFactory.getBean(name));

      requestAttributes.requestCompleted();
      serializedState = session.serializeState();
      assertFalse(bean.wasDestroyed());
    }
    finally {
      RequestContextHolder.setRequestAttributes(null);
    }

    serializedState = (Serializable) SerializationTestUtils.serializeAndDeserialize(serializedState);

    session = new MockHttpSession();
    session.deserializeState(serializedState);
    request = new MockHttpServletRequest();
    request.setSession(session);
    requestAttributes = new ServletRequestAttributes(request);

    RequestContextHolder.setRequestAttributes(requestAttributes);
    try {
      String name = "sessionScopedDisposableObject";
      assertNotNull(session.getAttribute(name));
      DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
      assertEquals(session.getAttribute(name), bean);
      assertSame(bean, this.beanFactory.getBean(name));

      requestAttributes.requestCompleted();
      session.invalidate();
      assertTrue(bean.wasDestroyed());

      if (beanNameReset) {
        assertNull(bean.getBeanName());
      }
View Full Code Here

  public void testRequireSessionWithSession() throws Exception {
    TestController mc = new TestController();
    mc.setRequireSession(true);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/ok.html");
    request.setSession(new MockHttpSession(null));
    HttpServletResponse response = new MockHttpServletResponse();
    mc.handleRequest(request, response);
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.MockHttpSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.