Refactor FhirReqestBuilderTests
This commit is contained in:
parent
e93b575021
commit
d374758f49
|
@ -5,6 +5,7 @@ import org.hl7.fhir.dstu3.formats.IParser;
|
||||||
|
|
||||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.AdditionalMatchers;
|
import org.mockito.AdditionalMatchers;
|
||||||
|
@ -54,55 +55,46 @@ public class FhirRequestBuilderTests {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeEach() {
|
public void beforeEach() {
|
||||||
Mockito.doReturn(client).when(fhirRequestBuilder).getHttpClient();
|
Mockito.doReturn(client).when(fhirRequestBuilder).getHttpClient();
|
||||||
|
fhirRequestBuilder.withLogger(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Nested
|
||||||
public void testExecuteLogging() throws IOException {
|
class RequestLoggingTests {
|
||||||
|
|
||||||
Mockito.doReturn(response).when(mockCall).execute();
|
@BeforeEach
|
||||||
Mockito.doReturn(mockCall).when(client).newCall(ArgumentMatchers.any());
|
public void beforeEach() throws IOException {
|
||||||
|
Mockito.doReturn(response).when(mockCall).execute();
|
||||||
|
Mockito.doReturn(mockCall).when(client).newCall(ArgumentMatchers.any());
|
||||||
|
|
||||||
Mockito.doReturn(null).when(fhirRequestBuilder).unmarshalReference(ArgumentMatchers.any(), ArgumentMatchers.isNull());
|
Mockito.doReturn(null).when(fhirRequestBuilder).unmarshalReference(ArgumentMatchers.any(), ArgumentMatchers.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
fhirRequestBuilder.withLogger(logger);
|
@Test
|
||||||
fhirRequestBuilder.execute();
|
public void testExecuteLogging() throws IOException {
|
||||||
|
fhirRequestBuilder.execute();
|
||||||
|
Mockito.verify(logger).logRequest(ArgumentMatchers.eq("GET"), ArgumentMatchers.eq(DUMMY_URL), ArgumentMatchers.anyList(), ArgumentMatchers.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
Mockito.verify(logger).logRequest(ArgumentMatchers.eq("GET"), ArgumentMatchers.eq(DUMMY_URL), ArgumentMatchers.anyList(), ArgumentMatchers.isNull());
|
@Test
|
||||||
}
|
public void testExecuteBatchLogging() throws IOException {
|
||||||
|
fhirRequestBuilder.executeAsBatch();
|
||||||
|
Mockito.verify(logger).logRequest(ArgumentMatchers.eq("GET"), ArgumentMatchers.eq(DUMMY_URL), ArgumentMatchers.anyList(), ArgumentMatchers.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testExecuteBatchLogging() throws IOException {
|
|
||||||
|
|
||||||
Mockito.doReturn(response).when(mockCall).execute();
|
|
||||||
Mockito.doReturn(mockCall).when(client).newCall(ArgumentMatchers.any());
|
|
||||||
|
|
||||||
Mockito.doReturn(null).when(fhirRequestBuilder).unmarshalFeed(ArgumentMatchers.any(), ArgumentMatchers.isNull());
|
|
||||||
|
|
||||||
fhirRequestBuilder.withLogger(logger);
|
|
||||||
fhirRequestBuilder.executeAsBatch();
|
|
||||||
|
|
||||||
Mockito.verify(logger).logRequest(ArgumentMatchers.eq("GET"), ArgumentMatchers.eq(DUMMY_URL), ArgumentMatchers.anyList(), ArgumentMatchers.isNull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshallReferenceLogging() {
|
public void testUnmarshallReferenceLogging() {
|
||||||
|
|
||||||
IParser parser = Mockito.mock(IParser.class);
|
IParser parser = Mockito.mock(IParser.class);
|
||||||
|
|
||||||
Mockito.doReturn(parser).when(fhirRequestBuilder).getParser(ArgumentMatchers.eq("json"));
|
Mockito.doReturn(parser).when(fhirRequestBuilder).getParser(ArgumentMatchers.eq("json"));
|
||||||
|
|
||||||
fhirRequestBuilder.withLogger(logger);
|
|
||||||
fhirRequestBuilder.unmarshalReference(response, "json");
|
fhirRequestBuilder.unmarshalReference(response, "json");
|
||||||
|
|
||||||
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
|
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshallFeedLogging() {
|
public void testUnmarshallFeedLogging() {
|
||||||
|
|
||||||
fhirRequestBuilder.withLogger(logger);
|
|
||||||
fhirRequestBuilder.unmarshalFeed(response, "application/json");
|
fhirRequestBuilder.unmarshalFeed(response, "application/json");
|
||||||
|
|
||||||
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
|
Mockito.verify(logger).logResponse(ArgumentMatchers.eq("200"), ArgumentMatchers.anyList(), AdditionalMatchers.aryEq(RESPONSE_BODY_STRING.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue