use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetServiceTest method testExecuteNotificationWithBeaconNull.
/**
* If a user sends a notifications request with Context.beacon = null, we should set it to false
* to avoid NPE. Beacon does not make sense to use with a server-side SDK.
*/
@Test
public void testExecuteNotificationWithBeaconNull() {
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(null);
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.delivery.v1.model.DeliveryRequest 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.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class DefaultTargetHttpClientTest method testExecute.
@Test
void testExecute() 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 = "/url";
DeliveryRequest deliveryRequest = new DeliveryRequest();
HttpResponse<Object> mockHttpResponse = Mockito.mock(HttpResponse.class);
when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObject(ArgumentMatchers.<Function<RawResponse, Object>>any())).thenAnswer(invocation -> {
RawResponse rawResponse = TargetTestDeliveryRequestUtils.getRawTestResponse(HttpStatus.SC_OK);
Function<RawResponse, Object> function = (Function<RawResponse, Object>) invocation.getArguments()[0];
function.apply(rawResponse);
return mockHttpResponse;
});
ResponseWrapper<MockRawResponse> responseWrapper = defaultTargetHttpClient.execute(queryParams, url, deliveryRequest, MockRawResponse.class);
assertNotNull(responseWrapper);
assertEquals(mockHttpResponse, responseWrapper.getHttpResponse());
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningService method getOrCreateVisitorId.
private String getOrCreateVisitorId(TargetDeliveryRequest deliveryRequest, TargetDeliveryResponse targetResponse) {
String vid = null;
VisitorId visitorId = deliveryRequest.getDeliveryRequest().getId();
if (visitorId != null) {
vid = StringUtils.firstNonBlank(visitorId.getMarketingCloudVisitorId(), removeLocationHint(visitorId.getTntId()), visitorId.getThirdPartyId());
}
// set our own tntId there in an earlier call
if (vid == null && targetResponse.getResponse().getId() != null) {
vid = removeLocationHint(targetResponse.getResponse().getId().getTntId());
}
if (vid != null) {
return vid;
}
// If vid still null, create new tntId and use that and set it in the response
String newTntId = generateTntId();
if (visitorId == null) {
visitorId = new VisitorId().tntId(newTntId);
} else {
visitorId.setTntId(newTntId);
}
targetResponse.getResponse().setId(visitorId);
return removeLocationHint(newTntId);
}
use of com.adobe.target.delivery.v1.model.DeliveryRequest 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