Add tests and tix for terminologyCapabilitiesQuick
This commit is contained in:
parent
6ac813addd
commit
35fbd191ac
|
@ -171,7 +171,7 @@ public class FHIRToolingClient {
|
||||||
public TerminologyCapabilities getTerminologyCapabilities() {
|
public TerminologyCapabilities getTerminologyCapabilities() {
|
||||||
TerminologyCapabilities capabilities = null;
|
TerminologyCapabilities capabilities = null;
|
||||||
|
|
||||||
capabilities = (TerminologyCapabilities) getCapabilities(resourceAddress.resolveMetadataTxCaps(),
|
capabilities = getCapabilities(resourceAddress.resolveMetadataTxCaps(),
|
||||||
"TerminologyCapabilities",
|
"TerminologyCapabilities",
|
||||||
"Error fetching the server's terminology capabilities");
|
"Error fetching the server's terminology capabilities");
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ public class FHIRToolingClient {
|
||||||
public CapabilityStatement getCapabilitiesStatement() {
|
public CapabilityStatement getCapabilitiesStatement() {
|
||||||
CapabilityStatement capabilityStatement = null;
|
CapabilityStatement capabilityStatement = null;
|
||||||
|
|
||||||
capabilityStatement = (CapabilityStatement) getCapabilities(resourceAddress.resolveMetadataUri(false),
|
capabilityStatement = getCapabilities(resourceAddress.resolveMetadataUri(false),
|
||||||
|
|
||||||
"CapabilitiesStatement", "Error fetching the server's conformance statement");
|
"CapabilitiesStatement", "Error fetching the server's conformance statement");
|
||||||
return capabilityStatement;
|
return capabilityStatement;
|
||||||
|
@ -189,15 +189,12 @@ public class FHIRToolingClient {
|
||||||
|
|
||||||
public CapabilityStatement getCapabilitiesStatementQuick() throws EFhirClientException {
|
public CapabilityStatement getCapabilitiesStatementQuick() throws EFhirClientException {
|
||||||
if (capabilities != null) return capabilities;
|
if (capabilities != null) return capabilities;
|
||||||
try {
|
|
||||||
capabilities = (CapabilityStatement) client.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true),
|
capabilities = getCapabilities(resourceAddress.resolveMetadataUri(true),
|
||||||
getPreferredResourceFormat(),
|
|
||||||
generateHeaders(),
|
|
||||||
"CapabilitiesStatement-Quick",
|
"CapabilitiesStatement-Quick",
|
||||||
TIMEOUT_NORMAL).getReference();
|
"Error fetching the server's capability statement");
|
||||||
} catch (Exception e) {
|
|
||||||
throw new FHIRException("Error fetching the server's capability statement: "+e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return capabilities;
|
return capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,6 @@ class FHIRToolingClientTest {
|
||||||
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
|
Mockito.when(mockClient.issueGetResourceRequest(Mockito.any(URI.class), Mockito.anyString(),
|
||||||
Mockito.any(Headers.class), Mockito.anyString(), Mockito.anyLong()))
|
Mockito.any(Headers.class), Mockito.anyString(), Mockito.anyLong()))
|
||||||
.thenReturn(resourceResourceRequest);
|
.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
|
//PUT
|
||||||
Mockito.when(mockClient.issuePutRequest(Mockito.any(URI.class), Mockito.any(byte[].class), Mockito.anyString(),
|
Mockito.when(mockClient.issuePutRequest(Mockito.any(URI.class), Mockito.any(byte[].class), Mockito.anyString(),
|
||||||
|
@ -248,6 +245,11 @@ class FHIRToolingClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getCapabilitiesStatementQuick() throws IOException {
|
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);
|
ArgumentCaptor<Headers> headersArgumentCaptor = ArgumentCaptor.forClass(Headers.class);
|
||||||
toolingClient.setClientHeaders(getHeaders());
|
toolingClient.setClientHeaders(getHeaders());
|
||||||
toolingClient.getCapabilitiesStatementQuick();
|
toolingClient.getCapabilitiesStatementQuick();
|
||||||
|
@ -256,6 +258,46 @@ class FHIRToolingClientTest {
|
||||||
|
|
||||||
Headers argumentCaptorValue = headersArgumentCaptor.getValue();
|
Headers argumentCaptorValue = headersArgumentCaptor.getValue();
|
||||||
checkHeaders(argumentCaptorValue);
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue