use of com.adobe.target.delivery.v1.model.DeliveryResponse in project target-java-sdk by adobe.
the class TelemetryServiceTest method testExecutionModeForHybridWithAllLocal.
/**
* Test to verify telemetryEntry has correct executionMode With partial content 206 status &
* hybrid our mode should be edge
*
* @throws NoSuchFieldException
*/
@Test
void testExecutionModeForHybridWithAllLocal() throws NoSuchFieldException {
setup(true, DecisioningMethod.HYBRID, "testExecutionModeHybridWithAllLocal");
TimingTool timer = new TimingTool();
timer.timeStart(TIMING_EXECUTE_REQUEST);
Context context = getContext();
ExecuteRequest executeRequest = getMboxExecuteRequest();
String nonDefaultToken = "non-default-token";
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.HYBRID).build();
DeliveryResponse deliveryResponse = new DeliveryResponse();
deliveryResponse.setClient("SUMMIT_TEST2021");
deliveryResponse.setEdgeHost(null);
TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
targetDeliveryResponse.getResponse().setRequestId("testID");
telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
TelemetryEntry telemetryEntry = telemetryServiceSpy.getTelemetry().getEntries().get(1);
assert telemetryEntry != null;
assertEquals(ExecutionMode.LOCAL, telemetryEntry.getMode());
}
use of com.adobe.target.delivery.v1.model.DeliveryResponse 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.DeliveryResponse 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.DeliveryResponse in project target-java-sdk by adobe.
the class TelemetryServiceTest method testAddTelemetry.
/**
* Verify if telemetry data is added correctly
*
* @throws NoSuchFieldException
*/
@Test
void testAddTelemetry() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testAddTelemetry");
TimingTool timer = new TimingTool();
timer.timeStart(TIMING_EXECUTE_REQUEST);
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();
DeliveryResponse deliveryResponse = new DeliveryResponse();
deliveryResponse.setClient("SUMMIT_TEST2021");
TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
targetDeliveryResponse.getResponse().setRequestId("testID");
// empty the in memory stored telemetry
telemetryServiceSpy.getTelemetry();
assertEquals(0, telemetryServiceSpy.getTelemetry().getEntries().size());
telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
assertEquals(1, telemetryServiceSpy.getTelemetry().getEntries().size());
}
use of com.adobe.target.delivery.v1.model.DeliveryResponse in project target-java-sdk by adobe.
the class TelemetryServiceTest method testExecutionModeForOnDevice.
/**
* Test to verify telemetryEntry has correct executionMode For ODD & status 200 it should be local
*
* @throws NoSuchFieldException
*/
@Test
void testExecutionModeForOnDevice() throws NoSuchFieldException {
setup(true, DecisioningMethod.ON_DEVICE, "testExecutionModeOnDeviceWhenStatusOK");
TimingTool timer = new TimingTool();
timer.timeStart(TIMING_EXECUTE_REQUEST);
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.ON_DEVICE).build();
DeliveryResponse deliveryResponse = new DeliveryResponse();
deliveryResponse.setClient("SUMMIT_TEST2021");
TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
targetDeliveryResponse.getResponse().setRequestId("testID");
telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
TelemetryEntry telemetryEntry = telemetryServiceSpy.getTelemetry().getEntries().get(1);
assert telemetryEntry != null;
assertEquals(ExecutionMode.LOCAL, telemetryEntry.getMode());
}
Aggregations