Add tests and fix for terminologyCapabilities
This commit is contained in:
parent
093904abb1
commit
6ac813addd
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue