use of com.adobe.target.edge.client.utils.MockRawResponse in project target-java-sdk by adobe.
the class DefaultTargetHttpClientTest method testExecute.
@Test
void testExecute() throws NoSuchFieldException {
ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).telemetryEnabled(false).build();
DefaultTargetHttpClient defaultTargetHttpClient = new DefaultTargetHttpClient(clientConfig);
UnirestInstance unirestInstance = Mockito.mock(UnirestInstance.class, Mockito.RETURNS_DEEP_STUBS);
FieldSetter.setField(defaultTargetHttpClient, defaultTargetHttpClient.getClass().getDeclaredField("unirestInstance"), unirestInstance);
Map<String, Object> queryParams = new HashMap<>();
String url = "/url";
DeliveryRequest deliveryRequest = new DeliveryRequest();
HttpResponse<Object> mockHttpResponse = Mockito.mock(HttpResponse.class);
when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObject(ArgumentMatchers.<Function<RawResponse, Object>>any())).thenAnswer(invocation -> {
RawResponse rawResponse = TargetTestDeliveryRequestUtils.getRawTestResponse(HttpStatus.SC_OK);
Function<RawResponse, Object> function = (Function<RawResponse, Object>) invocation.getArguments()[0];
function.apply(rawResponse);
return mockHttpResponse;
});
ResponseWrapper<MockRawResponse> responseWrapper = defaultTargetHttpClient.execute(queryParams, url, deliveryRequest, MockRawResponse.class);
assertNotNull(responseWrapper);
assertEquals(mockHttpResponse, responseWrapper.getHttpResponse());
}
Aggregations