Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockHttpSession


    }

    @Test
    public void testHandleLogin() throws AuthenticationException {

        MockHttpSession mockHttpSession = new MockHttpSession();
        mockHttpSession.setAttribute(LoginController.REQUESTED_URL, "someUrl");

        String view = this.loginController.handleLogin("john", "secret", mockHttpSession);

        Account account = (Account) mockHttpSession.getAttribute(LoginController.ACCOUNT_ATTRIBUTE);

        assertNotNull(account);
        assertEquals("John", account.getFirstName());
        assertEquals("Doe", account.getLastName());
        assertNull(mockHttpSession.getAttribute(LoginController.REQUESTED_URL));
        assertEquals("redirect:someUrl", view);

        // Test the different view selection choices
        mockHttpSession = new MockHttpSession();
        view = this.loginController.handleLogin("john", "secret", mockHttpSession);
        assertEquals("redirect:/index.htm", view);

        mockHttpSession = new MockHttpSession();
        mockHttpSession.setAttribute(LoginController.REQUESTED_URL, "abclogindef");
        view = this.loginController.handleLogin("john", "secret", mockHttpSession);
        assertEquals("redirect:/index.htm", view);
    }
View Full Code Here


    String xml = loadXmlFromFile(getXmlDatasetPath() + filename + ".xml");
   
    HtmlForm fakeForm = new HtmlForm();
    fakeForm.setXmlData(xml);
    fakeForm.setForm(new Form(1));
    FormEntrySession session = new FormEntrySession(patient, null, FormEntryContext.Mode.ENTER, fakeForm, new MockHttpSession());
        session.setAttributes(getFormEntrySessionAttributes());
        session.getHtmlToDisplay();
    return session;
  }
View Full Code Here

    String xml = loadXmlFromFile(getXmlDatasetPath() + filename + ".xml");
   
    HtmlForm fakeForm = new HtmlForm();
    fakeForm.setXmlData(xml);
    fakeForm.setForm(new Form(1));
    FormEntrySession session = new FormEntrySession(patient, encounter, FormEntryContext.Mode.VIEW, fakeForm, new MockHttpSession());
        session.setAttributes(getFormEntrySessionAttributes());
        session.getHtmlToDisplay();
    return session;
  }
View Full Code Here

    String xml = loadXmlFromFile(getXmlDatasetPath() + filename + ".xml");
   
    HtmlForm fakeForm = new HtmlForm();
    fakeForm.setXmlData(xml);
    fakeForm.setForm(new Form(1));
    FormEntrySession session = new FormEntrySession(patient, encounter, FormEntryContext.Mode.EDIT, fakeForm, new MockHttpSession());
        session.setAttributes(getFormEntrySessionAttributes());
        session.getHtmlToDisplay();
    return session;
  }
View Full Code Here

     */
    @Test
    @Verifies(value = "should find a location by session attribute", method = "getLocation(String,FormEntrySession)")
    public void getLocation_shouldFindALocationBySessionAttribute() throws Exception {
        String attrName = "emr.sessionLocation";
        MockHttpSession httpSession = new MockHttpSession();
        httpSession.setAttribute(attrName, "2");

        FormEntryContext formEntryContext = new FormEntryContext(FormEntryContext.Mode.ENTER);
        formEntryContext.setHttpSession(httpSession);

        Assert.assertEquals("2", HtmlFormEntryUtil.getLocation("SessionAttribute:" + attrName, formEntryContext).getId().toString());
View Full Code Here

    }

    protected void initSession(ActionContext actionContext) {
        if (actionContext.getSession() == null) {
            actionContext.setSession(new HashMap<String, Object>());
            request.setSession(new MockHttpSession(servletContext));
        }
    }
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

  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);
  }

  @Test
  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

  }
 
  @Test
  public void testGetCacheControlDataExistsInPrivateCache() {
    // mock 2 requests, have to share sessionId for private cache
    MockHttpSession mockSession = new MockHttpSession();
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setSession(mockSession);
    MockHttpServletRequest nextHttpRequest = new MockHttpServletRequest();
    nextHttpRequest.setSession(mockSession);
   
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.