Search in sources :

Example 16 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.

the class DefaultTargetServiceTest method testExecuteNotificationWithBeaconNull.

/**
 * If a user sends a notifications request with Context.beacon = null, we should set it to false
 * to avoid NPE. Beacon does not make sense to use with a server-side SDK.
 */
@Test
public void testExecuteNotificationWithBeaconNull() {
    ResponseWrapper<DeliveryResponse> mockedResponseWrapper = getTestDeliveryResponse();
    getMockedTelemetry();
    Mockito.lenient().doReturn(mockedResponseWrapper).when(targetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    TargetDeliveryRequest targetDeliveryRequestMock = getDeliveryRequest();
    targetDeliveryRequestMock.getDeliveryRequest().getContext().setBeacon(null);
    targetService.executeNotification(targetDeliveryRequestMock);
    ArgumentCaptor<DeliveryRequest> captor = ArgumentCaptor.forClass(DeliveryRequest.class);
    verify(targetHttpClient, times(1)).execute(any(Map.class), any(String.class), captor.capture(), any(Class.class));
    assertFalse(captor.getValue().getContext().getBeacon());
}
Also used : TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TargetTestDeliveryRequestUtils.getTestDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 17 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.

the class DefaultTargetServiceTest method testExecuteNotificationWithBeaconTrue.

/**
 * If a user sends a notifications request with Context.beacon = true, we should always set it to
 * false for them. Beacon does not make sense to use with a server-side SDK.
 */
@Test
public void testExecuteNotificationWithBeaconTrue() {
    ResponseWrapper<DeliveryResponse> mockedResponseWrapper = getTestDeliveryResponse();
    getMockedTelemetry();
    Mockito.lenient().doReturn(mockedResponseWrapper).when(targetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    TargetDeliveryRequest targetDeliveryRequestMock = getDeliveryRequest();
    targetDeliveryRequestMock.getDeliveryRequest().getContext().setBeacon(true);
    targetService.executeNotification(targetDeliveryRequestMock);
    ArgumentCaptor<DeliveryRequest> captor = ArgumentCaptor.forClass(DeliveryRequest.class);
    verify(targetHttpClient, times(1)).execute(any(Map.class), any(String.class), captor.capture(), any(Class.class));
    assertFalse(captor.getValue().getContext().getBeacon());
}
Also used : TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TargetTestDeliveryRequestUtils.getTestDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 18 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest 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)

Example 19 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method getOrCreateVisitorId.

private String getOrCreateVisitorId(TargetDeliveryRequest deliveryRequest, TargetDeliveryResponse targetResponse) {
    String vid = null;
    VisitorId visitorId = deliveryRequest.getDeliveryRequest().getId();
    if (visitorId != null) {
        vid = StringUtils.firstNonBlank(visitorId.getMarketingCloudVisitorId(), removeLocationHint(visitorId.getTntId()), visitorId.getThirdPartyId());
    }
    // set our own tntId there in an earlier call
    if (vid == null && targetResponse.getResponse().getId() != null) {
        vid = removeLocationHint(targetResponse.getResponse().getId().getTntId());
    }
    if (vid != null) {
        return vid;
    }
    // If vid still null, create new tntId and use that and set it in the response
    String newTntId = generateTntId();
    if (visitorId == null) {
        visitorId = new VisitorId().tntId(newTntId);
    } else {
        visitorId.setTntId(newTntId);
    }
    targetResponse.getResponse().setId(visitorId);
    return removeLocationHint(newTntId);
}
Also used : VisitorId(com.adobe.target.delivery.v1.model.VisitorId)

Example 20 with DeliveryRequest

use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.

the class DefaultTargetService method executeRequest.

@Override
public TargetDeliveryResponse executeRequest(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    TargetDeliveryResponse targetDeliveryResponse;
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    ResponseWrapper<DeliveryResponse> response = callDeliveryApi(deliveryRequest);
    targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
    /* capture Telemetry information once original request's response is received */
    telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
    return targetDeliveryResponse;
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse)

Aggregations

DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)8 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)8 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)6 TimingTool (com.adobe.target.edge.client.utils.TimingTool)6 Test (org.junit.jupiter.api.Test)5 Context (com.adobe.target.delivery.v1.model.Context)4 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)4 HashMap (java.util.HashMap)4 ResponseStatus (com.adobe.target.edge.client.http.ResponseStatus)3 ResponseWrapper (com.adobe.target.edge.client.http.ResponseWrapper)3 Map (java.util.Map)3 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)2 Geo (com.adobe.target.delivery.v1.model.Geo)2 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)2 Property (com.adobe.target.delivery.v1.model.Property)2 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)2 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)2 ClientConfig (com.adobe.target.edge.client.ClientConfig)2 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)2