-
Notifications
You must be signed in to change notification settings - Fork 505
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-707: Fix bug in encounterRole endpoint #332
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...nmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/EncounterRoleResource1_11.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; | ||
|
||
import org.openmrs.EncounterRole; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.RequestContext; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.annotation.Resource; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; | ||
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.EncounterRoleResource1_9; | ||
|
||
/** | ||
* {@link Resource} for {@link EncounterRole}, supporting standard CRUD operations | ||
*/ | ||
@Resource(name = RestConstants.VERSION_1 + "/encounterrole", supportedClass = EncounterRole.class, supportedOpenmrsVersions = { | ||
"1.11.*", "1.12.*", "2.0.*", "2.1.*", "2.2.*" }) | ||
public class EncounterRoleResource1_11 extends EncounterRoleResource1_9 { | ||
|
||
/** | ||
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) | ||
*/ | ||
@Override | ||
protected NeedsPaging<EncounterRole> doSearch(RequestContext context) { | ||
return new NeedsPaging<EncounterRole>(Context.getEncounterService().getEncounterRolesByName( | ||
context.getParameter("q")), context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ule/webservices/rest/web/v1_0/controller/openmrs1_11/EncounterRoleController1_11Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_11; | ||
|
||
import org.apache.commons.beanutils.PropertyUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openmrs.EncounterRole; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.test.Util; | ||
import org.openmrs.module.webservices.rest.web.RestTestConstants1_11; | ||
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
public class EncounterRoleController1_11Test extends MainResourceControllerTest { | ||
|
||
@Override | ||
public String getURI() { | ||
return "encounterrole"; | ||
} | ||
|
||
@Override | ||
public String getUuid() { | ||
return RestTestConstants1_11.ENCOUNTER_ROLE_UUID; | ||
} | ||
|
||
@Override | ||
public long getAllCount() { | ||
return 1; | ||
} | ||
|
||
@Test | ||
public void shouldGetAnEncounterRoleByName() throws Exception { | ||
final String ROLE_NAME = "Unknown"; | ||
|
||
MockHttpServletRequest req = request(RequestMethod.GET, getURI()); | ||
req.setParameter("q", ROLE_NAME); | ||
req.setParameter("v", "default"); | ||
SimpleObject result = deserialize(handle(req)); | ||
Object encounterRoleObject = Util.getResultsList(result).get(0); | ||
|
||
EncounterRole encounterRole = Context.getEncounterService().getEncounterRoleByName(ROLE_NAME); | ||
Assert.assertEquals(encounterRole.getUuid(), PropertyUtils.getProperty(encounterRoleObject, "uuid")); | ||
Assert.assertEquals(encounterRole.getName(), PropertyUtils.getProperty(encounterRoleObject, "name")); | ||
Assert.assertEquals(encounterRole.getDescription(), PropertyUtils.getProperty(encounterRoleObject, "description")); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../module/webservices/rest/web/v1_0/resource/openmrs1_11/EncounterRoleResource1_11Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; | ||
|
||
import org.openmrs.EncounterRole; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.RestTestConstants1_11; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; | ||
|
||
public class EncounterRoleResource1_11Test extends BaseDelegatingResourceTest<EncounterRoleResource1_11, EncounterRole> { | ||
|
||
@Override | ||
public EncounterRole newObject() { | ||
return Context.getEncounterService().getEncounterRoleByUuid(getUuidProperty()); | ||
} | ||
|
||
@Override | ||
public void validateDefaultRepresentation() throws Exception { | ||
super.validateDefaultRepresentation(); | ||
assertPropEquals("display", getDisplayProperty()); | ||
getObject().toString(); | ||
assertPropEquals("uuid", getObject().getUuid()); | ||
assertPropPresent("links"); | ||
} | ||
|
||
@Override | ||
public void validateFullRepresentation() throws Exception { | ||
super.validateFullRepresentation(); | ||
assertPropEquals("description", getObject().getDescription()); | ||
assertPropEquals("dateCreated", getObject().getDateChanged()); | ||
assertPropEquals("retired", getObject().getRetired()); | ||
assertPropEquals("name", getObject().getName()); | ||
assertPropPresent("auditInfo"); | ||
assertPropPresent("retired"); | ||
assertPropPresent("resourceVersion"); | ||
} | ||
|
||
@Override | ||
public String getDisplayProperty() { | ||
return "Unknown"; | ||
} | ||
|
||
@Override | ||
public String getUuidProperty() { | ||
return RestTestConstants1_11.ENCOUNTER_ROLE_UUID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this used anywhere?
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, it's been used in the test files
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.
Can you point me to the exact line?
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.
https://github.com/larrystone/openmrs-module-webservices.rest/blob/41b70a6fe09f2601ed7be96c2204ea8a73bea097/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/EncounterRoleResource1_11Test.java#L52
https://github.com/larrystone/openmrs-module-webservices.rest/blob/41b70a6fe09f2601ed7be96c2204ea8a73bea097/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_11/EncounterRoleController1_11Test.java#L33