List of usage examples for org.springframework.mock.web MockHttpServletRequest setMethod
public void setMethod(@Nullable String method)
From source file:org.apache.wink.test.mock.MockRequestConstructor.java
/** * Construct a mock request to be used in tests. * //from w w w.ja v a2s . c o 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:cherry.foundation.springmvc.CsrfRequestMatcherTest.java
private MockHttpServletRequest createRequest(String method, String pathInfo) { MockHttpServletRequest r = new MockHttpServletRequest(); r.setMethod(method); r.setPathInfo(pathInfo);/*from w w w .j av a 2s .c om*/ return r; }
From source file:com.carlos.projects.billing.ui.controllers.NewDocumentControllerTest.java
@Test public void shouldForwardToNewDocumentPage() throws Exception { //given/*from ww w . j ava 2 s .com*/ NewDocumentController controller = new NewDocumentController(); controller.setViewName("newDocument"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); MockHttpServletResponse response = new MockHttpServletResponse(); //when ModelAndView modelAndView = controller.handleRequest(request, response); //then assertThat(modelAndView.getViewName(), is("newDocument")); }
From source file:com.carlos.projects.billing.ui.controllers.ShowComponentsControllerTest.java
@Test public void shouldForwardToNewDocumentPage() throws Exception { //given//from ww w .j ava 2s . c o m ShowComponentsController controller = new ShowComponentsController(); controller.setViewName("showComponents"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); MockHttpServletResponse response = new MockHttpServletResponse(); //when ModelAndView modelAndView = controller.handleRequest(request, response); //then assertThat(modelAndView.getViewName(), is("showComponents")); }
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 w w w .ja v a2 s.co m*/ * @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.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);//from w ww.j a v a 2s . c o 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) *///from w w w . j a v a 2 s . com @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())); }
From source file:org.openmrs.module.clinicalsummary.web.service.PatientSummaryControllerTest.java
/** * @verifies return summary data for patient and summary * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSummaryController#searchSummary(String, String, String, Integer, javax.servlet.http.HttpServletResponse) *//*from w ww . j ava2 s. c om*/ @Test public void searchSummary_shouldReturnSummaryDataForPatientAndSummary() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setRequestURI("/module/clinicalsummary/service/patient/summary"); request.setParameter("username", "admin"); request.setParameter("password", "test"); request.setParameter("patientId", "7"); request.setParameter("summaryId", "3"); MockHttpServletResponse response = new MockHttpServletResponse(); HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter(); handlerAdapter.handle(request, response, controller); Assert.assertFalse(StringUtils.isNotEmpty(response.getContentAsString())); }
From source file:org.openmrs.module.clinicalsummary.web.service.PatientSummaryControllerTest.java
/** * @verifies return empty data when no index found for the patient and summary * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSummaryController#searchSummary(String, String, String, Integer, javax.servlet.http.HttpServletResponse) */// w w w . j av a 2s .co m @Test public void searchSummary_shouldReturnEmptyDataWhenNoIndexFoundForThePatientAndSummary() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setRequestURI("/module/clinicalsummary/service/patient/summary"); request.setParameter("username", "admin"); request.setParameter("password", "test"); request.setParameter("patientId", "7"); request.setParameter("summaryId", "4"); MockHttpServletResponse response = new MockHttpServletResponse(); HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter(); handlerAdapter.handle(request, response, controller); Assert.assertFalse(StringUtils.isNotEmpty(response.getContentAsString())); }
From source file:org.openmrs.module.clinicalsummary.web.service.PatientIndexControllerTest.java
/** * @verifies return indexes for the patient * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientIndexController#searchIndex(String, String, Integer, javax.servlet.http.HttpServletResponse) *//*from w ww.j a v a2 s .c o m*/ @Test public void searchIndex_shouldReturnIndexesForThePatient() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setRequestURI("/module/clinicalsummary/service/patient/index"); request.setParameter("username", "admin"); request.setParameter("password", "test"); request.setParameter("patientId", String.valueOf(7)); MockHttpServletResponse response = new MockHttpServletResponse(); HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter(); handlerAdapter.handle(request, response, controller); Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString())); Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony")); Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4")); }