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.UserController1_8Test.java
/** * @see UserController#updateUser(UserAndPassword1_8,SimpleObject,WebRequest) * @throws Exception /* ww w. ja va 2s. c o m*/ * @verifies change a property on a patient */ @Test public void updateUser_shouldChangeAPropertyOnAUser() throws Exception { User user = service.getUserByUuid(getUuid()); Assert.assertNotNull(user); Assert.assertFalse("5-6".equals(user.getSystemId())); Util.log("Old User SystemId: ", user.getSystemId()); String json = "{\"systemId\":\"5-6\",\"password\":\"Admin@123\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); User editedUser = service.getUserByUuid(getUuid()); Assert.assertNotNull(editedUser); Assert.assertEquals("5-6", editedUser.getSystemId()); Util.log("Edited User SystemId: ", editedUser.getSystemId()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldCreateALocation() throws Exception { long originalCount = getAllCount(); SimpleObject location = new SimpleObject(); location.add("name", "Location name"); location.add("description", "Location description"); String json = new ObjectMapper().writeValueAsString(location); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newLocation = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newLocation, "uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldEditALocation() throws Exception { final String editedName = "Xanadu edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/*from w w w . ja v a2 s . co m*/ Location editedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(editedLocation); Assert.assertEquals(editedName, editedLocation.getName()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationController1_8Test.java
@Test public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location);//from w w w . jav a 2 s. c o m String json = "{ \"childLocations\": [] }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(updatedLocation); Assert.assertTrue(updatedLocation.getChildLocations().isEmpty()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsController1_8Test.java
/** * @verifies create a new obs with numeric concept *//* ww w . j a va 2s. c o m*/ @Test public void createObs_shouldCreateANewObsWithNumericConcept() throws Exception { List<Obs> observationsByPerson = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); int before = observationsByPerson.size(); String json = "{\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\",\"concept\":\"a09ab2c5-878e-4905-b25d-5784167d0216\",\"person\":\"5946f880-b197-400b-9caa-a3c661d23041\",\"obsDatetime\":\"2011-05-18\",\"value\":\"150.0\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); Object newObs = deserialize(handle(req)); List<Obs> observationsByPersonAfterSave = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); Assert.assertEquals(before + 1, observationsByPersonAfterSave.size()); newObs = observationsByPersonAfterSave.get(0); Assert.assertEquals((Double) 150.0, ((Obs) newObs).getValueNumeric()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsController1_8Test.java
/** * @see ObsController#createObs(SimpleObject,WebRequest,HttpServletResponse) * @verifies create a new obs with text concept */// ww w.ja va 2 s . com @Test //@Ignore("RESTWS-238: Define creatable/updatable properties on Obs resource") public void createObs_shouldCreateANewObsWithTextConcept() throws Exception { List<Obs> observationsByPerson = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); int before = observationsByPerson.size(); String json = "{\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\",\"concept\":\"96408258-000b-424e-af1a-403919332938\",\"person\":\"5946f880-b197-400b-9caa-a3c661d23041\",\"obsDatetime\":\"2011-05-18\",\"value\":\"high\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); Object newObs = deserialize(handle(req)); List<Obs> observationsByPersonAfterSave = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); Assert.assertEquals(before + 1, observationsByPersonAfterSave.size()); newObs = observationsByPersonAfterSave.get(0); Assert.assertEquals("high", ((Obs) newObs).getValueText()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsController1_8Test.java
@Test //@Ignore("RESTWS-238: Define creatable/updatable properties on Obs resource") public void createObs_shouldCreateAnObsWhenUnitsAreSpecifiedForAConceptNumeric() throws Exception { String conceptUuid = "c607c80f-1ea9-4da3-bb88-6276ce8868dd"; List<Obs> observationsByPerson = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); int before = observationsByPerson.size(); String json = "{\"location\":\"dc5c1fcc-0459-4201-bf70-0b90535ba362\",\"concept\":\"" + conceptUuid + "\",\"person\":\"5946f880-b197-400b-9caa-a3c661d23041\",\"obsDatetime\":\"2011-05-18\",\"value\":\"90.0 kg\"}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes());//w w w. ja v a 2 s. com Object newObs = deserialize(handle(req)); List<Obs> observationsByPersonAfterSave = Context.getObsService() .getObservationsByPerson((Context.getPatientService().getPatient(7))); Assert.assertEquals(before + 1, observationsByPersonAfterSave.size()); newObs = observationsByPersonAfterSave.get(0); Assert.assertEquals((Double) 90.0, ((Obs) newObs).getValueNumeric()); }
From source file:com.github.jrialland.ajpclient.servlet.TestServletProxy.java
@Test public void testMultiple() throws Exception { final int nTasks = 10; for (int i = 0; i < nTasks; i++) { final MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setRequestURI("/long_request"); request.setMethod("POST"); request.addHeader("Content-Type", "application/x-www-form-urlencoded"); request.setContent("duration=1000".getBytes()); final MockHttpServletResponse response = new MockHttpServletResponse(); AjpServletProxy.forHost("localhost", getPort()).forward(request, response); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); }//ww w . ja v a 2 s. c om }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsController1_8Test.java
/** * @verifies setting observation group members *//*from w w w .j ava 2 s. c o m*/ @Test public void setGroupMembers_shouldSetObservationGroupMembers() throws Exception { executeDataSet("obsWithGroupMembers.xml"); String obsWannaBeParentUuid = "5117f5d4-96cc-11e0-8d6b-9b9415a91439"; // check if obs is a group parent assertTrue(Context.getObsService().getObsByUuid(obsWannaBeParentUuid).getGroupMembers().isEmpty()); String json = "{\"groupMembers\" : [\"5117f5d4-96cc-11e0-8d6b-9b9415a91433\", " + "\"5117f5d4-96cc-11e0-8d6b-9b9415a91436\"]}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + obsWannaBeParentUuid); req.setContent(json.getBytes()); Object response = deserialize(handle(req)); // get uuid for observation's new instance String newObsUuid = PropertyUtils.getProperty(response, "uuid").toString(); assertFalse(Context.getObsService().getObsByUuid(newObsUuid).getGroupMembers().isEmpty()); }
From source file:org.springframework.cloud.aws.messaging.endpoint.BaseNotificationMessageHandlerMethodArgumentResolverTest.java
@Test public void resolveArgument_NotificationMessage_createsObjectWithAllFields() throws Exception { //Arrange// w w w .ja v a2s .c om AbstractNotificationMessageHandlerMethodArgumentResolver resolver = new AbstractNotificationMessageHandlerMethodArgumentResolver() { @Override protected Object doResolveArgumentFromNotificationMessage(JsonNode content, HttpInputMessage request, Class<?> parameterType) { return content; } @Override public boolean supportsParameter(MethodParameter parameter) { return true; } }; MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServletWebRequest servletWebRequest = new ServletWebRequest(servletRequest); byte[] fileContent = FileCopyUtils.copyToByteArray(new ClassPathResource("notificationMessage.json", AbstractNotificationMessageHandlerMethodArgumentResolver.class).getInputStream()); servletRequest.setContent(fileContent); MethodParameter methodParameter = new MethodParameter(ReflectionUtils.findMethod(NotificationMethods.class, "subscriptionMethod", NotificationStatus.class), 0); //Act ObjectNode content = (ObjectNode) resolver.resolveArgument(methodParameter, null, servletWebRequest, null); //Assert assertEquals("Notification", content.get("Type").asText()); assertEquals("f2c15fec-c617-5b08-b54d-13c4099fec60", content.get("MessageId").asText()); assertEquals("arn:aws:sns:eu-west-1:111111111111:mySampleTopic", content.get("TopicArn").asText()); assertEquals("asdasd", content.get("Subject").asText()); assertEquals("asdasd", content.get("Message").asText()); assertEquals("2014-06-28T14:12:24.418Z", content.get("Timestamp").asText()); assertEquals("1", content.get("SignatureVersion").asText()); assertEquals( "XDvKSAnhxECrAmyIrs0Dsfbp/tnKD1IvoOOYTU28FtbUoxr/CgziuW87yZwTuSNNbHJbdD3BEjHS0vKewm0xBeQ0PToDkgtoORXo5RWnmShDQ2nhkthFhZnNulKtmFtRogjBtCwbz8sPnbOCSk21ruyXNdV2RUbdDalndAW002CWEQmYMxFSN6OXUtMueuT610aX+tqeYP4Z6+8WTWLWjAuVyy7rOI6KHYBcVDhKtskvTOPZ4tiVohtQdQbO2Gjuh1vblRzzwMkfaoFTSWImd4pFXxEsv/fq9aGIlqq9xEryJ0w2huFwI5gxyhvGt0RnTd9YvmAEC+WzdJDOqaDNxg==", content.get("Signature").asText()); assertEquals( "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-e372f8ca30337fdb084e8ac449342c77.pem", content.get("SigningCertURL").asText()); assertEquals( "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:721324560415:mySampleTopic:9859a6c9-6083-4690-ab02-d1aead3442df", content.get("UnsubscribeURL").asText()); }