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