Skip to content

Commit

Permalink
RESTWS-739:Reposting metadata should not persist changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcliff committed Nov 28, 2019
1 parent 97549ed commit 17236d2
Show file tree
Hide file tree
Showing 22 changed files with 322 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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";
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void shouldCreateADrug() throws Exception {

}

@Test
@Test(expected = RuntimeException.class)
public void shouldEditADrug() throws Exception {

final String editedName = "Aspirin Edited";
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 17236d2

Please sign in to comment.