use of com.adobe.target.delivery.v1.model.Telemetry in project target-java-sdk by adobe.
the class TelemetryServiceTest method testExecutionModeForServerSide.
@Test
void testExecutionModeForServerSide() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testExecutionModeServerSide");
TimingTool timer = new TimingTool();
timer.timeStart(TIMING_EXECUTE_REQUEST);
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
DeliveryResponse deliveryResponse = new DeliveryResponse();
deliveryResponse.setClient("SUMMIT_TEST2021");
deliveryResponse.setEdgeHost("mboxedge35.tt.omtrdc.net");
TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
targetDeliveryResponse.getResponse().setRequestId("testID");
telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
Telemetry telemetry = telemetryServiceSpy.getTelemetry();
assertEquals(ExecutionMode.EDGE, telemetry.getEntries().get(0).getMode());
}
use of com.adobe.target.delivery.v1.model.Telemetry in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForServerSideSendNotification.
/**
* Test case for server-side decisioning that calls getOffers() once and then sendNotifications()
* once. This is to verify (and document the use case) telemetry is being added to any request
* that goes to Delivery API, regardless of which method is being called on TargetClient by the
* user.
*
* @throws NoSuchFieldException
*/
@Test
void testTelemetryForServerSideSendNotification() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotification");
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
String nonDefaultToken = "non-default-token";
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
TargetDeliveryResponse targetDeliveryResponse1 = targetJavaClient.getOffers(targetDeliveryRequest);
assertNull(targetDeliveryResponse1.getRequest().getTelemetry());
targetJavaClient.sendNotifications(targetDeliveryRequest);
verify(telemetryServiceSpy, atLeast(2)).getTelemetry();
verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
assertEquals(1, telemetryServiceSpy.getTelemetry().getEntries().size());
}
use of com.adobe.target.delivery.v1.model.Telemetry in project target-java-sdk by adobe.
the class DefaultTargetServiceTest method getMockedTelemetry.
private void getMockedTelemetry() {
Telemetry telemetryMock = new Telemetry();
TelemetryEntry telemetryEntryMock = new TelemetryEntry();
telemetryEntryMock.setRequestId("test123");
telemetryEntryMock.setTimestamp(System.currentTimeMillis());
telemetryMock.addEntriesItem(telemetryEntryMock);
Mockito.lenient().when(telemetryService.getTelemetry()).thenReturn(telemetryMock);
}
use of com.adobe.target.delivery.v1.model.Telemetry 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");
}
use of com.adobe.target.delivery.v1.model.Telemetry in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetrySentOnExecute.
/**
* Check telemetryEntry in execute call
*
* @throws NoSuchFieldException
* @throws IOException
*/
@Test
void testTelemetrySentOnExecute() throws NoSuchFieldException, IOException {
setup(true, DecisioningMethod.ON_DEVICE, "testTelemetrySentOnExecute");
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);
ArgumentCaptor<TargetDeliveryRequest> captor = ArgumentCaptor.forClass(TargetDeliveryRequest.class);
verify(targetServiceMock, timeout(1000)).executeNotificationAsync(captor.capture());
Telemetry telemetry = telemetryServiceSpy.getTelemetry();
assertNotNull(telemetry);
assertEquals(telemetry.getEntries().size(), 2);
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