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));
}
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);
}
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));
}
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);
}
});
}
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);
}
Aggregations