-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTWS-956 - Erroneous response when totalCount is included in query … (
#625) * RESTWS-956 - Erroneous response when totalCount is included in query parameters for fetching encounters * Added EncounterSearchHandler2_0Test to test for encounter list based on filters (patient, encounterType) and limit (size of results limited is not necessarily same as totalCount) --------- Co-authored-by: Amos Laboso <[email protected]>
- Loading branch information
Showing
2 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
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
93 changes: 93 additions & 0 deletions
93
...mrs/module/webservices/rest/web/v1_0/search/openmrs2_0/EncounterSearchHandler2_0Test.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,93 @@ | ||
/** | ||
* 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.search.openmrs2_0; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openmrs.Encounter; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.RestTestConstants1_8; | ||
import org.openmrs.module.webservices.rest.web.RestTestConstants1_9; | ||
import org.openmrs.module.webservices.rest.web.v1_0.controller.RestControllerTestUtils; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
public class EncounterSearchHandler2_0Test extends RestControllerTestUtils { | ||
|
||
protected String getURI() { | ||
return "encounter"; | ||
} | ||
|
||
/** | ||
* @verifies returns encounters and totalCount filtered by patient uuid only | ||
* @see @see EncounterSearchHandler2_0#search(RequestContext) | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void search_shouldReturnEncountersWithTotalCountFilteredByPatient() throws Exception { | ||
MockHttpServletRequest req = request(RequestMethod.GET, getURI()); | ||
req.addParameter("patient", RestTestConstants1_9.PATIENT_WITH_OBS_UUID); | ||
req.addParameter("totalCount", String.valueOf(Boolean.TRUE)); | ||
|
||
SimpleObject result = deserialize(handle(req)); | ||
List<Encounter> encounters = result.get("results"); | ||
Assert.assertEquals(3, encounters.size()); | ||
int totalCount = result.get("totalCount"); | ||
Assert.assertNotNull(totalCount); | ||
Assert.assertEquals(3, totalCount); | ||
Assert.assertEquals(encounters.size(), totalCount); | ||
} | ||
|
||
/** | ||
* @verifies returns encounters and totalCount filtered by patient uuid and encounterType uuid | ||
* @see @see EncounterSearchHandler2_0#search(RequestContext) | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void search_shouldReturnEncountersWithTotalCountFilteredByPatientAndEncounterType() throws Exception { | ||
MockHttpServletRequest req = request(RequestMethod.GET, getURI()); | ||
req.addParameter("patient", RestTestConstants1_9.PATIENT_WITH_OBS_UUID); | ||
req.addParameter("encounterType", RestTestConstants1_8.ENCOUNTER_TYPE_UUID); | ||
req.addParameter("totalCount", String.valueOf(Boolean.TRUE)); | ||
|
||
SimpleObject result = deserialize(handle(req)); | ||
List<Encounter> encounters = result.get("results"); | ||
Assert.assertEquals(2, encounters.size()); | ||
int totalCount = result.get("totalCount"); | ||
Assert.assertNotNull(totalCount); | ||
Assert.assertEquals(2, totalCount); | ||
Assert.assertEquals(encounters.size(), totalCount); | ||
} | ||
|
||
/** | ||
* @verifies returns encounters and totalCount filtered by patient uuid and limit | ||
* i.e. (limit 1, results size should not be the same as totalCount) | ||
* | ||
* @see @see EncounterSearchHandler2_0#search(RequestContext) | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void search_shouldReturnEncountersWithTotalCountFilteredByPatientLimitedToOne() throws Exception { | ||
MockHttpServletRequest req = request(RequestMethod.GET, getURI()); | ||
req.addParameter("patient", RestTestConstants1_9.PATIENT_WITH_OBS_UUID); | ||
req.addParameter("limit", String.valueOf(1)); | ||
req.addParameter("totalCount", String.valueOf(Boolean.TRUE)); | ||
|
||
SimpleObject result = deserialize(handle(req)); | ||
List<Encounter> encounters = result.get("results"); | ||
Assert.assertEquals(1, encounters.size()); | ||
int totalCount = result.get("totalCount"); | ||
Assert.assertNotNull(totalCount); | ||
Assert.assertEquals(3, totalCount); | ||
Assert.assertNotEquals(encounters.size(), totalCount); | ||
} | ||
} |