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:com.modelmetrics.common.util.TestCaseWithLog.java

public BeanFactory getTestBeanFactory() {

    ConfigurableApplicationContext context = (ConfigurableApplicationContext) SpringBeanBroker.getBeanFactory();

    context.getBeanFactory().registerScope("session", new SessionScope());

    MockHttpServletRequest request = new MockHttpServletRequest();

    ServletRequestAttributes attributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(attributes);

    return context.getBeanFactory();

}

From source file:org.openmrs.module.webservices.rest.web.RequestContextTest.java

/**
 * @see RequestContext#getParameter(String)
 * @verifies return null if the wanted request parameter is not present in the request
 *//* w ww. ja v a  2  s  .c o m*/
@Test
public void getParameter_shouldReturnNullIfTheWantedRequestParameterIsNotPresentInTheRequest()
        throws Exception {

    RequestContext requestContext = new RequestContext();
    MockHttpServletRequest request = new MockHttpServletRequest();
    requestContext.setRequest(request);

    assertNull(requestContext.getParameter("UNKOWN"));
}

From source file:org.jasig.cas.web.view.Cas10ResponseViewTests.java

public void testSuccessView() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.view.setSuccessResponse(true);
    this.view.render(this.model, new MockHttpServletRequest(), response);
    assertEquals("yes\ntest\n", response.getContentAsString());
}

From source file:org.openmrs.module.feedback.web.SubmitFeedbackControllerTest.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 w w  w .java  2s  . co  m*/
    executeDataSet("SeverityDataset.xml");
    executeDataSet("PredefinedSubjectDataset.xml");

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

From source file:ch.rasc.extclassgenerator.ModelGeneratorBeanWithValidationTest.java

@Test
public void testWriteModelHttpServletRequestHttpServletResponseClassOfQOutputFormatBoolean()
        throws IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class,
            OutputFormat.EXTJS4, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareExtJs4Code("BeanWithValidation", response.getContentAsString(), true, false);

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class,
            OutputFormat.TOUCH2, IncludeValidation.ALL, false);
    GeneratorTestUtil.compareTouch2Code("BeanWithValidation", response.getContentAsString(), false, false);

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class,
            OutputFormat.EXTJS4, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareExtJs4Code("BeanWithValidation", response.getContentAsString(), true, false);

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class,
            OutputFormat.TOUCH2, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareTouch2Code("BeanWithValidation", response.getContentAsString(), true, false);
}

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

@Before
public void before()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    controller = new BaseRestController();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    spyOnLog = spy(LogFactory.getLog(BaseRestController.class));
    // Need to get the logger using reflection
    Field log;/*ww w.jav  a  2  s .  c  o m*/
    log = controller.getClass().getDeclaredField("log");
    log.setAccessible(true);

    log.set(controller, spyOnLog);

}

From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java

/**
 * Test of request: show all customers.//from   w w  w  . ja v a2 s . co  m
 */
@Test
public void testListCustomers() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    ListCustomersController listCustomersController = new ListCustomersController(
            new CustomerRepositoryMockImpl());
    request.setMethod("GET");
    request.setRequestURI("/listcustomers");

    try {
        ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response,
                listCustomersController);

        ModelAndViewAssert.assertViewName(mv, "listcustomers");
        List<Customer> customers = (List<Customer>) mv.getModel().get("customers");

        assertNotNull(customers);
        assertEquals(5, customers.size());
    } catch (Exception ex) {
        fail();
    }
}

From source file:com.amashchenko.struts2.actionflow.ActionFlowAwareTest.java

/** Initializes servlet mock objects but preserves session. */
private void initServletMockObjectsPreserveSession() {
    servletContext = new MockServletContext(resourceLoader);
    response = new MockHttpServletResponse();

    // preserve session
    HttpSession session = null;//w  w w  .j av a 2  s  .com
    if (request != null && request.getSession() != null) {
        session = request.getSession();
    }
    request = new MockHttpServletRequest();
    request.setSession(session);

    pageContext = new MockPageContext(servletContext, request, response);
}

From source file:com.liferay.httpservice.internal.http.DefaultHttpContextTest.java

@Test
public void testHandleSecurity() {
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();

    Assert.assertTrue(_defaultHttpContext.handleSecurity(mockHttpServletRequest, mockHttpServletResponse));
}