List of usage examples for org.springframework.mock.web MockHttpServletRequest setContent
public void setContent(@Nullable byte[] content)
From source file:org.apache.amber.oauth2.ext.dynamicreg.server.request.OAuthServerRegistrationRequestTest.java
@Test public void testValidOAuthPushRequest() throws Exception { final String validJson = FileUtils.readTextFileAsString("json/push_valid.json"); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/register"); request.setContentType(OAuth.ContentType.JSON); request.setContent(validJson.getBytes("UTF-8")); final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request); OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper); Assert.assertEquals("Uploading and also editing capabilities!", registrationRequest.getClientDescription()); Assert.assertEquals("http://onlinephotogallery.com/icon.png", registrationRequest.getClientIcon()); Assert.assertEquals("Online Photo Gallery", registrationRequest.getClientName()); Assert.assertEquals("https://onlinephotogallery.com/client_reg", registrationRequest.getRedirectURI()); Assert.assertEquals("push", registrationRequest.getType()); Assert.assertEquals("http://onlinephotogallery.com", registrationRequest.getClientUrl()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.PrivilegeController1_8Test.java
@Test public void shouldEditingAPrivilege() throws Exception { final String newDescription = "updated descr"; SimpleObject privilege = new SimpleObject(); assertEquals(false, newDescription.equals(service.getPrivilegeByUuid(getUuid()).getName())); privilege.add("description", newDescription); String json = new ObjectMapper().writeValueAsString(privilege); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);/*from ww w. j av a 2 s .c o m*/ assertEquals(newDescription, service.getPrivilegeByUuid(getUuid()).getDescription()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.LocationTagController1_8Test.java
@Test public void shouldCreateALocationTag() throws Exception { long originalCount = getAllCount(); SimpleObject locationTag = new SimpleObject(); locationTag.add("name", "Location Tag name"); locationTag.add("description", "Location Tag description"); String json = new ObjectMapper().writeValueAsString(locationTag); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newLocationTag = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newLocationTag, "uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.ConceptMapTypeController1_9Test.java
@Test public void shouldCreateAConceptMapType() throws Exception { long originalCount = getAllCount(); SimpleObject conceptMapTypeType = new SimpleObject(); conceptMapTypeType.add("name", "test name"); String json = new ObjectMapper().writeValueAsString(conceptMapTypeType); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newConceptMapType = deserialize(handle(req)); assertNotNull(PropertyUtils.getProperty(newConceptMapType, "uuid")); assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_12.OrderSetController1_12Test.java
@Test public void shouldCreateAnOrderSet() throws Exception { long originalCount = getAllCount(); SimpleObject orderSet = new SimpleObject(); orderSet.add("name", "New OrderSet"); orderSet.add("description", "OrderSet description"); orderSet.add("operator", "ALL"); String json = new ObjectMapper().writeValueAsString(orderSet); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newOrderSet = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newOrderSet, "uuid")); Assert.assertEquals(originalCount + 1, getAllCount()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_12.OrderSetController1_12Test.java
@Test public void shouldCreateAnOrderSetWithSomeOrderSetMembers() throws Exception { long originalCount = getAllCount(); String json = "{\n" + " \"name\": \"A\",\n" + " \"description\": \"OSA\",\n" + " \"operator\": \"ALL\",\n" + " \"orderSetMembers\": [\n" + " {\n" + " \"orderType\": {\n" + " \"uuid\": \"131168f4-15f5-102d-96e4-000c29c2a5d7\"\n" + " },\n" + " \"concept\": {\n" + " \"name\": \"Amoxicillin\",\n" + " \"uuid\": \"b055abd8-a420-4a11-8b98-02ee170a7b54\"\n" + " }\n" + " }\n" + " ]\n" + "}"; MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newOrderSet = deserialize(handle(req)); Assert.assertNotNull(PropertyUtils.getProperty(newOrderSet, "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 shouldSaveSystemSettingWithoutCustomDatatype() throws Exception { SimpleObject property = new SimpleObject(); property.add("property", "a.property.test"); property.add("description", "Testing post operation of global property"); property.add("value", "Saving property value without custome datatype"); String json = new ObjectMapper().writeValueAsString(property); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject result = deserialize(handle(req)); assertEquals("a.property.test", PropertyUtils.getProperty(result, "property")); assertEquals("Testing post operation of global property", PropertyUtils.getProperty(result, "description")); assertEquals("Saving property value without custome datatype", PropertyUtils.getProperty(result, "value")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.EncounterTypeController1_8Test.java
@Test public void shouldCreateAEncounterType() throws Exception { long originalCount = getAllCount(); SimpleObject encounterType = new SimpleObject(); encounterType.add("name", "test name"); encounterType.add("description", "test description"); String json = new ObjectMapper().writeValueAsString(encounterType); MockHttpServletRequest req = request(RequestMethod.POST, getURI()); req.setContent(json.getBytes()); SimpleObject newEncounterType = deserialize(handle(req)); assertNotNull(PropertyUtils.getProperty(newEncounterType, "uuid")); assertEquals(originalCount + 1, getAllCount()); }
From source file:net.jadler.stubbing.server.jetty.RequestUtilsTest.java
@Test public void parametersURLEncoded() throws IOException { final MockHttpServletRequest httpRequest = prepareEmptyRequest(); httpRequest.setQueryString("param1%20name=param1%20value"); httpRequest.setContent("param2%20name=param2%20value".getBytes()); httpRequest.addHeader("content-type", "application/x-www-form-urlencoded"); final Request req = RequestUtils.convert(httpRequest); assertThat(req.getParameters().getKeys(), containsInAnyOrder("param1%20name", "param2%20name")); assertThat(req.getParameters().getValues("param1%20name"), contains("param1%20value")); assertThat(req.getParameters().getValues("param2%20name"), contains("param2%20value")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.PatientIdentifierTypeController1_8Test.java
@Test public void shouldEditingAPatientIdentifierType() throws Exception { final String newName = "updated name"; SimpleObject patientIdentifierType = new SimpleObject(); patientIdentifierType.add("name", newName); String json = new ObjectMapper().writeValueAsString(patientIdentifierType); MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req);//from ww w.j a v a 2s. co m assertEquals(newName, service.getPatientIdentifierTypeByUuid(getUuid()).getName()); }