From 50efd1a04e7d81cb672d167147aaa8f03b5696ca Mon Sep 17 00:00:00 2001 From: gita cliff Date: Tue, 26 Nov 2019 09:28:22 +0300 Subject: [PATCH] RESTWS-739:Reposting metadata should not persist changes --- .../OrderTypeController1_10Test.java | 2 +- .../OrderSetController1_12Test.java | 5 +- .../ConceptSourceController1_8Test.java | 3 +- .../EncounterTypeController1_8Test.java | 6 +- .../LocationTagController1_8Test.java | 3 +- ...atientIdentifierTypeController1_8Test.java | 6 +- .../PersonAttributeTypeController1_8Test.java | 6 +- .../PrivilegeController1_8Test.java | 2 +- .../openmrs1_8/RoleController1_8Test.java | 3 +- .../ConceptMapTypeController1_9Test.java | 10 ++-- ...ConceptReferenceTermController1_9Test.java | 36 +++++------- .../openmrs1_9/DrugController1_9Test.java | 2 +- .../EncounterRoleController1_9Test.java | 8 +-- ...ocationAttributeTypeController1_9Test.java | 9 +-- .../openmrs1_9/LocationController1_9Test.java | 15 ++--- .../openmrs1_9/ProgramController1_9Test.java | 9 ++- ...roviderAttributeTypeController1_9Test.java | 11 ++-- .../openmrs1_9/ProviderController1_9Test.java | 20 +++---- .../VisitAttributeTypeController1_9Test.java | 6 +- .../VisitTypeController1_9Test.java | 6 +- .../ConceptSourceController2_0Test.java | 2 +- .../impl/MetadataDelegatingCrudResource.java | 56 +++++++++++++++++-- 22 files changed, 134 insertions(+), 92 deletions(-) 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 1674aa9756..21c0cd7062 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(); 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 4237da6358..405a1b1390 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"; 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 aa7f1f5189..b87629ea1c 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,7 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; -import java.util.Date; import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -114,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(); 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 90e96225cb..2a3936b637 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 @@ -10,13 +10,11 @@ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import java.util.Date; import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; @@ -109,7 +107,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(); 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 2b06cef271..b6329851aa 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 @@ -21,6 +21,7 @@ import org.openmrs.module.webservices.rest.test.Util; import org.openmrs.module.webservices.rest.web.RestTestConstants1_8; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; +import org.openmrs.web.controller.encounter.LocationTagController; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; @@ -108,7 +109,7 @@ public void shouldListAll() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldUpdateLocationTag() throws Exception { final String editedName = "Location Tag edited"; 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 817b3868b6..2736f34b24 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 @@ -10,13 +10,11 @@ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import java.util.Date; import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; @@ -108,7 +106,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(); 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 0c62b4c725..26f06b255d 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 @@ -10,7 +10,9 @@ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; import java.util.List; -import java.util.Date; + +import javax.servlet.http.HttpServletResponse; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -108,7 +110,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"; 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 eeb27bf6f8..3db508f881 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(); 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 7918a07e32..9dc33b0713 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 @@ -10,7 +10,6 @@ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8; import java.util.List; -import java.util.Date; import javax.servlet.http.HttpServletResponse; @@ -126,7 +125,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"; 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 ab58d1cf4f..574c82b6ae 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 @@ -9,6 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; @@ -24,10 +28,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - /** * Tests CRUD operations for {@link ConceptMapType}s via web service calls */ @@ -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(); 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 ef28f4235c..6236906475 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 @@ -9,11 +9,22 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; -import org.apache.commons.beanutils.BeanUtils; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +import java.util.List; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.hamcrest.Matcher; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.openmrs.ConceptReferenceTerm; @@ -28,23 +39,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.hasValue; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - /** * Tests CRUD operations for {@link ConceptReferenceTerm}s via web service calls */ @@ -110,7 +104,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(); @@ -280,7 +274,7 @@ public void shouldFindByCodeOrNameEqualCodeWithLimit() throws Exception { @Test(expected = InvalidSearchException.class) public void shouldThrowExceptionWhenSearchTypeIsInvalid() throws Exception { - SimpleObject result = deserialize(handle(newGetRequest(getURI(), new Parameter("source", + deserialize(handle(newGetRequest(getURI(), new Parameter("source", "Some Standardized Terminology"), new Parameter("codeOrName", "WGT"), new Parameter("searchType", "invalid")))); } } 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 a9d2b59159..3c9a9ad693 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"; 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 ed96fd8bff..8950356bcc 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 @@ -9,6 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Before; @@ -24,9 +27,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - /** * Tests functionality of {@link EncounterRoleController}. */ @@ -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(); 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 a002d05d8e..5969987cfd 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 @@ -9,6 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + import org.apache.commons.beanutils.PropertyUtils; import org.junit.Assert; import org.junit.Before; @@ -23,9 +27,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - public class LocationAttributeTypeController1_9Test extends MainResourceControllerTest { /** @@ -75,7 +76,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\"}"; 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 c784b6e20f..32b4b556ab 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 @@ -9,8 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + import java.util.Collection; import java.util.List; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -27,9 +31,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - /** * Tests functionality of {@link LocationController}. */ @@ -124,7 +125,7 @@ public void shouldCreateALocation() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldEditALocation() throws Exception { final String editedName = "Xanadu edited"; @@ -143,7 +144,7 @@ public void shouldEditALocation() throws Exception { * 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)); @@ -156,7 +157,7 @@ public void shouldAllowYouToPostANonUpdatablePropertyWithAnUnchangedValue() thro assertThat(updatedLocation.getName(), is("New York")); } - @Test + @Test(expected = RuntimeException.class) public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); @@ -190,7 +191,7 @@ public void shouldRetireALocation() throws Exception { } - @Test + @Test(expected = RuntimeException.class) public void shouldUnretireALocation() throws Exception { Location location = service.getLocation(3); 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 ae5c21adcf..32a6884c64 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 @@ -9,6 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import java.util.List; +import java.util.Map; + import org.apache.commons.beanutils.PropertyUtils; import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; @@ -24,10 +27,6 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; -import java.util.List; -import java.util.Map; -import java.util.Date; - /** * Tests functionality of Program CRUD by MainResourceController */ @@ -124,7 +123,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"; 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 08d19e3614..7d333d2eaa 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 @@ -9,8 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; -import org.junit.Assert; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + import org.apache.commons.beanutils.PropertyUtils; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openmrs.ProviderAttributeType; @@ -23,9 +27,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - public class ProviderAttributeTypeController1_9Test extends MainResourceControllerTest { @Before @@ -51,7 +52,7 @@ 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)); 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 1bcd2b8acb..0fbeb09688 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 @@ -9,26 +9,26 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; -import org.junit.Assert; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + import org.apache.commons.beanutils.PropertyUtils; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openmrs.Provider; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RestTestConstants1_9; -import org.openmrs.module.webservices.rest.web.response.ConversionException; 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 org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletResponse; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - public class ProviderController1_9Test extends MainResourceControllerTest { @Before @@ -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"); @@ -134,7 +134,7 @@ public void shouldFindProviderByUserUuid() throws Exception { Assert.assertNotSame(0, results.size()); Object next = results.iterator().next(); - Assert.assertEquals(getUuid(), (String) PropertyUtils.getProperty(next, "uuid")); + Assert.assertEquals(getUuid(), PropertyUtils.getProperty(next, "uuid")); } /** 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 666972e3ad..e5f2208c13 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 @@ -9,6 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import javax.servlet.http.HttpServletResponse; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -21,8 +23,6 @@ import org.openmrs.module.webservices.rest.web.RestTestConstants1_9; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; -import javax.servlet.http.HttpServletResponse; - /** * Contains tests for {@link VisitAttributeTypeController} CRUD operations */ @@ -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\"}"; 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 69c85f128c..bf3e1d7a7e 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 @@ -9,6 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; +import java.util.List; + import org.apache.commons.beanutils.PropertyUtils; import org.junit.Assert; import org.junit.Before; @@ -21,8 +23,6 @@ import org.openmrs.module.webservices.rest.web.RestTestConstants1_9; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; -import java.util.List; - /** * Contains tests for the {@link VisitTypeController} */ @@ -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)); 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 b5fd1623ba..6d9fc0f03c 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(); 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 ae0d71d7de..a95f45415f 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 @@ -11,14 +11,11 @@ import java.util.Date; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; 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 +25,14 @@ 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; + +import io.swagger.models.Model; +import io.swagger.models.ModelImpl; +import io.swagger.models.properties.BooleanProperty; +import io.swagger.models.properties.StringProperty; /** * Subclass of {@link DelegatingCrudResource} with helper methods specific to @@ -217,4 +221,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; + } }