Skip to content

Commit

Permalink
Added tests for FhirQuestionnaireServiceImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-loliveira committed Jul 17, 2024
1 parent ed5c0ac commit 0d1c9d4
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void searchForQuestionnaires_shouldSearchForQuestionnairesByName() {
}

@Test
public void searchForQuestionnaires_shouldReturnCollectionOfPatientWhenLastUpdatedMatched() {
public void searchForQuestionnaires_shouldReturnCollectionOfQuestionnaireWhenLastUpdatedMatched() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);

SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER,
Expand Down Expand Up @@ -198,6 +198,47 @@ public void searchForQuestionnaires_shouldReturnEmptyCollectionWhenLastUpdatedNo
assertThat(get(results), empty());
}

@Test
public void getQuestionnaireEverything_shouldReturnAllInformationAboutAllQuestionnaires() {
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "");

when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(form));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams,
dao, questionnaireTranslator, globalPropertyService, searchQueryInclude));

when(questionnaireTranslator.toFhirResource(form)).thenReturn(fhirQuestionnaire);

IBundleProvider results = questionnaireService.getQuestionnaireEverything();
List<IBaseResource> resultList = get(results);

assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(1));
}

@Test
public void getQuestionnaireEverything_shouldReturnAllInformationAboutSpecifiedQuestionnaire() {
TokenParam questionnaireId = new TokenParam().setValue(FORM_UUID);

SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "")
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, questionnaireId);

when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(form));
when(dao.getSearchResultsCount(any())).thenReturn(1);
when(questionnaireTranslator.toFhirResource(form)).thenReturn(fhirQuestionnaire);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams,
dao, questionnaireTranslator, globalPropertyService, searchQueryInclude));

IBundleProvider results = questionnaireService.getQuestionnaireEverything(questionnaireId);

List<IBaseResource> resultList = get(results);

assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(1));

}

private List<IBaseResource> get(IBundleProvider results) {
return results.getResources(0, 10);
}
Expand Down

0 comments on commit 0d1c9d4

Please sign in to comment.