Search in sources :

Example 26 with Context

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

the class TelemetryServiceTest method testTelemetryForServerSideSendNotificationNullResponse.

/**
 * Test case for calling sendNotifications() and getting an http timeout. In this case Delivery
 * API will return a null response body, and the SDK will throw a RuntimeException, and not
 * collect telemetry.
 *
 * @throws NoSuchFieldException
 */
@Test
void testTelemetryForServerSideSendNotificationNullResponse() throws NoSuchFieldException {
    setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotificationNullResponse");
    Mockito.lenient().doReturn(getNoContentDeliveryResponse()).when(defaultTargetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    Context context = getContext();
    List<Notification> notifications = new ArrayList<>();
    Notification notification = new Notification().id("12345").impressionId("12345").mbox(new NotificationMbox().name("test-mbox").state("11111")).type(MetricType.DISPLAY).timestamp(System.currentTimeMillis());
    notifications.add(notification);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).notifications(notifications).build();
    assertThrows(RuntimeException.class, () -> targetJavaClient.sendNotifications(targetDeliveryRequest));
    verify(telemetryServiceSpy, never()).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) NotificationMbox(com.adobe.target.delivery.v1.model.NotificationMbox) ArrayList(java.util.ArrayList) Notification(com.adobe.target.delivery.v1.model.Notification) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 27 with Context

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

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

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

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

the class NotificationService method buildNotifications.

public void buildNotifications(TargetDeliveryRequest targetDeliveryRequest, TargetDeliveryResponse targetDeliveryResponse, List<Notification> notifications) {
    boolean noNotifications = notifications == null || notifications.isEmpty();
    if (noNotifications) {
        return;
    }
    DeliveryRequest deliveryRequest = targetDeliveryRequest.getDeliveryRequest();
    setBeaconToFalse(deliveryRequest);
    String locationHint = targetDeliveryRequest.getLocationHint() != null ? targetDeliveryRequest.getLocationHint() : this.clusterLocator.getLocationHint();
    TargetDeliveryRequest notificationRequest = TargetDeliveryRequest.builder().locationHint(locationHint).sessionId(targetDeliveryRequest.getSessionId()).visitor(targetDeliveryRequest.getVisitor()).decisioningMethod(DecisioningMethod.SERVER_SIDE).requestId(UUID.randomUUID().toString()).impressionId(UUID.randomUUID().toString()).id(deliveryRequest.getId() != null ? deliveryRequest.getId() : targetDeliveryResponse.getResponse().getId()).experienceCloud(deliveryRequest.getExperienceCloud()).context(deliveryRequest.getContext()).environmentId(deliveryRequest.getEnvironmentId()).qaMode(deliveryRequest.getQaMode()).property(deliveryRequest.getProperty()).notifications(notifications).trace(deliveryRequest.getTrace()).build();
    this.sendNotification(notificationRequest);
}
Also used : DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest)

Aggregations

Context (com.adobe.target.delivery.v1.model.Context)24 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)22 Test (org.junit.jupiter.api.Test)19 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)18 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)17 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)14 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)13 TimingTool (com.adobe.target.edge.client.utils.TimingTool)12 Property (com.adobe.target.delivery.v1.model.Property)8 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)6 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)6 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 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)4 Test (org.junit.Test)4 Geo (com.adobe.target.delivery.v1.model.Geo)3 Notification (com.adobe.target.delivery.v1.model.Notification)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3