From 6ac813addd565765bdb6d20835773661d0ebad6e Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 17 Jun 2022 11:21:11 -0400 Subject: [PATCH] Add tests and fix for terminologyCapabilities --- .../r5/utils/client/FHIRToolingClient.java | 12 +++----- .../utils/client/FHIRToolingClientTest.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java index f638c9a9b..2713477e7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java @@ -170,15 +170,11 @@ public class FHIRToolingClient { public TerminologyCapabilities getTerminologyCapabilities() { TerminologyCapabilities capabilities = null; - try { - capabilities = (TerminologyCapabilities) client.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), - getPreferredResourceFormat(), - generateHeaders(), + + capabilities = (TerminologyCapabilities) getCapabilities(resourceAddress.resolveMetadataTxCaps(), "TerminologyCapabilities", - TIMEOUT_NORMAL).getReference(); - } catch (Exception e) { - throw new FHIRException("Error fetching the server's terminology capabilities", e); - } + "Error fetching the server's terminology capabilities"); + return capabilities; } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java index 8b78a92c6..d642aa9a1 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/client/FHIRToolingClientTest.java @@ -165,6 +165,36 @@ class FHIRToolingClientTest { checkHeaders(argumentCaptorValue); } + @Test + void getTerminologyCapabilitiesFailsForJSON() throws IOException { + Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(), + Mockito.any(Headers.class), Mockito.eq("TerminologyCapabilities"), Mockito.anyLong())) + .thenThrow(new FHIRFormatError("dummy error")) + .thenReturn(new ResourceRequest<>(new TerminologyCapabilities(), 200, "location")); + + ArgumentCaptor headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class); + toolingClient.setClientHeaders(getHeaders()); + toolingClient.getTerminologyCapabilities(); + Mockito.verify(mockClient, times(2)).issueGetResourceRequest(ArgumentMatchers.any(URI.class), ArgumentMatchers.anyString(), + headersArgumentCaptor.capture(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong()); + + Headers argumentCaptorValue = headersArgumentCaptor.getValue(); + checkHeaders(argumentCaptorValue); + } + + @Test + void getTerminologyCapabilitiesStatementFailsForJSONandXML() throws IOException { + Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(), + Mockito.any(Headers.class), Mockito.eq("TerminologyCapabilities"), Mockito.anyLong())) + .thenThrow(new FHIRFormatError("dummy error")) + .thenThrow(new FHIRFormatError("dummy error 2")); + assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat()); + toolingClient.setClientHeaders(getHeaders()); + Exception exception = assertThrows(FHIRException.class, () -> { ArgumentCaptor headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class); + toolingClient.getTerminologyCapabilities(); }); + assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat()); + } + @Test void getCapabilitiesStatement() throws IOException { Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),