use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetServiceTest method testExecuteNotificationWithBeaconTrue.
/**
* If a user sends a notifications request with Context.beacon = true, we should always set it to
* false for them. Beacon does not make sense to use with a server-side SDK.
*/
@Test
public void testExecuteNotificationWithBeaconTrue() {
ResponseWrapper<DeliveryResponse> mockedResponseWrapper = getTestDeliveryResponse();
getMockedTelemetry();
Mockito.lenient().doReturn(mockedResponseWrapper).when(targetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
TargetDeliveryRequest targetDeliveryRequestMock = getDeliveryRequest();
targetDeliveryRequestMock.getDeliveryRequest().getContext().setBeacon(true);
targetService.executeNotification(targetDeliveryRequestMock);
ArgumentCaptor<DeliveryRequest> captor = ArgumentCaptor.forClass(DeliveryRequest.class);
verify(targetHttpClient, times(1)).execute(any(Map.class), any(String.class), captor.capture(), any(Class.class));
assertFalse(captor.getValue().getContext().getBeacon());
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class NotificationServiceTest method testNotificationDeliveryServiceCalled.
@Test
void testNotificationDeliveryServiceCalled() throws NoSuchFieldException, IOException {
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"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
targetJavaClient.getOffers(targetDeliveryRequest);
verify(targetServiceMock, timeout(1000)).executeNotificationAsync(any());
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class NotificationServiceTest method localDeliveryRequest.
private TargetDeliveryRequest localDeliveryRequest() {
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();
assertEquals(prefetchRequest, targetDeliveryRequest.getDeliveryRequest().getPrefetch());
assertEquals(executeRequest, targetDeliveryRequest.getDeliveryRequest().getExecute());
assertEquals(context, targetDeliveryRequest.getDeliveryRequest().getContext());
return targetDeliveryRequest;
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForHybrid.
/**
* This test is executed on-device for this Hybrid request.
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetryForHybrid() throws NoSuchFieldException, IOException {
setup(true, DecisioningMethod.HYBRID, "testTelemetryForHybrid");
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"))).decisioningMethod(DecisioningMethod.HYBRID).build();
targetJavaClient.getOffers(targetDeliveryRequest);
verify(telemetryServiceSpy, times(2)).getTelemetry();
verify(telemetryServiceSpy, times(1)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class));
verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
}
use of com.adobe.target.edge.client.model.TargetDeliveryRequest in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetrySentOnPrefetch.
/**
* Check telemetryEntry in prefetch call
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetrySentOnPrefetch() throws NoSuchFieldException, IOException {
setup(true, DecisioningMethod.ON_DEVICE, "testTelemetrySentOnPrefetch");
long timestamp = System.currentTimeMillis();
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);
Telemetry telemetry = telemetryServiceSpy.getTelemetry();
assertNotNull(telemetry);
TelemetryEntry telemetryEntry = telemetry.getEntries().get(1);
assertTrue(telemetryEntry.getTimestamp() > timestamp);
assertTrue(telemetryEntry.getExecution() > 0);
assertTrue(telemetryEntry.getRequestId().length() > 0);
assertEquals(telemetryEntry.getFeatures().getDecisioningMethod(), "on-device");
}
Aggregations