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(@Nullable String method, @Nullable String requestURI) 

Source Link

Document

Create a new MockHttpServletRequest with a default MockServletContext .

Usage

From source file:ar.com.zauber.commons.web.uri.factory.RelativePathUriFactoryTest.java

/** Test de inicializacion */
@Before//  w w  w  . jav  a  2 s .com
public final void setUp() throws Exception {
    new RelativePathUriFactory(new IdentityUriFactory(), "utf-8",
            new MutableRequestProvider(new MockHttpServletRequest("GET", "/")));
}

From source file:de.otto.jsonhome.controller.DocControllerTest.java

@Test
public void shouldReturnMarkdownAsHtml() throws IOException {
    // given//from ww w.j  a  v  a 2 s .  c  o  m
    final DocController controller = new DocController();
    controller.setRootDir(new ClassPathResource("/test/**"));
    // when
    final String markdown = controller
            .getMarkdownAsHtml(new MockHttpServletRequest("GET", "/test/doc/test.md"));
    // then
    assertTrue(markdown.startsWith("<h1>Test</h1>"));
}

From source file:ar.com.zauber.commons.web.proxy.impl.InmutableURLRequestMapperTest.java

/** @throws Exception on error */
public final void testAny() throws Exception {
    final URL url = new URL("http://127.0.0.1/foo/bar");
    final URLRequestMapper mapper = new InmutableURLRequestMapper(new InmutableURLResult(url));
    final String ctxPath = "/nexusaaa-0.0";
    final String servletContext = "/bin";

    final MockHttpServletRequest request = new MockHttpServletRequest("GET", ctxPath + servletContext + "/");
    request.setContextPath(ctxPath);//from   w w w. j  a v a 2 s. c o m
    request.setServletPath(servletContext);

    assertEquals(url, mapper.getProxiedURLFromRequest(request).getURL());
}

From source file:org.openmrs.web.controller.person.PersonAttributeTypeFormControllerTest.java

@Before
public void setup() throws Exception {
    executeDataSet("org/openmrs/web/controller/include/PersonAttributeTypeFormControllerTest.xml");
    controller = (PersonAttributeTypeFormController) applicationContext.getBean("personAttributeTypeForm");
    controller.setFormView("index.htm");
    controller.setSuccessView("PersonAttributeType.form");

    request = new MockHttpServletRequest("POST",
            "/admin/person/personAttributeType.form?personAttributeTypeId=1");
    request.setSession(new MockHttpSession(null));
    request.setContentType("application/x-www-form-urlencoded");
    request.addParameter("name", "TRUNK");
    request.addParameter("format", "java.lang.String");
    response = new MockHttpServletResponse();
}

From source file:org.openmrs.web.controller.patient.PatientIdentifierTypeFormControllerTest.java

@Before
public void setup() throws Exception {
    executeDataSet("org/openmrs/web/patient/include/PatientIdentifierTypeFormControllerTest.xml");
    controller = (PatientIdentifierTypeFormController) applicationContext.getBean("patientIdentifierTypeForm");
    controller.setFormView("index.htm");
    controller.setSuccessView("patientIdentifierType.form");

    request = new MockHttpServletRequest("POST",
            "/admin/patients/patientIdentifierType.form?patientIdentifierTypeId=1");
    request.setSession(new MockHttpSession(null));
    request.setContentType("application/x-www-form-urlencoded");
    request.addParameter("name", "TRUNK");
    response = new MockHttpServletResponse();
}

From source file:it.geosolutions.httpproxy.service.BaseProxyServiceTest.java

/**
 * Test IProxyService execute as HTTP GET
 *///from   ww w.ja  v a2s  .c  om
public void executeGet() {
    try {
        // Generate mocked request and response
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/proxy/");
        mockRequest.addParameter("url", testUrl);
        MockHttpServletResponse mockResponse = new MockHttpServletResponse();

        // Call proxy execute
        proxy.execute(mockRequest, mockResponse);

        // Assert the response
        assertNotNull(mockResponse);
        assertEquals(mockResponse.getStatus(), HttpStatus.SC_OK);
        assertNotNull(mockResponse.getOutputStream());
        assertNotNull(mockResponse.getContentType());
        assertTrue(mockResponse.getContentType().contains("text/xml"));

        LOGGER.info("Success proxy GET in '" + testUrl + "'");
        LOGGER.info("************************ Response ************************");
        LOGGER.info(mockResponse.getContentAsString());
        LOGGER.info("********************** EoF Response **********************");

    } catch (Exception e) {
        fail("Exception executing proxy");
    }
}

From source file:org.openmrs.web.controller.form.FieldFormControllerTest.java

/**
 * @see FieldFormController#formBackingObject(HttpServletRequest)
 *//*from  ww w.j a  va 2  s .co m*/
// @Transactional annotation needed because the parent class is @Transactional and so screws propagates to this readOnly test
@Transactional(readOnly = true)
@Test
@Verifies(value = "should get field", method = "formBackingObject(HttpServletRequest)")
public void formBackingObject_shouldGetField() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    request.setParameter("fieldId", "1");

    HttpServletResponse response = new MockHttpServletResponse();

    FieldFormController controller = (FieldFormController) applicationContext.getBean("fieldForm");

    ModelAndView modelAndView = controller.handleRequest(request, response);

    // make sure there is a "userId" filled in on the concept
    Field command = (Field) modelAndView.getModel().get("field");
    Assert.assertNotNull(command.getFieldId());
}

From source file:org.tonguetied.web.RequestUtilsTest.java

/**
 * Test method for {@link org.tonguetied.web.RequestUtils#isGetMethod(javax.servlet.http.HttpServletRequest)}.
 *//*from ww w.j a va2 s.c om*/
@Test
public final void testIsGetMethodUpperCase() {
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
    assertTrue(RequestUtils.isGetMethod(request));
}

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

@Test
public void verifyWrongMethod() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + "wrongmethod");

    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);

    assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus());
    assertEquals("text/plain", mockResponse.getContentType());
    assertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}