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

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

Introduction

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

Prototype

public MockHttpServletRequest() 

Source Link

Document

Create a new MockHttpServletRequest with a default MockServletContext .

Usage

From source file:org.araneaframework.tests.StandardServletInputDataTests.java

public void testWrongPathGetScopedData() {
    request = new MockHttpServletRequest();
    request.setAttribute("a", "b");
    request.setAttribute("a.b", "b");
    request.setAttribute("a.b.c", "b");

    input = new StandardServletInputData(request);
    input.pushScope("a");
    input.pushScope("b");
    input.pushScope("c");
    input.pushScope("d");
    assertEquals(null, input.getScopedData().get("c"));
}

From source file:fragment.web.SystemHealthControllerTest.java

@Before
public void init() throws Exception {
    map = new ModelMap();
    calendar = Calendar.getInstance();
    defaultServiceInstance = serviceInstanceDao.find(1L);
    request = new MockHttpServletRequest();

}

From source file:org.openmrs.module.feedback.web.AddStatusFormControllerTest.java

@Before
public void setUp() throws Exception {

    /* executed before the test is run */
    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    /* this file is in the same folder of test resources where the hibernate mapping file is located */
    initializeInMemoryDatabase();// w  w  w .ja  v a 2s. com
    executeDataSet("StatusDataset.xml");

    /* Sample data is loaded into the system */
    authenticate();
}

From source file:org.sventon.web.filter.ConfigAuthorizationFilterTest.java

@Test
public void testDoFilterInternalApplicationConfiguredEditDisabled() throws Exception {
    final ConfigAuthorizationFilter filter = new ConfigAuthorizationFilter(application);

    final HttpServletRequest request = new MockHttpServletRequest();
    final HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    final MockFilterChain filterChain = new MockFilterChain();

    application.setConfigured(true);/*  w  w  w  . ja  v  a  2s.co m*/
    application.setEditableConfig(false);

    response.sendRedirect("/repos/list");

    EasyMock.replay(response);
    filter.doFilterInternal(request, response, filterChain);
    EasyMock.verify(response);

    assertNull(filterChain.getRequest());
    assertNull(filterChain.getResponse());
}

From source file:nl.surfnet.coin.selfservice.control.BaseControllerTest.java

@Test
public void testSelectedIdP() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();

    InstitutionIdentityProvider idp1 = new InstitutionIdentityProvider();
    idp1.setId("idpId_1");
    InstitutionIdentityProvider idp2 = new InstitutionIdentityProvider();
    idp2.setId("idpId_2");
    when(coinUser.getInstitutionIdps()).thenReturn(Arrays.asList(idp1, idp2));

    final InstitutionIdentityProvider identityProvider = baseController.switchIdp(request, "idpId_2");
    assertEquals(idp2, identityProvider);
}

From source file:org.openmrs.module.feedback.web.AddSeverityFormControllerTest.java

@Before
public void setUp() throws Exception {

    /* executed before the test is run */
    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    /* this file is in the same folder of test resources where the hibernate mapping file is located */
    initializeInMemoryDatabase();//from www. ja v a2  s . co  m
    executeDataSet("SeverityDataset.xml");

    /* Sample data is loaded into the system */
    authenticate();
}

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

@Test
public void integrationTest() throws Exception {
    MockHttpSession httpSession = new MockHttpSession();
    Session session = sessionFactory.getSession(httpSession);
    MockHttpServletResponse response = new MockHttpServletResponse();
    PageRequest req = new PageRequest("uiframework", "home", new MockHttpServletRequest(), response, session);

    String html = pageFactory.handle(req);
    System.out.println("Result = " + html);

    // should not be cached
    assertThat((String) response.getHeader("Cache-Control"), is("no-cache,no-store,must-revalidate"));
}

From source file:io.jmnarloch.spring.boot.hystrix.Demo.java

@Before
public void setUp() throws Exception {

    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
    requestId = UUID.randomUUID().toString();
}

From source file:io.jmnarloch.spring.request.correlation.filter.RequestCorrelationFilterTest.java

@Test
public void shouldInitiateCorrelationId() throws IOException, ServletException {

    // given/* w ww.  j a v  a 2  s. co m*/
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockFilterChain chain = new MockFilterChain();

    // when
    instance.doFilter(request, response, chain);

    // then
    assertNotNull(request.getAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME));
    assertNotNull(((HttpServletRequest) chain.getRequest()).getHeader(RequestCorrelationConsts.HEADER_NAME));
}

From source file:com.gisgraphy.webapp.action.BaseActionTestCase.java

public static void setUpActionContext() {
    ConfigurationManager configurationManager = new ConfigurationManager();
    configurationManager.addContainerProvider(new XWorkConfigurationProvider());
    Configuration config = configurationManager.getConfiguration();
    Container container = config.getContainer();

    ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
    stack.getContext().put(ActionContext.CONTAINER, container);
    ActionContext.setContext(new ActionContext(stack.getContext()));
    ServletActionContext.setRequest(new MockHttpServletRequest());
}