Search in sources :

Example 6 with PrefetchRequest

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

the class OnDeviceDecisioningEvaluatorTest method testLocalAndRemoteView.

@Test
public void testLocalAndRemoteView() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> views = new ArrayList<>();
    views.add("test");
    views.add("test2");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), views);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), views);
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertFalse(evaluation.isAllLocal());
    List<String> remoteViews = evaluation.getRemoteViews();
    remoteViews.sort(Comparator.naturalOrder());
    assertEquals(views, remoteViews);
    assertNull(evaluation.getRemoteMBoxes());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 7 with PrefetchRequest

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

the class OnDeviceDecisioningEvaluatorTest method testUnknownView.

@Test
public void testUnknownView() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> views = new ArrayList<>();
    views.add("test");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), views);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), new ArrayList<>());
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertFalse(evaluation.isAllLocal());
    List<String> remoteViews = new ArrayList<>();
    remoteViews.add("test2");
    assertEquals(remoteViews, evaluation.getRemoteViews());
    assertNull(evaluation.getRemoteMBoxes());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 8 with PrefetchRequest

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

the class OnDeviceDecisioningEvaluatorTest method testAllLocalNoRemoteView.

@Test
public void testAllLocalNoRemoteView() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> localViews = new ArrayList<>();
    localViews.add("test");
    localViews.add("test2");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), localViews);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), new ArrayList<String>());
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertTrue(evaluation.isAllLocal());
    assertNull(evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 9 with PrefetchRequest

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

the class DefaultTargetServiceTest method getDeliveryRequest.

private TargetDeliveryRequest getDeliveryRequest() {
    Context context = getLocalContext();
    PrefetchRequest prefetchRequest = getMboxPrefetchLocalRequest("testoffer");
    ExecuteRequest executeRequest = getMboxExecuteLocalRequest("testoffer2");
    VisitorId visitorId = new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916873");
    Notification notification = new Notification();
    notification.setId(UUID.randomUUID().toString());
    notification.setImpressionId(UUID.randomUUID().toString());
    notification.setType(MetricType.DISPLAY);
    notification.setTimestamp(System.currentTimeMillis());
    notification.setTokens(Collections.singletonList("IbG2Jz2xmHaqX7Ml/YRxRGqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="));
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).id(visitorId).notifications(Collections.singletonList(notification)).build();
    return targetDeliveryRequest;
}
Also used : TargetTestDeliveryRequestUtils.getLocalContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getLocalContext) Context(com.adobe.target.delivery.v1.model.Context) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) VisitorId(com.adobe.target.delivery.v1.model.VisitorId) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Notification(com.adobe.target.delivery.v1.model.Notification)

Example 10 with PrefetchRequest

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

the class TelemetryServiceTest method testTelemetryForServerSide.

/**
 * Test case to call get offers for server side, in first request we capture the telemetry & in
 * next call we send it with any getOffers() call or sendNotifications() call
 *
 * @throws NoSuchFieldException
 */
@Test
void testTelemetryForServerSide() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSide");
    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());
    // In next call we see telemetry data added to the deliveryRequest
    TargetDeliveryResponse targetDeliveryResponse2 = targetJavaClient.getOffers(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());
    assertNotNull(targetDeliveryResponse2);
    assertNotNull(targetDeliveryResponse2.getRequest());
    assertNotNull(targetDeliveryResponse2.getRequest().getTelemetry());
    assertEquals(1, targetDeliveryResponse2.getRequest().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)

Aggregations

PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)24 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)20 Test (org.junit.jupiter.api.Test)18 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)15 Context (com.adobe.target.delivery.v1.model.Context)14 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)13 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)12 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)9 TimingTool (com.adobe.target.edge.client.utils.TimingTool)8 Property (com.adobe.target.delivery.v1.model.Property)7 ArrayList (java.util.ArrayList)7 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)6 ViewRequest (com.adobe.target.delivery.v1.model.ViewRequest)6 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)5 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)5 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)5 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)5 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)5 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)5 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)4