Search in sources :

Example 26 with ExecuteRequest

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

the class TelemetryServiceTest method testTelemetryNotSentExecute.

/**
 * When telemetryEnabled flag is set to false verify we don't store telemetry data
 *
 * @throws NoSuchFieldException
 * @throws IOException
 */
@Test
void testTelemetryNotSentExecute() throws NoSuchFieldException, IOException {
    setup(false, DecisioningMethod.ON_DEVICE, "testTelemetryNotSentExecute");
    TargetService targetServiceMock = mock(TargetService.class, RETURNS_DEFAULTS);
    NotificationService notificationService = new NotificationService(targetServiceMock, clientConfig, clusterLocator);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), notificationService);
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().index(0).name("TEST_PREFETCH"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
    targetJavaClient.getOffers(targetDeliveryRequest);
    ArgumentCaptor<TargetDeliveryRequest> captor = ArgumentCaptor.forClass(TargetDeliveryRequest.class);
    verify(targetServiceMock, timeout(1000)).executeNotificationAsync(captor.capture());
    Telemetry telemetry = captor.getValue().getDeliveryRequest().getTelemetry();
    List<Notification> notifications = captor.getValue().getDeliveryRequest().getNotifications();
    assertNull(telemetry);
    assertEquals(notifications.size(), 1);
}
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) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Notification(com.adobe.target.delivery.v1.model.Notification) Test(org.junit.jupiter.api.Test)

Example 27 with ExecuteRequest

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

the class OnDeviceDecisioningEvaluatorTest method testAllLocalNoRemoteMbox.

@Test
public void testAllLocalNoRemoteMbox() throws JsonProcessingException, NoSuchFieldException {
    OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
    List<String> localMboxes = new ArrayList<>();
    localMboxes.add("test");
    localMboxes.add("test2");
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localMboxes"), localMboxes);
    FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteMboxes"), new ArrayList<String>());
    String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
    evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().addMboxesItem(new MboxRequest().name("test")).addMboxesItem(new MboxRequest().name("test2"))).build();
    OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
    assertTrue(evaluation.isAllLocal());
    assertNull(evaluation.getRemoteMBoxes());
    assertNull(evaluation.getRemoteViews());
}
Also used : ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) 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 28 with ExecuteRequest

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

the class PageParamsCollatorTest method testCollator.

@Test
public void testCollator() {
    VisitorProvider.init("testOrgId");
    String url = "http://WWW.TARGET.ADOBE.COM/ABOUT/?foo=bar&name=JimmyG#Part1";
    RequestDetails pageLoad = new RequestDetails();
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).context(new Context().address(new Address().url(url))).build();
    PageParamsCollator collator = new PageParamsCollator();
    Map<String, Object> result = collator.collateParams(request, pageLoad);
    assertEquals(url, result.get(PageParamsCollator.PAGE_URL));
    assertEquals(url.toLowerCase(), result.get(PageParamsCollator.PAGE_URL_LOWER));
    assertEquals("/ABOUT/", result.get(PageParamsCollator.PAGE_PATH));
    assertEquals("/about/", result.get(PageParamsCollator.PAGE_PATH_LOWER));
    assertEquals("WWW.TARGET.ADOBE.COM", result.get(PageParamsCollator.PAGE_DOMAIN));
    assertEquals("www.target.adobe.com", result.get(PageParamsCollator.PAGE_DOMAIN_LOWER));
    assertEquals("TARGET", result.get(PageParamsCollator.PAGE_SUBDOMAIN));
    assertEquals("target", result.get(PageParamsCollator.PAGE_SUBDOMAIN_LOWER));
    assertEquals("COM", result.get(PageParamsCollator.PAGE_TOP_LEVEL_DOMAIN));
    assertEquals("com", result.get(PageParamsCollator.PAGE_TOP_LEVEL_DOMAIN_LOWER));
    assertEquals("foo=bar&name=JimmyG", result.get(PageParamsCollator.PAGE_QUERY));
    assertEquals("foo=bar&name=jimmyg", result.get(PageParamsCollator.PAGE_QUERY_LOWER));
    assertEquals("Part1", result.get(PageParamsCollator.PAGE_FRAGMENT));
    assertEquals("part1", result.get(PageParamsCollator.PAGE_FRAGMENT_LOWER));
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) Address(com.adobe.target.delivery.v1.model.Address) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails) Test(org.junit.jupiter.api.Test)

Example 29 with ExecuteRequest

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

the class ClusterLocator method executeRequest.

private void executeRequest(final TargetService targetService) {
    TargetDeliveryRequest request = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).build();
    future = targetService.executeRequestAsync(request);
    future.thenAcceptAsync(response -> {
        if (!this.running) {
            return;
        }
        if (response != null && response.getStatus() == SC_OK && response.getResponse() != null && response.getResponse().getId() != null && response.getResponse().getId().getTntId() != null) {
            String tntId = response.getResponse().getId().getTntId();
            this.locationHint = CookieUtils.locationHintFromTntId(tntId);
        } else if (retries++ < MAX_RETRIES) {
            this.timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    executeRequest(targetService);
                }
            }, retries * 10000);
        }
    });
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TimerTask(java.util.TimerTask) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest)

Example 30 with ExecuteRequest

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

ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)27 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)26 Test (org.junit.jupiter.api.Test)22 Context (com.adobe.target.delivery.v1.model.Context)19 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)15 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)15 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)14 TimingTool (com.adobe.target.edge.client.utils.TimingTool)13 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)10 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)8 Property (com.adobe.target.delivery.v1.model.Property)8 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)6 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)5 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)5 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)4 ArrayList (java.util.ArrayList)4 Notification (com.adobe.target.delivery.v1.model.Notification)3