Add tests and tix for terminologyCapabilitiesQuick

This commit is contained in:
dotasek 2022-06-17 15:00:58 -04:00
parent 6ac813addd
commit 35fbd191ac
2 changed files with 52 additions and 13 deletions

View File

@ -171,7 +171,7 @@ public class FHIRToolingClient {
public TerminologyCapabilities getTerminologyCapabilities() {
TerminologyCapabilities capabilities = null;
capabilities = (TerminologyCapabilities) getCapabilities(resourceAddress.resolveMetadataTxCaps(),
capabilities = getCapabilities(resourceAddress.resolveMetadataTxCaps(),
"TerminologyCapabilities",
"Error fetching the server's terminology capabilities");
@ -181,7 +181,7 @@ public class FHIRToolingClient {
public CapabilityStatement getCapabilitiesStatement() {
CapabilityStatement capabilityStatement = null;
capabilityStatement = (CapabilityStatement) getCapabilities(resourceAddress.resolveMetadataUri(false),
capabilityStatement = getCapabilities(resourceAddress.resolveMetadataUri(false),
"CapabilitiesStatement", "Error fetching the server's conformance statement");
return capabilityStatement;
@ -189,15 +189,12 @@ public class FHIRToolingClient {
public CapabilityStatement getCapabilitiesStatementQuick() throws EFhirClientException {
if (capabilities != null) return capabilities;
try {
capabilities = (CapabilityStatement) client.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true),
getPreferredResourceFormat(),
generateHeaders(),
capabilities = getCapabilities(resourceAddress.resolveMetadataUri(true),
"CapabilitiesStatement-Quick",
TIMEOUT_NORMAL).getReference();
} catch (Exception e) {
throw new FHIRException("Error fetching the server's capability statement: "+e.getMessage(), e);
}
"Error fetching the server's capability statement");
return capabilities;
}

View File

@ -56,9 +56,6 @@ class FHIRToolingClientTest {
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
Mockito.any(Headers.class), Mockito.anyString(), Mockito.anyLong()))
.thenReturn(resourceResourceRequest);
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
Mockito.any(Headers.class), Mockito.eq("CapabilitiesStatement-Quick"), Mockito.anyLong()))
.thenReturn(new ResourceRequest<>(new CapabilityStatement(), 200, "location"));
//PUT
Mockito.when(mockClient.issuePutRequest(Mockito.any(URI.class), Mockito.any(byte[].class), Mockito.anyString(),
@ -248,6 +245,11 @@ class FHIRToolingClientTest {
@Test
void getCapabilitiesStatementQuick() throws IOException {
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
Mockito.any(Headers.class), Mockito.eq("CapabilitiesStatement-Quick"), Mockito.anyLong()))
.thenReturn(new ResourceRequest<>(new CapabilityStatement(), 200, "location"));
assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat());
ArgumentCaptor<Headers> headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class);
toolingClient.setClientHeaders(getHeaders());
toolingClient.getCapabilitiesStatementQuick();
@ -256,6 +258,46 @@ class FHIRToolingClientTest {
Headers argumentCaptorValue = headersArgumentCaptor.getValue();
checkHeaders(argumentCaptorValue);
assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat());
}
@Test
void getCapabilitiesStatementQuickFailsForJSON() throws IOException {
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
Mockito.any(Headers.class), Mockito.eq("CapabilitiesStatement-Quick"), Mockito.anyLong()))
.thenThrow(new FHIRFormatError("dummy error"))
.thenReturn(new ResourceRequest<>(new CapabilityStatement(), 200, "location"));
assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat());
ArgumentCaptor<Headers> headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class);
toolingClient.setClientHeaders(getHeaders());
toolingClient.getCapabilitiesStatementQuick();
Mockito.verify(mockClient, times(2)).issueGetResourceRequest(ArgumentMatchers.any(URI.class), ArgumentMatchers.anyString(),
headersArgumentCaptor.capture(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong());
Headers argumentCaptorValue = headersArgumentCaptor.getValue();
checkHeaders(argumentCaptorValue);
assertEquals(ResourceFormat.RESOURCE_XML.getHeader(), toolingClient.getPreferredResourceFormat());
}
@Test
void getCapabilitiesStatementQuickFailsForJSONandXML() throws IOException {
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
Mockito.any(Headers.class), Mockito.eq("CapabilitiesStatement-Quick"), Mockito.anyLong()))
.thenThrow(new FHIRFormatError("dummy error"))
.thenThrow(new FHIRFormatError("dummy error 2"));
ArgumentCaptor<Headers> headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class);
toolingClient.setClientHeaders(getHeaders());
assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat());
Exception exception = assertThrows(FHIRException.class, () -> {
toolingClient.getCapabilitiesStatementQuick();
});
assertEquals(ResourceFormat.RESOURCE_JSON.getHeader(), toolingClient.getPreferredResourceFormat());
}
@Test