Search in sources :

Example 51 with TargetDeliveryRequest

use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.

the class TelemetryServiceTest method testExecutionModeForServerSide.

@Test
void testExecutionModeForServerSide() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testExecutionModeServerSide");
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    Context context = getContext();
    PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
    ExecuteRequest executeRequest = getMboxExecuteRequest();
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
    DeliveryResponse deliveryResponse = new DeliveryResponse();
    deliveryResponse.setClient("SUMMIT_TEST2021");
    deliveryResponse.setEdgeHost("mboxedge35.tt.omtrdc.net");
    TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
    targetDeliveryResponse.getResponse().setRequestId("testID");
    telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
    Telemetry telemetry = telemetryServiceSpy.getTelemetry();
    assertEquals(ExecutionMode.EDGE, telemetry.getEntries().get(0).getMode());
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) TargetTestDeliveryRequestUtils.getTestDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Test(org.junit.jupiter.api.Test)

Example 52 with TargetDeliveryRequest

use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.

the class TelemetryServiceTest method testExecutionModeForHybridWithNotAllLocal.

/**
 * Test to verify telemetryEntry has correct executionMode For hybrid & status 200 we should have
 * mode as local
 *
 * @throws NoSuchFieldException
 */
@Test
void testExecutionModeForHybridWithNotAllLocal() throws NoSuchFieldException {
    setup(true, DecisioningMethod.HYBRID, "testExecutionModeHybridWithNotALlLocal");
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    Context context = getContext();
    PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
    ExecuteRequest executeRequest = getMboxExecuteRequest();
    String nonDefaultToken = "non-default-token";
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.HYBRID).build();
    DeliveryResponse deliveryResponse = new DeliveryResponse();
    deliveryResponse.setClient("SUMMIT_TEST2021");
    deliveryResponse.setEdgeHost("mboxedge35.tt.omtrdc.net");
    TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
    targetDeliveryResponse.getResponse().setRequestId("testID");
    telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
    TelemetryEntry telemetryEntry = telemetryServiceSpy.getTelemetry().getEntries().get(1);
    assert telemetryEntry != null;
    assertEquals(ExecutionMode.EDGE, telemetryEntry.getMode());
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) TargetTestDeliveryRequestUtils.getTestDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse) Property(com.adobe.target.delivery.v1.model.Property) Test(org.junit.jupiter.api.Test)

Example 53 with TargetDeliveryRequest

use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetryForServerSideSendNotification.

/**
 * Test case for server-side decisioning that calls getOffers() once and then sendNotifications()
 * once. This is to verify (and document the use case) telemetry is being added to any request
 * that goes to Delivery API, regardless of which method is being called on TargetClient by the
 * user.
 *
 * @throws NoSuchFieldException
 */
@Test
void testTelemetryForServerSideSendNotification() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotification");
    Context context = getContext();
    PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
    ExecuteRequest executeRequest = getMboxExecuteRequest();
    String nonDefaultToken = "non-default-token";
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
    TargetDeliveryResponse targetDeliveryResponse1 = targetJavaClient.getOffers(targetDeliveryRequest);
    assertNull(targetDeliveryResponse1.getRequest().getTelemetry());
    targetJavaClient.sendNotifications(targetDeliveryRequest);
    verify(telemetryServiceSpy, atLeast(2)).getTelemetry();
    verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
    assertEquals(1, telemetryServiceSpy.getTelemetry().getEntries().size());
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Property(com.adobe.target.delivery.v1.model.Property) Test(org.junit.jupiter.api.Test)

Example 54 with TargetDeliveryRequest

use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.

the class TelemetryServiceTest method testExecutionModeForHybridWithAllLocal.

/**
 * Test to verify telemetryEntry has correct executionMode With partial content 206 status &
 * hybrid our mode should be edge
 *
 * @throws NoSuchFieldException
 */
@Test
void testExecutionModeForHybridWithAllLocal() throws NoSuchFieldException {
    setup(true, DecisioningMethod.HYBRID, "testExecutionModeHybridWithAllLocal");
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    Context context = getContext();
    ExecuteRequest executeRequest = getMboxExecuteRequest();
    String nonDefaultToken = "non-default-token";
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.HYBRID).build();
    DeliveryResponse deliveryResponse = new DeliveryResponse();
    deliveryResponse.setClient("SUMMIT_TEST2021");
    deliveryResponse.setEdgeHost(null);
    TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
    targetDeliveryResponse.getResponse().setRequestId("testID");
    telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
    TelemetryEntry telemetryEntry = telemetryServiceSpy.getTelemetry().getEntries().get(1);
    assert telemetryEntry != null;
    assertEquals(ExecutionMode.LOCAL, telemetryEntry.getMode());
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) TargetTestDeliveryRequestUtils.getTestDeliveryResponse(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse) Property(com.adobe.target.delivery.v1.model.Property) Test(org.junit.jupiter.api.Test)

Example 55 with TargetDeliveryRequest

use of com.adobe.target.edge.client.model.TargetDeliveryRequest 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)

Aggregations

TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)104 Test (org.junit.jupiter.api.Test)89 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)62 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)24 Context (com.adobe.target.delivery.v1.model.Context)21 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)20 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)17 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)13 TimingTool (com.adobe.target.edge.client.utils.TimingTool)13 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)11 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)10 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Property (com.adobe.target.delivery.v1.model.Property)9 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)9 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)9 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6