diff --git a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java index 1ab9b58..c985bf6 100644 --- a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java +++ b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java @@ -6,7 +6,6 @@ import gov.cms.madie.terminology.exceptions.VsacResourceNotFoundException; import gov.cms.madie.terminology.models.CodeSystem; import gov.cms.madie.terminology.util.TerminologyServiceUtil; -import gov.cms.madie.models.measure.ManifestExpansion; import gov.cms.madie.terminology.dto.ValueSetsSearchCriteria; import io.netty.channel.ChannelOption; import lombok.extern.slf4j.Slf4j; @@ -120,21 +119,6 @@ public String searchValueSets(String apiKey, Map queryParams) { return fetchResourceFromVsac(uri.toString(), apiKey, "bundle"); } - public String getValueSetResource( - String apiKey, - ValueSetsSearchCriteria.ValueSetParams valueSetParams, - String profile, - String includeDraft, - String activeOnly, - ManifestExpansion manifestExpansion) { - profile = StringUtils.isNotBlank(profile) ? defaultProfile : profile; - URI uri = - TerminologyServiceUtil.buildValueSetResourceUri( - valueSetParams, profile, includeDraft, activeOnly, manifestExpansion); - - return fetchResourceFromVsac(uri.toString(), apiKey, "ValueSet"); - } - public String getValueSetResources(String apiKey, ValueSetsSearchCriteria searchCriteria) { String profile = StringUtils.isNotBlank(searchCriteria.getProfile()) diff --git a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java index 7951a9b..f2fc862 100644 --- a/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java +++ b/src/test/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClientTest.java @@ -15,7 +15,12 @@ import org.springframework.web.reactive.function.client.WebClientResponseException; import java.io.IOException; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class FhirTerminologyServiceWebClientTest { @@ -34,6 +39,8 @@ class FhirTerminologyServiceWebClientTest { private ValueSetsSearchCriteria.ValueSetParams testValueSetParams; + private ValueSetsSearchCriteria searchCriteria; + FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient; @BeforeAll @@ -44,6 +51,15 @@ static void setUp() throws IOException { @BeforeEach void initialize() { + searchCriteria = + ValueSetsSearchCriteria.builder() + .profile(null) + .includeDraft(null) + .activeOnly("false") + .manifestExpansion(new ManifestExpansion()) + .valueSetParams( + List.of(ValueSetsSearchCriteria.ValueSetParams.builder().oid("test-vs-id").build())) + .build(); testValueSetParams = ValueSetsSearchCriteria.ValueSetParams.builder().oid("test-vs-id").build(); String baseUrl = String.format("http://localhost:%s", mockBackEnd.getPort()); fhirTerminologyServiceWebClient = @@ -94,13 +110,15 @@ void getLatestValueSetResourceSuccessfully_when_noCustomSearchCriteriaIsProvided .setResponseCode(200) .setBody(MOCK_RESPONSE_STRING) .addHeader("Content-Type", "application/fhir+json")); + when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); String actualResponse = - fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion()); + fhirTerminologyServiceWebClient.getValueSetResources(MOCK_API_KEY, searchCriteria); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand?activeOnly=false", recordedRequest.getPath()); + assertThat( + recordedRequest.getBody().readUtf8(), + containsString("/ValueSet/test-vs-id/$expand?activeOnly=false")); } @Test @@ -111,15 +129,16 @@ void getDraftValueSetResourceSuccessfully_when_noCustomSearchCriteriaIsProvided( .setResponseCode(200) .setBody(MOCK_RESPONSE_STRING) .addHeader("Content-Type", "application/fhir+json")); + when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); + searchCriteria.setIncludeDraft("true"); String actualResponse = - fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, "yes", "false", new ManifestExpansion()); + fhirTerminologyServiceWebClient.getValueSetResources(MOCK_API_KEY, searchCriteria); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals( - "/ValueSet/test-vs-id/$expand?includeDraft=true&activeOnly=false", - recordedRequest.getPath()); + assertThat( + recordedRequest.getBody().readUtf8(), + containsString("ValueSet/test-vs-id/$expand?includeDraft=true&activeOnly=false")); } @Test @@ -130,23 +149,21 @@ void getValueSetResourceSuccessfully_when_manifestExpansionIsProvided() .setResponseCode(200) .setBody(MOCK_RESPONSE_STRING) .addHeader("Content-Type", "application/fhir+json")); + when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); + searchCriteria.setManifestExpansion( + ManifestExpansion.builder() + .id("test-manifest-456") + .fullUrl("https://cts.nlm.nih.gov/fhir/Library/test-manifest-456") + .build()); String actualResponse = - fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, - testValueSetParams, - null, - null, - "true", - ManifestExpansion.builder() - .id("test-manifest-456") - .fullUrl("https://cts.nlm.nih.gov/fhir/Library/test-manifest-456") - .build()); + fhirTerminologyServiceWebClient.getValueSetResources(MOCK_API_KEY, searchCriteria); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals( - "/ValueSet/test-vs-id/$expand?manifest=https://cts.nlm.nih.gov/fhir/Library/test-manifest-456", - recordedRequest.getPath()); + assertThat( + recordedRequest.getBody().readUtf8(), + containsString( + "/ValueSet/test-vs-id/$expand?manifest=https://cts.nlm.nih.gov/fhir/Library/test-manifest-456")); } @Test @@ -158,28 +175,30 @@ void getValueSetResourceSuccessfully_when_ValueSetVersionIsProvided() .setBody(MOCK_RESPONSE_STRING) .addHeader("Content-Type", "application/fhir+json")); testValueSetParams.setVersion("test-value-set-version-2024"); + searchCriteria.setValueSetParams(List.of(testValueSetParams)); + when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); String actualResponse = - fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion()); + fhirTerminologyServiceWebClient.getValueSetResources(MOCK_API_KEY, searchCriteria); assertNotNull(actualResponse); assertEquals(MOCK_RESPONSE_STRING, actualResponse); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals( - "/ValueSet/test-vs-id/$expand?valueSetVersion=test-value-set-version-2024", - recordedRequest.getPath()); + assertThat( + recordedRequest.getBody().readUtf8(), + containsString("ValueSet/test-vs-id/$expand?valueSetVersion=test-value-set-version-2024")); } @Test void getValueSetResource_ReturnsException() throws InterruptedException { testValueSetParams.setVersion(""); mockBackEnd.enqueue(new MockResponse().setResponseCode(HttpStatus.UNAUTHORIZED.value())); + when(fhirContext.newJsonParser()).thenReturn(FhirContext.forR4().newJsonParser()); assertThrows( WebClientResponseException.class, - () -> - fhirTerminologyServiceWebClient.getValueSetResource( - MOCK_API_KEY, testValueSetParams, null, null, "false", new ManifestExpansion())); + () -> fhirTerminologyServiceWebClient.getValueSetResources(MOCK_API_KEY, searchCriteria)); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); - assertEquals("/ValueSet/test-vs-id/$expand?activeOnly=false", recordedRequest.getPath()); + assertThat( + recordedRequest.getBody().readUtf8(), + containsString("/ValueSet/test-vs-id/$expand?activeOnly=false")); } @Test