Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockHttpSession


  }

  public void testInvokesCorrectMethodWithSession() throws Exception {
    TestMaController mc = new TestMaController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/inSession.html");
    request.setSession(new MockHttpSession(null));
    HttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = mc.handleRequest(request, response);
    assertTrue("Invoked inSession method", mc.wasInvoked("inSession"));
    assertTrue("view name is welcome", mv.getViewName().equals("inSession"));
    assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
View Full Code Here


    TestMaController mc = new TestMaController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/commandInSession.html");
    request.addParameter("name", "rod");
    request.addParameter("age", "32");

    request.setSession(new MockHttpSession(null));
    HttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = mc.handleRequest(request, response);
    assertTrue("Invoked commandInSession method", mc.wasInvoked("commandInSession"));
    assertTrue("view name is commandInSession", mv.getViewName().equals("commandInSession"));
    assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
View Full Code Here

  public void setUp() {
    this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
    this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
 
    MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
    oldRequestWithSession.setSession(new MockHttpSession());
    this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
   
    MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
    newRequestWithSession.setSession(new MockHttpSession());
    this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
  }
View Full Code Here

    assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0);
  }

  public void testSessionScoping() throws Exception {
    MockHttpSession oldSession = new MockHttpSession();
    MockHttpSession newSession = new MockHttpSession();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(oldSession);
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
View Full Code Here

    public void testSetLocaleInSessionWhenSessionNotNull() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter("locale", "es");

        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setSession(new MockHttpSession(null));
       
        filter.doFilter(request, response, new MockFilterChain());
       
        // session not null, should result in not null
        Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
View Full Code Here

    public void testSetInvalidLocale() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter("locale", "foo");

        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setSession(new MockHttpSession(null));
       
        filter.doFilter(request, response, new MockFilterChain());
       
        // a locale will get set regardless - there's no such thing as an invalid one
        assertNotNull(request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY));
View Full Code Here

    public void testJstlLocaleIsSet() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter("locale", "es");

        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setSession(new MockHttpSession(null));
       
        filter.doFilter(request, response, new MockFilterChain());
       
        assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE));
    }
View Full Code Here

        assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE));
    }

    public void testLocaleAndCountry() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setSession(new MockHttpSession());
        request.addParameter("locale", "zh_TW");

        MockHttpServletResponse response = new MockHttpServletResponse();
        filter.doFilter(request, response, new MockFilterChain());
View Full Code Here

    assertEquals("bar", request.getSession().getAttribute("foo"));
  }

  @Test
  public void session() throws Exception {
    MockHttpSession session = new MockHttpSession(this.servletContext);
    session.setAttribute("foo", "bar");
    this.builder.session(session);
    this.builder.sessionAttr("baz", "qux");

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
View Full Code Here

public class HttpSessionOAuthRememberMeServicesTests {

  @Test
  public void testEmptySession() {

    MockHttpSession mockHttpSession = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setSession(mockHttpSession);
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.