Search in sources :

Example 1 with MockRawResponse

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());
}
Also used : DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) HashMap(java.util.HashMap) Function(java.util.function.Function) UnirestInstance(kong.unirest.UnirestInstance) MockRawResponse(com.adobe.target.edge.client.utils.MockRawResponse) ClientConfig(com.adobe.target.edge.client.ClientConfig) MockRawResponse(com.adobe.target.edge.client.utils.MockRawResponse) RawResponse(kong.unirest.RawResponse) Test(org.junit.jupiter.api.Test)

Aggregations

DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 ClientConfig (com.adobe.target.edge.client.ClientConfig)1 MockRawResponse (com.adobe.target.edge.client.utils.MockRawResponse)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 RawResponse (kong.unirest.RawResponse)1 UnirestInstance (kong.unirest.UnirestInstance)1 Test (org.junit.jupiter.api.Test)1