List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
From source file:cc.redpen.server.api.RedPenResourceTest.java
public void testRunWithErrors() throws Exception { MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD); request.setContent(("document=foobar.foobar").getBytes()); //NOTE: need space between periods. MockHttpServletResponse response = invoke(request); assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); System.out.println(response.getContentAsString()); JSONArray errors = (JSONArray) new JSONObject(response.getContentAsString()).get("errors"); // the following will change whenever the configuration or validator functionaliy changes // but it doesn't indicate what particular errors are new/missing // assertEquals(3, errors.length()); assertTrue(errors.get(0).toString().length() > 0); }
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. ja va2 s . co m*/ @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:fi.okm.mpass.shibboleth.profile.impl.BuildMetaRestResponseTest.java
/** * Runs action successfully.//from w w w. ja va 2s . c om * @throws UnsupportedEncodingException * @throws ComponentInitializationException */ @Test public void testWithSource() throws UnsupportedEncodingException, ComponentInitializationException { final MetaDTO metaDTO = new MetaDTO(); metaDTO.setId(id); metaDTO.setName(name); action.setMetaDTO(metaDTO); action.initialize(); ActionTestingSupport.assertProceedEvent(action.execute((RequestContext) null)); final MockHttpServletResponse httpResponse = (MockHttpServletResponse) action.getHttpServletResponse(); Assert.assertNotNull(httpResponse.getContentAsString()); Assert.assertEquals(httpResponse.getStatus(), HttpStatus.SC_OK); final Gson gson = new Gson(); final MetaDTO resultDTO = gson.fromJson(httpResponse.getContentAsString(), MetaDTO.class); Assert.assertEquals(resultDTO.getId(), metaDTO.getId()); Assert.assertEquals(resultDTO.getSamlEntityId(), metaDTO.getSamlEntityId()); Assert.assertEquals(resultDTO.getContactEmail(), metaDTO.getContactEmail()); Assert.assertEquals(resultDTO.getCountryCode(), metaDTO.getCountryCode()); Assert.assertEquals(resultDTO.getName(), metaDTO.getName()); Assert.assertEquals(resultDTO.getSamlMetadataUrl(), metaDTO.getSamlMetadataUrl()); Assert.assertEquals(resultDTO.getServiceDescription(), metaDTO.getServiceDescription()); Assert.assertEquals(resultDTO.getOrganization(), metaDTO.getOrganization()); }
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) *//* w ww . j a va 2 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")); }
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 w w .jav a2 s . c o m*/ @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 ww . ja va 2s. c o 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.casereport.rest.v1_0.controller.CaseReportControllerTest.java
@Test public void shouldFetchTheSavedDocumentOfAGivenCaseReport() throws Exception { final String uuid = "5e7d57f0-9077-11e1-aaa4-00248140a5ec"; CaseReport cr = service.getCaseReportByUuid(uuid); String contents = IOUtils//ww w . j av a 2 s .c om .toString(OpenmrsClassLoader.getInstance().getResourceAsStream("submitted-doc.xml")); File file = DocumentUtil.getSubmittedCaseReportFile(cr); FileUtils.writeStringToFile(file, contents, DocumentConstants.ENCODING); MockHttpServletResponse resp = handle(newGetRequest(getURI() + "/" + uuid + "/document")); assertTrue(StringUtils.isNotBlank(resp.getContentAsString())); assertTrue(resp.getContentAsString().indexOf("<ClinicalDocument/>") > -1); }
From source file:com.thoughtworks.go.server.view.velocity.TestVelocityView.java
public String render() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); try {/*from www . j a v a 2 s .co m*/ setExposeSpringMacroHelpers(false); renderMergedOutputModel(modelData, request, response); return response.getContentAsString(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:cc.redpen.server.api.RedPenResourceTest.java
public void testJSValidatorDoesntRunFromNonHomeDir() throws Exception { System.setProperty("REDPEN_HOME", "."); MockHttpServletRequest request = constructMockRequest("POST", "/document/validate/json", WILDCARD, APPLICATION_JSON);//from w w w .j av a 2 s. c om request.setContent(String.format( "{\"document\":\"Test, this is a test.\",\"format\":\"json2\",\"documentParser\":\"PLAIN\",\"config\":{\"lang\":\"en\",\"validators\":{\"JavaScript\":{\"properties\":{\"script-path\":\"%s\"}}}}}", "resources/js").getBytes()); MockHttpServletResponse response = invoke(request); assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); JSONArray errors = new JSONObject(response.getContentAsString()).getJSONArray("errors"); assertEquals(0, errors.length()); }