List of usage examples for org.springframework.mock.web MockHttpServletRequest setContent
public void setContent(@Nullable byte[] content)
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ConceptDatatypeController1_8Test.java
@Test(expected = ResourceDoesNotSupportOperationException.class) public void shouldNotSupportEditingAConceptDatatype() throws Exception { SimpleObject conceptDataType = new SimpleObject(); conceptDataType.add("name", "updated name"); String json = new ObjectMapper().writeValueAsString(conceptDataType); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/* w w w . j a v a 2 s . com*/ }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationTagController1_8Test.java
@Test public void shouldUpdateLocationTag() throws Exception { final String editedName = "Location Tag edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);// w w w.ja v a 2 s . c om LocationTag editedLocationTag = service.getLocationTagByUuid(getUuid()); Assert.assertNotNull(editedLocationTag); Assert.assertEquals(editedName, editedLocationTag.getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.CohortMemberController1_8Test.java
@Test public void addCohortMember_shouldAddCohortMember() throws Exception { String patientId = "da7f524f-27ce-4bb2-86d6-6d1d05312bd5"; SimpleObject attributes = new SimpleObject(); attributes.add("patient", patientId); String json = new ObjectMapper().writeValueAsString(attributes); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid() + "/member"); req.setContent(json.getBytes()); handle(req);//from w ww . j a v a 2s . co m Cohort cohort = service.getCohortByUuid(getUuid()); Patient patient = patientService.getPatientByUuid(patientId); Assert.assertTrue(cohort.contains(patient)); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ConceptSourceController1_8Test.java
@Test public void shouldCreateAConceptSource() throws Exception { long originalCount = getAllCount(); SimpleObject conceptSource = new SimpleObject(); conceptSource.add("name", "test name"); conceptSource.add("description", "test description"); String json = new ObjectMapper().writeValueAsString(conceptSource); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newConceptSource = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newConceptSource, "uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SystemSettingController1_9Test.java
@Test public void shouldSaveSystemSettingWithCustomDatatype() throws Exception { SimpleObject property = new SimpleObject(); property.add("property", "a.property.test"); property.add("description", "Testing post operation of global property"); property.add("datatypeClassname", "org.openmrs.customdatatype.datatype.BooleanDatatype"); property.add("value", "true"); String json = new ObjectMapper().writeValueAsString(property); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newlyCreatedSetting = deserialize(handle(req)); String uuid = (String) PropertyUtils.getProperty(newlyCreatedSetting, "uuid"); MockHttpServletRequest getReq = request(RequestMethod.GET, getURI() + "/" + uuid); getReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(getReq)); assertEquals("a.property.test", PropertyUtils.getProperty(result, "property")); assertEquals("Testing post operation of global property", PropertyUtils.getProperty(newlyCreatedSetting, "description")); assertEquals("true", PropertyUtils.getProperty(result, "value")); assertEquals("org.openmrs.customdatatype.datatype.BooleanDatatype", PropertyUtils.getProperty(result, "datatypeClassname")); assertNull(PropertyUtils.getProperty(result, "datatypeConfig")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.ConceptMapTypeController1_9Test.java
@Test public void shouldEditingAConceptMapType() throws Exception { final String newName = "updated name"; SimpleObject conceptMapTypeType = new SimpleObject(); conceptMapTypeType.add("name", newName); String json = new ObjectMapper().writeValueAsString(conceptMapTypeType); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/*from www. ja v a 2 s . c o m*/ assertEquals(newName, service.getConceptMapTypeByUuid(getUuid()).getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_12.OrderSetController1_12Test.java
@Test public void shouldEditAnOrderSet() throws Exception { final String editedName = "OrderSet Edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);// w w w . ja v a 2s . com OrderSet editedOrderSet = orderSetService.getOrderSetByUuid(getUuid()); Assert.assertNotNull(editedOrderSet); Assert.assertEquals(editedName, editedOrderSet.getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.DrugController1_8Test.java
@Test public void shouldCreateADrug() throws Exception { long originalCount = getAllCount(); SimpleObject drug = new SimpleObject(); drug.add("name", "Drug name"); drug.add("description", "Drug description"); drug.add("combination", "false"); drug.add("concept", service.getConcept(3).getUuid()); String json = new ObjectMapper().writeValueAsString(drug); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newDrug = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newDrug, "uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParserTest.java
@Test public void testInvalidSignature() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("X-Line-Signature", "SSSSIGNATURE"); request.setContent("{}".getBytes(StandardCharsets.UTF_8)); assertThatThrownBy(() -> lineBotCallbackRequestParser.handle(request)) .isInstanceOf(LineBotCallbackException.class).hasMessage("Invalid API signature"); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.EncounterTypeController1_8Test.java
@Test public void shouldEditingAnEncounterType() throws Exception { final String newName = "updated name"; SimpleObject encounterType = new SimpleObject(); encounterType.add("name", newName); String json = new ObjectMapper().writeValueAsString(encounterType); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/* w ww. j a va2 s . c o m*/ assertEquals(newName, service.getEncounterTypeByUuid(getUuid()).getName()); }