-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RESTWS-739:Reposting metadata should not persist changes #414
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
orderType.add("name", newName); | ||||||
String json = new ObjectMapper().writeValueAsString(orderType); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
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()); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 + "\" }"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rename the |
||
MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); | ||
req.setContent(json.getBytes()); | ||
handle(req); | ||
} | ||
|
||
@Test | ||
public void shouldRetireAnOrderSet() throws Exception { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
conceptSource.add("name", newName); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you use a builder for |
||||||
|
||||||
String json = new ObjectMapper().writeValueAsString(conceptSource); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try to re-use an |
||||||
|
||||||
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()); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question like the previous test case name applies to this as well. |
||
|
||
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 { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log statement will not be useful when we are running the test. Because we will expect an Exception to be thrown. So, in this situation why do you think this information is useful to see? |
||
|
||
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 | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitcliff after your changes , now these tests return Exceptions ?? Thats wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mozzy11 these tests were run against the update method in DelegatingCrudResource which was allowing reposting of changes metadata but the ticket description says this should not happen any more with metadata hence notifying the client with an exception ,,,thats why the tests that were permitiing the reposting of metadata data initially are now throwing exceptional errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitcliff ,the tickect talks about forbidding re-posting metadata, not updating metadata.
So idealy updating meta-data shouldnt have any problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, @mozzy11 and @gitcliff I haven't looked deeply at the code but looking at the ticket, the idea is, for example, if you post to the Encounter endpoint, although you can change the encounter type of that encounter, you shouldn't be able to inadvertantly change any of the underlying properties (name, etc) of that encounter type. However, you should be able to post directly to the EncounterType endpoint and change the name, etc.
The idea is that you shouldn't be able to by mistake change a piece of metadata when updating some data that refers to that metadata. Hope that makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense @mogoodrich
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mozzy11 u can also have a look a this , it concurs with what @mogoodrich was explaining above