-
Notifications
You must be signed in to change notification settings - Fork 519
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-956 - Erroneous response when totalCount is included in query … #625
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 { | ||
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. Did you notice that this test passes even without your fix? |
||
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 { | ||
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. Did you notice that this test passes even without your fix? |
||
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); | ||
} | ||
} |
Oops, something went wrong.
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.
Can we add a test for this?
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.
Sure, on it!
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.
I have added
EncounterSearchHandler2_0Test