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(@Nullable ServletContext servletContext, @Nullable String id) 

Source Link

Document

Create a new MockHttpSession.

Usage

From source file:org.springframework.security.web.jackson2.WebAuthenticationDetailsMixinTest.java

@Test
public void buildWebAuthenticationDetailsUsingDifferentConstructors() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("localhost");
    request.setSession(new MockHttpSession(null, "1"));

    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    String jsonString = "{\"@class\": \"org.springframework.security.web.authentication.WebAuthenticationDetails\","
            + "\"sessionId\": \"1\", \"remoteAddress\": \"/localhost\"}";
    WebAuthenticationDetails authenticationDetails = this.mapper.readValue(jsonString,
            WebAuthenticationDetails.class);
    assertThat(details.equals(authenticationDetails));
}

From source file:org.springframework.security.web.jackson2.WebAuthenticationDetailsMixinTest.java

@Test
public void webAuthenticationDetailsSerializeTest() throws JsonProcessingException, JSONException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("/home");
    request.setSession(new MockHttpSession(null, "1"));
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    String expectedJson = "{\"@class\": \"org.springframework.security.web.authentication.WebAuthenticationDetails\","
            + "\"sessionId\": \"1\", \"remoteAddress\": \"/home\"}";
    String actualJson = this.mapper.writeValueAsString(details);
    JSONAssert.assertEquals(expectedJson, actualJson, true);
}

From source file:org.carewebframework.ui.test.MockEnvironment.java

/**
 * Initializes the mock environment.//from   w w w . j  av  a2s. c  om
 * 
 * @param configLocations Additional config file locations.
 * @throws Exception Unspecified exception.
 */
public void init(String... configLocations) throws Exception {
    // Set up web app
    servletContext = init(new MockServletContext());
    configuration = init(new Configuration());
    webApp = init(new SimpleWebApp());
    // Create root Spring context
    rootContext = init(new FrameworkAppContext(null, true), configLocations);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    rootContext.refresh();
    // Create mock session
    request = init(new MockHttpServletRequest(servletContext));
    response = init(new MockHttpServletResponse());
    session = SessionsCtrl.newSession(webApp, init(new MockHttpSession(servletContext, "mock")), request);
    SessionsCtrl.setCurrent(session);
    // Create the page
    PageImpl page = init(new PageImpl(LanguageDefinition.lookup(null), null, null, null));
    // Create the mock execution
    execution = init(new MockExecution(servletContext, request, response, null, page));
    // Create desktop
    ExecutionsCtrl.setCurrent(execution);
    desktop = init(new DesktopImpl(webApp, "mock", null, null, request));
    ExecutionsCtrl.setCurrent(null);
    // Initialize the environment
    webApp.getUiEngine().activate(execution);
    serverPush = init(new MockServerPush());
    desktop.enableServerPush(serverPush);
    page.preInit();
    page.init(init(new MockPageConfig()));
    inEventListener(true);
    // Create the desktop Spring context
    desktopContext = init(new FrameworkAppContext(desktop, true), configLocations);
    desktopContext.refresh();
}

From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainer.java

public MockHttpSession newSession() {
    MockHttpSession session = new MockHttpSession(m_context,
            String.valueOf(m_sessionIdProvider.getAndIncrement()));
    m_session = session;//from   w  ww  . j a  va  2 s  . com
    return session;
}

From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainer.java

public MockHttpSession newSession(String sessionId) {
    MockHttpSession session = new MockHttpSession(m_context, sessionId);
    m_session = session;
    return session;
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.SessionController1_8Test.java

@Before
public void before() {
    controller = new SessionController1_8();
    MockHttpServletRequest hsr = new MockHttpServletRequest();
    hsr.setSession(new MockHttpSession(new MockServletContext(), SESSION_ID));
    request = new ServletWebRequest(hsr);

    Context.getAdministrationService().saveGlobalProperty(
            new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, sp, fr"));
}