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

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

Introduction

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

Prototype

public void setRequestURI(@Nullable String requestURI) 

Source Link

Usage

From source file:com.google.api.server.spi.discovery.ProxyingDiscoveryServiceTest.java

private static MockHttpServletRequest createRequest(String apiPath) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI(BASE_PATH + apiPath);
    request.setServerName(SERVER_NAME);/*w  ww.  j  a v a  2s  . c om*/
    request.setServerPort(SERVER_PORT);
    return request;
}

From source file:org.apache.wink.test.mock.MockRequestConstructor.java

/**
 * Construct a mock request to be used in tests.
 * //  www . jav a2 s  .  co  m
 * @param method HTTP method
 * @param requestURI request URI
 * @param acceptHeader request Accept header
 * @return new mock request
 */
public static MockHttpServletRequest constructMockRequest(String method, String requestURI,
        String acceptHeader) {
    MockHttpServletRequest mockRequest = new MockHttpServletRequestWrapper() {

        public String getPathTranslated() {
            return null; // prevent Spring to resolve the file on the
                         // filesystem which fails
        }

    };
    mockRequest.setMethod(method);
    mockRequest.setRequestURI(requestURI);
    mockRequest.addHeader("Accept", acceptHeader);
    return mockRequest;
}

From source file:com.trenako.web.infrastructure.ServletRequestPathVariablesPropertyValuesTests.java

@Test
public void shouldFillPropertyValues() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/trenako-web/rs/brand/ACME");

    PropertyValues pvs = new ServletRequestPathVariablesPropertyValues(request);

    assertNotNull(pvs);//from   ww w.  j  av a 2  s.c o m
    assertEquals(1, pvs.getPropertyValues().length);
    assertEquals("ACME", pvs.getPropertyValue("brand").getValue());
}

From source file:org.moserp.infrastructure.gateway.filter.ResponseLinksMapperTest.java

@Before
public void setUp() {
    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setRequestURI("/api/products");
    servletRequest.setServerPort(8080);//  w ww .  jav a2 s .com
    RequestContextHolder.setRequestAttributes(new ServletWebRequest(servletRequest));
}

From source file:com.epam.ta.reportportal.ws.PagedResourcesAssemblerTest.java

private void prepareRequestContext(int currentPage, int currentPageSize) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI(REQUEST_URI);
    request.setParameter(CURRENT_PAGE_PARAMETER, String.valueOf(currentPage));
    request.setParameter(PAGE_SIZE_PARAMETER, String.valueOf(currentPageSize));

    request.setQueryString(String.format(QUERY_STRING_PATTERN, currentPage, currentPageSize));
    ServletRequestAttributes attributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(attributes);
}

From source file:com.github.jrialland.ajpclient.servlet.TestWrongHost.java

/**
 * tries to make a request to an unknown host, verifies that the request
 * fails (the library does not hangs) and that we have a 502 error
 * //from ww  w . ja  va 2  s  .c  om
 * @throws Exception
 */
@Test
public void testWrongTargetHost() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/dizzy.mp4");
    final MockHttpServletResponse response = new MockHttpServletResponse();

    final Future<Integer> statusFuture = Executors.newSingleThreadExecutor().submit(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            AjpServletProxy.forHost("unknownhost.inexistentdomain.com", 8415).forward(request, response);
            return response.getStatus();
        }
    });

    final long start = System.currentTimeMillis();

    // should finish in less that seconds
    final int status = statusFuture.get(10, TimeUnit.SECONDS);

    Assert.assertTrue(System.currentTimeMillis() - start < 8000);

    Assert.assertEquals(HttpServletResponse.SC_BAD_GATEWAY, status);
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java

public void testNoSuchFlowExecutionException() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    ModelAndView model = (this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = 1443616250214416520L;

                public String toString() {
                    return "test";
                }/*from w  w w .j a va2s . c o  m*/

                @Override
                public boolean equals(Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException())));

    assertEquals(request.getRequestURI(), ((RedirectView) model.getView()).getUrl());
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java

public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = (this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = -4750073902540974152L;

                public String toString() {
                    return "test";
                }/*from  w w  w .  ja  v  a 2  s .  c  o  m*/

                @Override
                public boolean equals(Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException())));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(),
            ((RedirectView) model.getView()).getUrl());
}

From source file:org.mifos.ui.loan.controller.AppInfoControllerTest.java

@SuppressWarnings("PMD.SignatureDeclareThrowsException") // Exception is thrown by AppInfoController.handleRequest
public void testHandleRequestView() throws Exception {
    applicationInformationDto = new ApplicationInformationDto();
    String expectedSvnRevision = "123456";
    applicationInformationDto.setSvnRevision(expectedSvnRevision);
    String expectedBuildId = "fooId";
    applicationInformationDto.setBuildId(expectedBuildId);
    String expectedBuildTag = "bar-baz-tag-1";
    applicationInformationDto.setBuildTag(expectedBuildTag);
    AppInfoController controller = new AppInfoController();
    controller.setAppInfo(applicationInformationDto);
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setMethod("GET");
    mockRequest.setRequestURI("/appInfo.ftl");
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse);

    Assert.assertNotNull(modelAndView.getModel());
    Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model");
    Assert.assertNotNull(modelMap);// w  w  w.ja v  a2s  . co m
    ApplicationInformationDto actualApplicationInformationDto = (ApplicationInformationDto) modelMap
            .get("appInfo");
    Assert.assertNotNull(actualApplicationInformationDto);
    Assert.assertEquals(actualApplicationInformationDto.getSvnRevision(), expectedSvnRevision);
    Assert.assertEquals(actualApplicationInformationDto.getBuildId(), expectedBuildId);
    Assert.assertEquals(actualApplicationInformationDto.getBuildTag(), expectedBuildTag);
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientIndexControllerTest.java

/**
 * @verifies return empty list when no index found for the patient
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientIndexController#searchIndex(String, String, Integer, javax.servlet.http.HttpServletResponse)
 *//*  ww w  .ja v  a  2  s . c om*/
@Test
public void searchIndex_shouldReturnEmptyListWhenNoIndexFoundForThePatient() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/index");
    request.setParameter("patientId", String.valueOf(8));
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
}