-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESRWS-707: Fix bug in encounterRole endpoint
- Loading branch information
1 parent
5d656d7
commit 36fe583
Showing
6 changed files
with
148 additions
and
3 deletions.
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
.../module/webservices/rest/web/v1_0/controller/openmrs1_11/EncounterRoleController1_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,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_11 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
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