Example usage for org.springframework.mock.web MockHttpSession MockHttpSession

List of usage examples for org.springframework.mock.web MockHttpSession MockHttpSession

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpSession MockHttpSession.

Prototype

public MockHttpSession() 

Source Link

Document

Create a new MockHttpSession with a default MockServletContext .

Usage

From source file:ControllersTest.HomeControllerTest.java

@Test
public void homeControllerTest() throws Exception {
    session = new MockHttpSession();
    ModelMap modelMap = new ModelMap();
    String viewName = controller.showForm(modelMap, session);
    assertEquals("index", viewName);
    String theme = session.getAttribute("theme").toString();
    assertEquals("bright", theme);
    assertTrue(modelMap.containsAttribute("tags"));
    assertTrue(modelMap.containsAttribute("topUsers"));
    assertTrue(modelMap.containsAttribute("topAds"));
}

From source file:com.healthcit.cacure.web.controller.LogoutControllerTest.java

@Test
public void testProcessLogout() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    UserCredentials userCredentials = new UserCredentials();
    userCredentials.setUserName("Testing");
    userCredentials.setPassword("TestPassword");
    MockHttpSession session = new MockHttpSession();
    session.setAttribute(Constants.CREDENTIALS, userCredentials);
    request.setSession(session);//from   ww  w  .j a  v a2 s.  c  om
    RedirectView actual = (RedirectView) logoutController.processLogout(request);
    RedirectView expected = new RedirectView(Constants.HOME_URI, true);
    Assert.assertNotNull(actual);
    Assert.assertNull(session.getAttribute(Constants.CREDENTIALS));
    Assert.assertEquals(expected.getUrl(), actual.getUrl());
}

From source file:ControllersTest.AddControllerTest.java

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    session = new MockHttpSession();
    map = new ModelMap();
    request = new MockHttpServletRequest();
}

From source file:org.openmrs.module.kenyaemr.form.KenyaEmrVelocityFunctionsTest.java

@Before
public void setup() throws Exception {
    executeDataSet("test-data.xml");

    HttpSession httpSession = new MockHttpSession();
    String formXml = "<htmlform></htmlform>";

    // Create a session for dummy form with patient #6
    Patient patient6 = Context.getPatientService().getPatient(6);
    FormEntrySession formSession1 = new FormEntrySession(patient6, formXml, httpSession);
    functionsForSession1 = new KenyaEmrVelocityFunctions(formSession1);

    // Create a session for dummy form with patient #7
    Patient patient7 = Context.getPatientService().getPatient(7);
    FormEntrySession formSession2 = new FormEntrySession(patient7, formXml, httpSession);
    functionsForSession2 = new KenyaEmrVelocityFunctions(formSession2);
}

From source file:ControllersTest.CommentControllerTest.java

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    request = new MockHttpServletRequest();
    session = new MockHttpSession();
}

From source file:org.openmrs.module.kenyaemr.form.velocity.UiVelocityFunctionsTest.java

/**
 * Setup each test//from   ww  w .  j av a2 s.  c  o  m
 */
@Before
public void setup() throws Exception {
    HttpSession httpSession = new MockHttpSession();
    String formXml = "<htmlform></htmlform>";

    // Create a session for dummy form with patient #7
    FormEntrySession formSession = new FormEntrySession(TestUtils.getPatient(7), formXml, httpSession);
    functions = new UiVelocityFunctions(formSession, ui);
}

From source file:org.eclipse.virgo.snaps.core.internal.webapp.container.SnapHttpServletTests.java

@Before
public void before() {
    MockServletContext parentContext = new MockServletContext();
    Bundle bundle = createMock(Bundle.class);
    SnapServletContext context = new SnapServletContext(parentContext, bundle, "/contextPath");

    this.parentSession = new MockHttpSession();
    this.snapSession = new SnapHttpSession(parentSession, context);
}

From source file:org.openmrs.ui.framework.PageControllerTest.java

@Test
public void shouldHandleFileDownloadReturnType() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession();
    Session uiSession = new Session(session);

    PageFactory pageFactory = mock(PageFactory.class);
    when(pageFactory.handle(any(PageRequest.class)))
            .thenThrow(new FileDownload("download.txt", "text/plain", "File contents".getBytes()));

    SessionFactory sessionFactory = mock(SessionFactory.class);
    when(sessionFactory.getSession(session)).thenReturn(uiSession);

    PageController controller = new PageController();
    controller.setPageFactory(pageFactory);
    controller.setSessionFactory(sessionFactory);

    controller.handlePath("somemodule/download", request, response, new ExtendedModelMap(), session);

    Assert.assertEquals("text/plain", response.getContentType());
    Assert.assertEquals("File contents", response.getContentAsString());
    Assert.assertEquals("attachment; filename=download.txt", response.getHeader("Content-Disposition"));
}

From source file:ControllersTest.HomeControllerTest.java

@Test
public void changeThemeTest() throws SQLException {
    session = new MockHttpSession();
    session.setAttribute("theme", "bright");
    String viewName = controller.changeTheme(session);
    assertEquals("redirect:index.htm", viewName);
    assertEquals(session.getAttribute("theme").toString(), "dark");
    session.setAttribute("theme", "dark");
    controller.changeTheme(session);//from   w  w w .ja v  a 2 s  .  co m
    assertEquals(session.getAttribute("theme").toString(), "bright");
}

From source file:org.apache.jetspeed.portlets.sso.TestSSOSiteCredentialsProvider.java

@Override
public void setUp() {
    session = new MockHttpSession();

    ssoSiteCredsOfSubject = new ArrayList<SSOSiteCredentials>();

    DefaultSSOSiteCredentials siteCreds = new DefaultSSOSiteCredentials("http://www.localhost.com",
            "www.localhost.com");
    siteCreds.setUsername("admin");
    siteCreds.setPassword("admin");
    ssoSiteCredsOfSubject.add(siteCreds);

    siteCreds = new DefaultSSOSiteCredentials("http://www.localhost.com/basicauth", "www.localhost.com");
    siteCreds.setUsername("basic");
    siteCreds.setPassword("basic");
    ssoSiteCredsOfSubject.add(siteCreds);

    siteCreds = new DefaultSSOSiteCredentials("http://www.localhost.com/formauth", "www.localhost.com");
    siteCreds.setFormAuthentication(true);
    siteCreds.setFormUserField("user");
    siteCreds.setFormPwdField("pass");
    siteCreds.setUsername("form");
    siteCreds.setPassword("form");
    ssoSiteCredsOfSubject.add(siteCreds);

    session.setAttribute(SSOReverseProxyIFramePortlet.SUBJECT_SSO_SITE_CREDS, ssoSiteCredsOfSubject);
}