diff --git a/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderTypeController1_10Test.java b/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderTypeController1_10Test.java index 1674aa975..60d5280aa 100644 --- a/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderTypeController1_10Test.java +++ b/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderTypeController1_10Test.java @@ -162,7 +162,7 @@ public void shouldCreateANewOrderType() throws Exception { assertEquals(orderType.get("description"), Util.getByPath(newOrder, "description")); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAnOrderType() throws Exception { final String newName = "Updated name"; SimpleObject conceptMapTypeType = new SimpleObject(); @@ -176,6 +176,18 @@ public void shouldEditAnOrderType() throws Exception { assertEquals(newName, service.getOrderTypeByUuid(getUuid()).getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAnAnOrderType() throws Exception { + final String newName = "updated name"; + SimpleObject orderType = new SimpleObject(); + orderType.add("name", newName); + String json = new ObjectMapper().writeValueAsString(orderType); + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + + } + @Test public void shouldRetireAnOrderType() throws Exception { assertEquals(false, service.getOrderTypeByUuid(getUuid()).isRetired()); diff --git a/omod-1.12/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_12/OrderSetController1_12Test.java b/omod-1.12/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_12/OrderSetController1_12Test.java index 4237da635..7b463a4d5 100644 --- a/omod-1.12/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_12/OrderSetController1_12Test.java +++ b/omod-1.12/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_12/OrderSetController1_12Test.java @@ -9,6 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_12; +import static org.junit.Assert.assertEquals; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -23,7 +25,6 @@ import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import static org.junit.Assert.assertEquals; /** * Tests functionality of OrderSet CRUD by MainResourceController @@ -127,7 +128,7 @@ public void shouldCreateAnOrderSetWithSomeOrderSetMembers() throws Exception { Assert.assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAnOrderSet() throws Exception { final String editedName = "OrderSet Edited"; @@ -141,6 +142,16 @@ public void shouldEditAnOrderSet() throws Exception { Assert.assertNotNull(editedOrderSet); Assert.assertEquals(editedName, editedOrderSet.getName()); } + + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAnAnOrderSet() throws Exception { + + final String editedName = "OrderSet Edited"; + String json = "{ \"name\":\"" + editedName + "\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireAnOrderSet() throws Exception { diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ConceptSourceController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ConceptSourceController1_8Test.java index aa7f1f518..dd6767cb3 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ConceptSourceController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ConceptSourceController1_8Test.java @@ -9,6 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; +import static org.junit.Assert.assertNull; + import java.util.Date; import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; @@ -114,7 +116,7 @@ public void shouldCreateAConceptSource() throws Exception { Assert.assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAConceptSource() throws Exception { final String newName = "updated name"; SimpleObject conceptSource = new SimpleObject(); @@ -128,6 +130,19 @@ public void shouldEditAConceptSource() throws Exception { Assert.assertEquals(newName, service.getConceptSourceByUuid(getUuid()).getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAConceptSource() 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); + } + @Test public void shouldRetireAConceptSource() throws Exception { Assert.assertEquals(false, service.getConceptSourceByUuid(getUuid()).isRetired()); diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/EncounterTypeController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/EncounterTypeController1_8Test.java index 90e96225c..5cb13c576 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/EncounterTypeController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/EncounterTypeController1_8Test.java @@ -109,7 +109,7 @@ public void shouldCreateAEncounterType() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAnEncounterType() throws Exception { final String newName = "updated name"; SimpleObject encounterType = new SimpleObject(); @@ -123,6 +123,17 @@ public void shouldEditingAnEncounterType() throws Exception { assertEquals(newName, service.getEncounterTypeByUuid(getUuid()).getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAnEncounterTypeProperty() 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); + } + @Test public void shouldRetireAEncounterType() throws Exception { assertEquals(false, service.getEncounterTypeByUuid(getUuid()).isRetired()); diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/LocationTagController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/LocationTagController1_8Test.java index 2b06cef27..e46c077db 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/LocationTagController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/LocationTagController1_8Test.java @@ -108,7 +108,7 @@ public void shouldListAll() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldUpdateLocationTag() throws Exception { final String editedName = "Location Tag edited"; @@ -122,6 +122,16 @@ public void shouldUpdateLocationTag() throws Exception { } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingALocationTag() 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); + } + @Test public void shouldPurgeLocationTag() throws Exception { diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java index 817b3868b..e551e9e74 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java @@ -108,7 +108,7 @@ public void shouldCreateAPatientIdentifierType() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAPatientIdentifierType() throws Exception { final String newName = "updated name"; SimpleObject patientIdentifierType = new SimpleObject(); @@ -122,6 +122,18 @@ public void shouldEditingAPatientIdentifierType() throws Exception { assertEquals(newName, service.getPatientIdentifierTypeByUuid(getUuid()).getName()); } + @Test + public void shouldThrowAnExceptionWhenEditingAPatientIdentifierType() 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()); + } + @Test public void shouldRetireAPatientIdentifierType() throws Exception { assertEquals(false, service.getPatientIdentifierTypeByUuid(getUuid()).isRetired()); diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PersonAttributeTypeController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PersonAttributeTypeController1_8Test.java index 0c62b4c72..6ee3f4a6d 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PersonAttributeTypeController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PersonAttributeTypeController1_8Test.java @@ -108,7 +108,7 @@ public void getPersonAttributeType_shouldGetAFullRepresentationOfAPersonAttribut * @throws Exception * @verifies change a property on a person */ - @Test + @Test(expected = RuntimeException.class) public void updatePersonAttributeType_shouldChangeAPropertyOnAPersonAttributeType() throws Exception { final String newDescription = "Updated description"; @@ -129,6 +129,22 @@ public void updatePersonAttributeType_shouldChangeAPropertyOnAPersonAttributeTyp Util.log("Edited PersonAttributeType Description: ", editedAttr.getDescription()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAPersonAttributeType() throws Exception { + + final String newDescription = "Updated description"; + + PersonAttributeType obj = service.getPersonAttributeTypeByUuid(getUuid()); + Assert.assertNotNull(obj); + Assert.assertFalse(newDescription.equals(obj.getDescription())); + Util.log("Old PersonAttributeType Description: ", obj.getDescription()); + + String json = "{\"description\":\"Updated description\"}"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } + /** * @see PersonAttributeTypeController#retirePersonAttributeType(PersonAttributeType,String,WebRequest) * @throws Exception diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PrivilegeController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PrivilegeController1_8Test.java index eeb27bf6f..f01a0bc06 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PrivilegeController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PrivilegeController1_8Test.java @@ -105,7 +105,7 @@ public void shouldCreateAPrivilege() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAPrivilege() throws Exception { final String newDescription = "updated descr"; SimpleObject privilege = new SimpleObject(); @@ -120,6 +120,20 @@ public void shouldEditingAPrivilege() throws Exception { assertEquals(newDescription, service.getPrivilegeByUuid(getUuid()).getDescription()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAPrivilage() 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); + } + @Test public void shouldPurgeAPrivilege() throws Exception { assertNotNull(service.getPrivilegeByUuid(getUuid())); diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/RoleController1_8Test.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/RoleController1_8Test.java index 7918a07e3..6f9b7896c 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/RoleController1_8Test.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/RoleController1_8Test.java @@ -126,7 +126,7 @@ public void getRole_shouldGetAFullRepresentationOfARole() throws Exception { * HttpServletResponse) * @verifies change a property on a Role */ - @Test + @Test(expected = RuntimeException.class) public void updateRole_shouldChangeAPropertyOnARole() throws Exception { final String editedDescription = "Role description edited"; @@ -141,6 +141,16 @@ public void updateRole_shouldChangeAPropertyOnARole() throws Exception { } + @Test(expected = RuntimeException.class) + public void updateRole_shouldThrowAnExceptionWhenEditingAPrivilage() throws Exception { + + final String editedDescription = "Role description edited"; + String json = "{ \"description\":\"" + editedDescription + "\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } + /** * @see RoleController#delete(String, String, javax.servlet.http.HttpServletRequest, * HttpServletResponse) diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptMapTypeController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptMapTypeController1_9Test.java index ab58d1cf4..3aeef9401 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptMapTypeController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptMapTypeController1_9Test.java @@ -105,7 +105,7 @@ public void shouldCreateAConceptMapType() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAConceptMapType() throws Exception { final String newName = "updated name"; SimpleObject conceptMapTypeType = new SimpleObject(); @@ -118,6 +118,18 @@ public void shouldEditingAConceptMapType() throws Exception { handle(req); assertEquals(newName, service.getConceptMapTypeByUuid(getUuid()).getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAConceptMapType() 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); + } @Test public void shouldRetireAConceptMapType() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceTermController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceTermController1_9Test.java index ef28f4235..ee113b24b 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceTermController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceTermController1_9Test.java @@ -110,7 +110,7 @@ public void shouldCreateAConceptReferenceTerm() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAConceptReferenceTerm() throws Exception { final String newCode = "updated code"; SimpleObject conceptReferenceTermType = new SimpleObject(); @@ -123,6 +123,18 @@ public void shouldEditingAConceptReferenceTerm() throws Exception { handle(req); assertEquals(newCode, service.getConceptReferenceTermByUuid(getUuid()).getCode()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAConceptReferenceTerm() throws Exception { + final String newCode = "updated code"; + SimpleObject conceptReferenceTermType = new SimpleObject(); + conceptReferenceTermType.add("code", newCode); + + String json = new ObjectMapper().writeValueAsString(conceptReferenceTermType); + + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireAConceptReferenceTerm() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/DrugController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/DrugController1_9Test.java index a9d2b5915..470b236d2 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/DrugController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/DrugController1_9Test.java @@ -109,7 +109,7 @@ public void shouldCreateADrug() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldEditADrug() throws Exception { final String editedName = "Aspirin Edited"; @@ -123,6 +123,15 @@ public void shouldEditADrug() throws Exception { Assert.assertEquals(editedName, editedDrug.getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingADrug() throws Exception { + + final String editedName = "Aspirin Edited"; + String json = "{ \"name\":\"" + editedName + "\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireADrug() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterRoleController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterRoleController1_9Test.java index ed96fd8bf..b4bf9f2ef 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterRoleController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/EncounterRoleController1_9Test.java @@ -93,7 +93,7 @@ public void shouldCreateAEncounterRole() throws Exception { assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditingAnEncounterRole() throws Exception { final String newName = "updated name"; SimpleObject encounterRole = new SimpleObject(); @@ -106,6 +106,18 @@ public void shouldEditingAnEncounterRole() throws Exception { handle(req); assertEquals(newName, service.getEncounterRoleByUuid(getUuid()).getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAnEncounterRole() throws Exception { + final String newName = "updated name"; + SimpleObject encounterRole = new SimpleObject(); + encounterRole.add("name", newName); + + String json = new ObjectMapper().writeValueAsString(encounterRole); + + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireAEncounterRole() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationAttributeTypeController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationAttributeTypeController1_9Test.java index a002d05d8..ae4c60f1b 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationAttributeTypeController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationAttributeTypeController1_9Test.java @@ -75,7 +75,7 @@ public void createLocationAttributeType_shouldCreateANewLocationAttributeType() * @see LocationAttributeTypeController#updateLocationAttributeType(LocationAttributeType,SimpleObject,WebRequest) * @verifies change a property on a location */ - @Test + @Test(expected = RuntimeException.class) public void updateLocationAttributeType_shouldChangeAPropertyOnALocationAttributeType() throws Exception { String json = "{\"description\":\"Updated description\"}"; @@ -83,6 +83,12 @@ public void updateLocationAttributeType_shouldChangeAPropertyOnALocationAttribut Assert.assertEquals("Updated description", Context.getLocationService().getLocationAttributeType(1).getDescription()); } + @Test(expected = RuntimeException.class) + public void updateLocationAttributeType_shouldshouldThrowAnExceptionWhenEditingAPropertyOnALocationAttributeType() throws Exception { + String json = "{\"description\":\"Updated description\"}"; + + handle(newPostRequest(getURI() + "/" + getUuid(), json)); + } /** * @see LocationAttributeTypeController#retireLocationAttributeType(LocationAttributeType,String,WebRequest) diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationController1_9Test.java index c784b6e20..5943d2de0 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/LocationController1_9Test.java @@ -124,7 +124,7 @@ public void shouldCreateALocation() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldEditALocation() throws Exception { final String editedName = "Xanadu edited"; @@ -138,12 +138,21 @@ public void shouldEditALocation() throws Exception { Assert.assertEquals(editedName, editedLocation.getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingALocation() throws Exception { + + final String editedName = "Xanadu edited"; + String json = "{ \"name\":\"" + editedName + "\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } /** * See RESTWS-418 - Allow REST POST requests to accept un-updatable properties if they haven't * been updated */ - @Test + @Test(expected = RuntimeException.class) public void shouldAllowYouToPostANonUpdatablePropertyWithAnUnchangedValue() throws Exception { MockHttpServletRequest get = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject location = deserialize(handle(get)); @@ -155,8 +164,17 @@ public void shouldAllowYouToPostANonUpdatablePropertyWithAnUnchangedValue() thro Location updatedLocation = service.getLocationByUuid(getUuid()); assertThat(updatedLocation.getName(), is("New York")); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenYouPostANonUpdatablePropertyWithAnUnchangedValue() throws Exception { + MockHttpServletRequest get = request(RequestMethod.GET, getURI() + "/" + getUuid()); + SimpleObject location = deserialize(handle(get)); + location.put("name", "New York"); + + MockHttpServletRequest post = newPostRequest(getURI() + "/" + getUuid(), location); + handle(post); + } - @Test + @Test(expected = RuntimeException.class) public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); @@ -172,6 +190,18 @@ public void shouldOverwriteAListOfChildLocations() throws Exception { Assert.assertTrue(updatedLocation.getChildLocations().isEmpty()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenOverwriteAListOfChildLocations() throws Exception { + + Location location = service.getLocationByUuid(getUuid()); + location.addChildLocation(service.getLocation(2)); + service.saveLocation(location); + + String json = "{ \"childLocations\": [] }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireALocation() throws Exception { @@ -190,7 +220,7 @@ public void shouldRetireALocation() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldUnretireALocation() throws Exception { Location location = service.getLocation(3); @@ -204,6 +234,17 @@ public void shouldUnretireALocation() throws Exception { Assert.assertTrue(!updatedLocation.isRetired()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenYouUnretireALocation() throws Exception { + + Location location = service.getLocation(3); + Assert.assertTrue(location.isRetired()); + + String json = "{ \"retired\": false }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldPurgeARetiredLocation() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProgramController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProgramController1_9Test.java index ae5c21adc..6776e01f4 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProgramController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProgramController1_9Test.java @@ -124,7 +124,7 @@ public void shouldCreateAProgram() throws Exception { Assert.assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAProgram() throws Exception { final String editedName = "Malaria Program Edited"; @@ -137,6 +137,15 @@ public void shouldEditAProgram() throws Exception { Assert.assertNotNull(editedProgram); Assert.assertEquals(editedName, editedProgram.getName()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAProgram() throws Exception { + + final String editedName = "Malaria Program Edited"; + String json = "{ \"name\":\"" + editedName + "\" }"; + MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); + req.setContent(json.getBytes()); + handle(req); + } @Test public void shouldRetireAProgram() throws Exception { diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderAttributeTypeController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderAttributeTypeController1_9Test.java index 08d19e361..639d563d4 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderAttributeTypeController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderAttributeTypeController1_9Test.java @@ -51,14 +51,18 @@ public void createProviderAttributeType_shouldCreateANewProviderAttributeType() * @see ProviderAttributeTypeController#updateProviderAttributeType(ProviderAttributeType,SimpleObject,WebRequest) * @verifies change a property on a provider */ - @Test + @Test(expected = RuntimeException.class) public void updateProviderAttributeType_shouldChangeAPropertyOnAProviderAttributeType() throws Exception { String json = "{\"description\":\"Updated description\"}"; handle(newPostRequest(getURI() + "/" + RestTestConstants1_9.PROVIDER_ATTRIBUTE_TYPE_UUID, json)); Assert.assertEquals("Updated description", Context.getProviderService().getProviderAttributeType(1).getDescription()); } - + @Test(expected = RuntimeException.class) + public void updateProviderAttributeType_shouldThrowAnExceptionWhenEditingAPropertyOnAProviderAttributeType() throws Exception { + String json = "{\"description\":\"Updated description\"}"; + handle(newPostRequest(getURI() + "/" + RestTestConstants1_9.PROVIDER_ATTRIBUTE_TYPE_UUID, json)); + } /** * @see ProviderAttributeTypeController#retireProviderAttributeType(ProviderAttributeType,String,WebRequest) * @verifies void a provider attribute type diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderController1_9Test.java index 1bcd2b8ac..dce0d6c5a 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ProviderController1_9Test.java @@ -68,7 +68,7 @@ public void createProvider_shouldCreateANewProviderWithAttributes() throws Excep * @see ProviderController#updateProvider(Provider,SimpleObject,WebRequest) * @verifies should fail when changing a person property on a Provider */ - @Test(expected = ConversionException.class) + @Test(expected = RuntimeException.class) public void updateProvider_shouldFailWhenChangingAPersonPropertyOnAProvider() throws Exception { Date now = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -76,6 +76,14 @@ public void updateProvider_shouldFailWhenChangingAPersonPropertyOnAProvider() th handle(newPostRequest(getURI() + "/" + RestTestConstants1_9.PROVIDER_UUID, json)); } + @Test(expected = RuntimeException.class) + public void updateProvider_shouldThrowAnExceptionWhenChangingAPersonPropertyOnAProvider() throws Exception { + Date now = new Date(); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String json = "{\"birthdate\":\"" + df.format(now) + "\"}"; + + handle(newPostRequest(getURI() + "/" + RestTestConstants1_9.PROVIDER_UUID, json)); + } /** * @see ProviderController#voidProvider(Provider,String,WebRequest) diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitAttributeTypeController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitAttributeTypeController1_9Test.java index 666972e3a..aa265098d 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitAttributeTypeController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitAttributeTypeController1_9Test.java @@ -84,7 +84,7 @@ public void create_shouldCreateANewVisitAttributeType() throws Exception { * @see VisitAttributeTypeController#update(String, SimpleObject, * javax.servlet.http.HttpServletRequest, HttpServletResponse) */ - @Test + @Test(expected = RuntimeException.class) public void update_shouldChangeAPropertyOnAVisitAttributeType() throws Exception { String json = "{\"description\":\"Updated description\"}"; @@ -92,6 +92,12 @@ public void update_shouldChangeAPropertyOnAVisitAttributeType() throws Exception Assert.assertEquals("Updated description", service.getVisitAttributeType(1).getDescription()); } + @Test(expected = RuntimeException.class) + public void update_shouldThrowAnExceptionWhenEditingAPropertyOnAVisitAttributeType() throws Exception { + String json = "{\"description\":\"Updated description\"}"; + + handle(newPostRequest(getURI() + "/" + getUuid(), json)); + } /** * @see VisitAttributeTypeController#delete(String, String, diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitTypeController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitTypeController1_9Test.java index 69c85f128..9e87e2ba5 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitTypeController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/VisitTypeController1_9Test.java @@ -83,7 +83,7 @@ public void shouldCreateAVisitType() throws Exception { Assert.assertEquals(originalCount + 1, service.getAllVisitTypes().size()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAVisitType() throws Exception { String json = "{ \"name\":\"new visit type\", \"description\":\"new description\" }"; handle(newPostRequest(getURI() + "/" + getUuid(), json)); @@ -92,6 +92,12 @@ public void shouldEditAVisitType() throws Exception { Assert.assertEquals("new visit type", updated.getName()); Assert.assertEquals("new description", updated.getDescription()); } + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditAVisitType() throws Exception { + String json = "{ \"name\":\"new visit type\", \"description\":\"new description\" }"; + handle(newPostRequest(getURI() + "/" + getUuid(), json)); + } + @Test public void shouldRetireAVisitType() throws Exception { diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/ConceptSourceController2_0Test.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/ConceptSourceController2_0Test.java index b5fd1623b..9fd98a7e8 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/ConceptSourceController2_0Test.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/ConceptSourceController2_0Test.java @@ -113,7 +113,7 @@ public void shouldCreateAConceptSource() throws Exception { Assert.assertEquals(originalCount + 1, getAllCount()); } - @Test + @Test(expected = RuntimeException.class) public void shouldEditAConceptSource() throws Exception { final String newName = "updated name"; SimpleObject conceptSource = new SimpleObject(); @@ -126,6 +126,19 @@ public void shouldEditAConceptSource() throws Exception { handle(req); Assert.assertEquals(newName, service.getConceptSourceByUuid(getUuid()).getName()); } + + @Test(expected = RuntimeException.class) + public void shouldThrowAnExceptionWhenEditingAConceptSource() 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); + } @Test public void shouldRetireAConceptSource() throws Exception { diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java index ae0d71d7d..cae9ef710 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java @@ -19,6 +19,7 @@ import org.openmrs.OpenmrsMetadata; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -28,7 +29,9 @@ import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.response.ConversionException; +import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.validation.ValidateUtil; /** * Subclass of {@link DelegatingCrudResource} with helper methods specific to @@ -217,4 +220,48 @@ public DelegatingResourceDescription getCreatableProperties() { public boolean isRetirable() { return true; } + + @Override + public Object update(String uuid, SimpleObject propertiesToUpdate, RequestContext context) throws ResponseException { + T delegate = getByUniqueId(uuid); + if (delegate == null) + throw new ObjectNotFoundException(); + if (propertiesToUpdate.get("name") != delegate.getName()) { + throw new RuntimeException( + "does not support editing of this type because this is metadata"); + } + if (hasTypesDefined()) { + // if they specify a type discriminator it must match the expected one--type can't be modified + if (propertiesToUpdate.containsKey(RestConstants.PROPERTY_FOR_TYPE)) { + String type = (String) propertiesToUpdate.remove(RestConstants.PROPERTY_FOR_TYPE); + if (!delegate.getClass().equals(getActualSubclass(type))) { + String nameToShow = getTypeName(delegate); + if (nameToShow == null) + nameToShow = delegate.getClass().getName(); + throw new IllegalArgumentException("You passed " + RestConstants.PROPERTY_FOR_TYPE + "=" + type + + " but this instance is a " + nameToShow); + } + } + } + + DelegatingResourceHandler handler = getResourceHandler(delegate); + + DelegatingResourceDescription description = handler.getUpdatableProperties(); + if (isRetirable()) { + description.addProperty("retired"); + } + + setConvertedProperties(delegate, propertiesToUpdate, description, false); + ValidateUtil.validate(delegate); + delegate = save(delegate); + + SimpleObject ret = (SimpleObject) ConversionUtil.convertToRepresentation(delegate, context.getRepresentation()); + + // add the 'type' discriminator if we support subclasses + if (hasTypesDefined()) { + ret.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate)); + } + + return ret; + } }