List of usage examples for org.springframework.mock.web MockHttpServletRequest setContent
public void setContent(@Nullable byte[] content)
From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParserTest.java
@Test public void testNullRequest() throws Exception { final byte[] requestBody = "null".getBytes(StandardCharsets.UTF_8); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("X-Line-Signature", "SSSSIGNATURE"); request.setContent(requestBody); doReturn(true).when(lineSignatureValidator).validateSignature(requestBody, "SSSSIGNATURE"); assertThatThrownBy(() -> lineBotCallbackRequestParser.handle(request)) .isInstanceOf(LineBotCallbackException.class).hasMessage("Invalid content"); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ProblemController1_8Test.java
@Test public void shouldAddANewProblemToAPatient() throws Exception { long originalCount = getAllCount(); SimpleObject problem = new SimpleObject(); problem.add("problem", RestTestConstants1_8.CONCEPT_UUID); problem.add("person", getPatientUuid()); problem.add("startDate", "2013-01-01"); String json = new ObjectMapper().writeValueAsString(problem); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes());/*from w w w . j a va 2 s . co m*/ SimpleObject newPatientIdentifierType = deserialize(handle(req)); assertNotNull(PropertyUtils.getProperty(newPatientIdentifierType, "uuid")); assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ConceptSourceController1_8Test.java
@Test public void shouldEditAConceptSource() throws Exception { final String newName = "updated name"; SimpleObject conceptSource = new SimpleObject(); conceptSource.add("name", newName); String json = new ObjectMapper().writeValueAsString(conceptSource); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/*from w ww . ja va2 s . c o m*/ Assert.assertEquals(newName, service.getConceptSourceByUuid(getUuid()).getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.DrugController1_8Test.java
@Test public void shouldEditADrug() throws Exception { final String editedName = "Aspirin Edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);//from w w w.j a v a2s. c o m Drug editedDrug = service.getDrugByUuid(getUuid()); Assert.assertNotNull(editedDrug); Assert.assertEquals(editedName, editedDrug.getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ProgramController1_8Test.java
@Test public void shouldCreateAProgram() throws Exception { long originalCount = getAllCount(); SimpleObject program = new SimpleObject(); program.add("name", "Program name"); program.add("description", "Program description"); program.add("concept", RestTestConstants1_8.CONCEPT_UUID); String json = new ObjectMapper().writeValueAsString(program); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newProgram = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newProgram, "uuid")); Assert.assertEquals(RestTestConstants1_8.CONCEPT_UUID, ((Map) PropertyUtils.getProperty(newProgram, "concept")).get("uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.ConceptReferenceTermController1_9Test.java
@Test public void shouldCreateAConceptReferenceTerm() throws Exception { long originalCount = getAllCount(); SimpleObject conceptReferenceTermType = new SimpleObject(); conceptReferenceTermType.add("code", "test code"); conceptReferenceTermType.add("conceptSource", "00001827-639f-4cb4-961f-1e025bf80000"); String json = new ObjectMapper().writeValueAsString(conceptReferenceTermType); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newConceptReferenceTerm = deserialize(handle(req)); assertNotNull(PropertyUtils.getProperty(newConceptReferenceTerm, "uuid")); assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.PatientIdentifierController1_9Test.java
@Test public void shouldAddANewIdentifierToAPatient() throws Exception { long originalCount = getAllCount(); SimpleObject patientIdentifier = new SimpleObject(); patientIdentifier.add("identifier", "abc123ez"); patientIdentifier.add("identifierType", "2f470aa8-1d73-43b7-81b5-01f0c0dfa53c"); patientIdentifier.add("location", RestTestConstants1_8.LOCATION_UUID); String json = new ObjectMapper().writeValueAsString(patientIdentifier); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes());//from w w w . j a v a 2s . c o m SimpleObject newPatientIdentifier = deserialize(handle(req)); assertNotNull(PropertyUtils.getProperty(newPatientIdentifier, "uuid")); assertEquals(originalCount + 1, getAllCount()); }
From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParserTest.java
@Test public void testCallRequest() throws Exception { InputStream resource = getClass().getClassLoader().getResourceAsStream("callback-request.json"); byte[] requestBody = ByteStreams.toByteArray(resource); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("X-Line-Signature", "SSSSIGNATURE"); request.setContent(requestBody); doReturn(true).when(lineSignatureValidator).validateSignature(requestBody, "SSSSIGNATURE"); CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request); assertThat(callbackRequest).isNotNull(); final List<Event> result = callbackRequest.getEvents(); final MessageEvent messageEvent = (MessageEvent) result.get(0); final TextMessageContent text = (TextMessageContent) messageEvent.getMessage(); assertThat(text.getText()).isEqualTo("Hello, world"); final String followedUserId = messageEvent.getSource().getUserId(); assertThat(followedUserId).isEqualTo("u206d25c2ea6bd87c17655609a1c37cb8"); assertThat(messageEvent.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z")); }
From source file:cc.redpen.server.api.RedPenResourceTest.java
public void testRunWithoutContent() throws Exception { MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD); request.setContent(("").getBytes()); //NOTE: need space between periods. MockHttpServletResponse response = invoke(request); assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); }
From source file:cc.redpen.server.api.RedPenResourceTest.java
public void testRunWithOnlyFormName() throws Exception { MockHttpServletRequest request = constructMockRequest("POST", "/document/validate", WILDCARD); request.setContent(("document=").getBytes()); //NOTE: need space between periods. MockHttpServletResponse response = invoke(request); assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); }