Add tests and fix for terminologyCapabilities

This commit is contained in:
dotasek 2022-06-17 11:21:11 -04:00
parent 093904abb1
commit 6ac813addd
2 changed files with 34 additions and 8 deletions

View File

@ -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;
}

View File

@ -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<Headers> 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<Headers> 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(),