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:org.openmrs.web.controller.concept.ConceptStopWordFormControllerTest.java

/**
 * @see {@link ConceptStopWordFormController#handleSubmission(HttpSession, ConceptStopWordFormBackingObject, org.springframework.validation.BindingResult)
 *///from  w w w .ja v  a 2s  .c  o m
@Test
@Verifies(value = "should add new ConceptStopWord", method = "handleSubmission(HttpSession, ConceptStopWordFormBackingObject, BindingResult)")
public void handleSubmission_shouldAddNewConceptStopWord() throws Exception {
    ConceptStopWordFormController controller = (ConceptStopWordFormController) applicationContext
            .getBean("conceptStopWordFormController");

    HttpSession mockSession = new MockHttpSession();

    mockSession.setAttribute("value", "As");
    BindException errors = new BindException(new ConceptStopWord("As", Locale.ENGLISH), "value");

    controller.handleSubmission(mockSession, new ConceptStopWord("As", Locale.ENGLISH), errors);

    Assert.assertEquals("ConceptStopWord.saved", mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    Assert.assertNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR));
}

From source file:org.javalite.activeweb.SpecHelper.java

@Before
public void atStart() {
    sessionFacade = new SessionTestFacade(new MockHttpSession());
    setTemplateLocation("src/main/webapp/WEB-INF/views");//default location of all views

    Context.setTLs(null, new MockHttpServletResponse(), new MockFilterConfig(),
            new ControllerRegistry(new MockFilterConfig()), new AppContext(), new RequestContext(), null);
}

From source file:org.terasoluna.gfw.web.logging.HttpSessionEventLoggingListenerTest.java

@Before
public void setup() throws Exception {
    mockHttpSession = new MockHttpSession();
    httpSessionEvent = new HttpSessionEvent(mockHttpSession);
    sessionBindingEvent = new HttpSessionBindingEvent(mockHttpSession, "terasoluna", "AA");

    listener = new HttpSessionEventLoggingListener();

    @SuppressWarnings("unchecked")
    Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    this.mockAppender = mockAppender;
    Logger logger = (Logger) LoggerFactory.getLogger(HttpSessionEventLoggingListener.class);
    logger.addAppender(mockAppender);/*from  w  w w .jav a 2s.  c  o  m*/

}

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    request = new MockHttpServletRequest();
    request.setServerName("www.neuromice.org");
    request.setContextPath("/");

    session = new MockHttpSession();
}

From source file:org.openmrs.module.sync.web.controller.ConfigCurrentServerFormControllerTest.java

@Test
public void shouldSaveCurrentServerSettings() throws Exception {
    SyncService syncService = Context.getService(SyncService.class);
    AdministrationService as = Context.getAdministrationService();

    // sanity check
    Assert.assertNotSame("new server name", syncService.getServerName());
    Assert.assertNull(syncService.getServerUuid());
    Assert.assertNull(syncService.getAdminEmail());

    ConfigCurrentServerFormController controller = new ConfigCurrentServerFormController();

    controller.onSaveSettings("new server name", "some uuid", "the server email address", 97, 98, 99, 100,
            new MockHttpSession());

    Assert.assertNotNull(syncService.getServerName());
    Assert.assertNotNull(syncService.getServerUuid());
    Assert.assertNotNull(syncService.getAdminEmail());
    Assert.assertEquals("97", as.getGlobalProperty(SyncConstants.PROPERTY_NAME_MAX_PAGE_RECORDS));
    Assert.assertEquals("98", as.getGlobalProperty(SyncConstants.PROPERTY_NAME_MAX_RECORDS_WEB));
    Assert.assertEquals("99", as.getGlobalProperty(SyncConstants.PROPERTY_NAME_MAX_RECORDS_FILE));
    Assert.assertEquals("100", as.getGlobalProperty(SyncConstants.PROPERTY_NAME_MAX_RETRY_COUNT));
}

From source file:se.kth.csc.config.WebSecurityConfigurationAware.java

public MockHttpSession signInAs(final String principalName, final String... roles) {
    MockHttpSession session = new MockHttpSession();

    final List<GrantedAuthority> authorities = Lists.newArrayList();

    for (String role : roles) {
        authorities.add(new SimpleGrantedAuthority(role));
    }//from   ww w.  j  a  v  a  2s  .co  m

    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
            new MockSecurityContext(new AbstractAuthenticationToken(authorities) {
                @Override
                public Object getCredentials() {
                    return null;
                }

                @Override
                public Object getPrincipal() {
                    return principalName;
                }
            }));

    return session;
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}

From source file:org.araneaframework.tests.framework.filter.StandardSerializingAuditFilterServiceTests.java

public void setUp() throws Exception {
    service = new StandardSerializingAuditFilterService();
    child = new MockEventfulBaseService();
    service.setChildService(child);//w w w.ja v  a 2s .co m

    httpSession = new MockHttpSession();

    Map map = new HashMap();
    map.put(HttpSession.class, httpSession);

    MockLifeCycle.begin(service, new StandardEnvironment(null, map));

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);
}

From source file:com.sse.abtester.VariantSelectionFilterTest.java

/**
 * Reinit.//from   w  w  w .  j a v a  2s  . co  m
 */
@Before
public void reinit() {
    // make a Mockito mock of the FC so we can verify it gets called
    fc = mock(FilterChain.class);
    mockReq = new MockHttpServletRequest();
    mockReq.setSession(new MockHttpSession());
    mockRes = new MockHttpServletResponse();

    VM = mock(VariantManager.class);
    vsf = new VariantSelectionFilter();
    try {
        vsf.init(new MockFilterConfig());
    } catch (ServletException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    vsf.setVariantManager(VM);
    vsf.setVSKEY(VSKEY);
}

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

/**
 * Setup each test/*w  w  w .  jav  a 2 s.  c  o m*/
 */
@Before
public void setup() throws Exception {
    executeDataSet("dataset/test-concepts.xml");

    commonMetadata.install();
    hivMetadata.install();

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

    // Create a session for dummy form with patient #6
    FormEntrySession formSession1 = new FormEntrySession(TestUtils.getPatient(6), formXml, httpSession);
    functionsForSession1 = new EmrVelocityFunctions(formSession1);

    // Create a session for dummy form with patient #7
    FormEntrySession formSession2 = new FormEntrySession(TestUtils.getPatient(7), formXml, httpSession);
    functionsForSession2 = new EmrVelocityFunctions(formSession2);
}