use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class TelemetryService method addTelemetry.
public void addTelemetry(TargetDeliveryRequest deliveryRequest, TimingTool timer, TargetDeliveryResponse targetDeliveryResponse, double parsingTime, long responseSize) {
TelemetryEntry telemetryEntry = createTelemetryEntry(deliveryRequest, targetDeliveryResponse, timer.timeEnd(TIMING_EXECUTE_REQUEST));
if (telemetryEntry == null) {
return;
}
telemetryEntry.setParsing(parsingTime);
TelemetryRequest telemetryRequest = new TelemetryRequest();
telemetryRequest.setResponseSize(responseSize);
telemetryEntry.setRequest(telemetryRequest);
storedTelemetries.add(telemetryEntry);
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetClient method updatePropertyToken.
private void updatePropertyToken(TargetDeliveryRequest targetRequest) {
if (StringUtils.isEmpty(this.defaultPropertyToken)) {
return;
}
DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
Property property = deliveryRequest.getProperty();
if (property != null && property.getToken() != null) {
return;
}
if (property == null) {
property = new Property();
deliveryRequest.setProperty(property);
}
property.setToken(this.defaultPropertyToken);
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetClient method addMBoxesToRequest.
private static TargetDeliveryRequest addMBoxesToRequest(TargetDeliveryRequest targetRequest, String... mboxes) {
if (targetRequest == null || targetRequest.getDeliveryRequest() == null) {
targetRequest = TargetDeliveryRequest.builder().decisioningMethod(DecisioningMethod.HYBRID).build();
}
int idx = 0;
Set<String> existingMBoxNames = new HashSet<>();
DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
PrefetchRequest prefetchRequest = deliveryRequest.getPrefetch();
if (prefetchRequest != null && prefetchRequest.getMboxes() != null) {
for (MboxRequest mb : prefetchRequest.getMboxes()) {
existingMBoxNames.add(mb.getName());
}
}
ExecuteRequest executeRequest = deliveryRequest.getExecute();
if (executeRequest != null) {
List<MboxRequest> executeMboxes = executeRequest.getMboxes();
if (executeMboxes != null) {
for (MboxRequest mb : executeMboxes) {
if (mb.getIndex() >= idx) {
idx = mb.getIndex() + 1;
}
existingMBoxNames.add(mb.getName());
}
}
}
for (String mbox : mboxes) {
if (!existingMBoxNames.contains(mbox)) {
if (executeRequest == null) {
executeRequest = new ExecuteRequest();
targetRequest.getDeliveryRequest().setExecute(executeRequest);
}
executeRequest.addMboxesItem(new MboxRequest().index(idx++).name(mbox));
}
}
return targetRequest;
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetHttpClientTest method testExecuteAsync.
@Test
void testExecuteAsync() throws NoSuchFieldException {
ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).telemetryEnabled(false).build();
DefaultTargetHttpClient defaultTargetHttpClient = new DefaultTargetHttpClient(clientConfig);
UnirestInstance unirestInstance = Mockito.mock(UnirestInstance.class, Mockito.RETURNS_DEEP_STUBS);
FieldSetter.setField(defaultTargetHttpClient, defaultTargetHttpClient.getClass().getDeclaredField("unirestInstance"), unirestInstance);
Map<String, Object> queryParams = new HashMap<>();
String url = "/testUrl";
DeliveryRequest deliveryRequest = new DeliveryRequest();
when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObjectAsync(ArgumentMatchers.<Function<RawResponse, Object>>any()).thenApply(ArgumentMatchers.<Function<HttpResponse<Object>, CompletableFuture<ResponseWrapper<Object>>>>any())).thenAnswer(invocation -> {
HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
Function<HttpResponse, Object> function = (Function<HttpResponse, Object>) invocation.getArguments()[0];
function.apply(httpResponse);
return null;
});
CompletableFuture<ResponseWrapper<MockRawResponse>> completableFuture = defaultTargetHttpClient.executeAsync(queryParams, url, deliveryRequest, MockRawResponse.class);
assertNotNull(completableFuture);
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForServerSide.
/**
* Test case to call get offers for server side, in first request we capture the telemetry & in
* next call we send it with any getOffers() call or sendNotifications() call
*
* @throws NoSuchFieldException
*/
@Test
void testTelemetryForServerSide() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSide");
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());
// In next call we see telemetry data added to the deliveryRequest
TargetDeliveryResponse targetDeliveryResponse2 = targetJavaClient.getOffers(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());
assertNotNull(targetDeliveryResponse2);
assertNotNull(targetDeliveryResponse2.getRequest());
assertNotNull(targetDeliveryResponse2.getRequest().getTelemetry());
assertEquals(1, targetDeliveryResponse2.getRequest().getTelemetry().getEntries().size());
}
Aggregations