use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.
the class TargetDeliveryLocalGeoTest method optionsForGeo.
@SuppressWarnings("unchecked")
private List<Option> optionsForGeo(Geo geo) {
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().geo(geo).address(new Address().url("https://test.com"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().name("geo").index(0))).id(new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916874")).decisioningMethod(DecisioningMethod.HYBRID).build();
TargetDeliveryResponse response = targetJavaClient.getOffers(targetDeliveryRequest);
assertNotNull(response);
assertEquals(200, response.getStatus());
verify(defaultTargetHttpClient, never()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
DeliveryResponse deliveryResponse = response.getResponse();
assertNotNull(deliveryResponse);
PrefetchResponse prefetchResponse = deliveryResponse.getPrefetch();
assertNotNull(prefetchResponse);
List<PrefetchMboxResponse> mboxResponses = prefetchResponse.getMboxes();
assertNotNull(mboxResponses);
assertEquals(1, mboxResponses.size());
PrefetchMboxResponse mboxResponse = mboxResponses.get(0);
assertNotNull(mboxResponse);
assertEquals(0, mboxResponse.getIndex());
assertEquals("geo", mboxResponse.getName());
return mboxResponse.getOptions();
}
use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.
the class TargetDeliveryLocalGeoTest method testTargetDeliveryLocalRequestGeoNoIPLookup.
@Test
void testTargetDeliveryLocalRequestGeoNoIPLookup() throws IOException, NoSuchFieldException {
fileRuleLoader(GEO_TEST_FAKE_FILE, localService);
String ip = "127.0.0.1";
Geo ipGeo = new Geo().ipAddress(ip);
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().geo(ipGeo).address(new Address().url("https://test.com"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().name("geo").index(0))).id(new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916874")).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
TargetDeliveryResponse response = targetJavaClient.getOffers(targetDeliveryRequest);
assertNotNull(response);
assertEquals(200, response.getStatus());
verify(mockGeoClient, atMostOnce()).start(any());
verify(mockGeoClient, never()).lookupGeo(eq(ip));
}
use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestAddressMbox.
@Test
void testTargetDeliveryLocalRequestAddressMbox() throws IOException, NoSuchFieldException {
fileRuleLoader("DECISIONING_PAYLOAD_ADDRESS.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("58734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.HYBRID, "offer2");
targetDeliveryRequest.getDeliveryRequest().getContext().setAddress(new Address().url("https://test.com"));
targetDeliveryRequest.getDeliveryRequest().getPrefetch().getMboxes().get(0).setAddress(new Address().url("https://test.com?foo=bar"));
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "offer2");
Map<String, Object> expectedContent = new HashMap<String, Object>() {
{
put("baz", 1);
}
};
verifyJSONContent(prefetchOptions, expectedContent, "mWtD0yDAXMnesyQOa7/jS2qipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==");
}
use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestAllMatches.
@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryLocalRequestAllMatches() throws IOException, NoSuchFieldException {
String mbox = "allmatches";
Set<String> onDeviceAllMatchingRulesMboxes = new HashSet<String>() {
{
add(mbox);
}
};
FieldSetter.setField(localService, localService.getClass().getDeclaredField("onDeviceAllMatchingRulesMboxes"), onDeviceAllMatchingRulesMboxes);
fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, mbox);
PrefetchRequest prefetchRequest = targetDeliveryRequest.getDeliveryRequest().getPrefetch();
MboxRequest mboxRequest = prefetchRequest.getMboxes().get(0);
mboxRequest.setParameters(new HashMap<String, String>() {
{
put("foo", "bar");
}
});
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
DeliveryResponse response = targetDeliveryResponse.getResponse();
assertNotNull(response);
PrefetchResponse preResponse = response.getPrefetch();
assertNotNull(preResponse);
List<PrefetchMboxResponse> preMboxes = preResponse.getMboxes();
assertNotNull(preMboxes);
assertEquals(2, preMboxes.size());
PrefetchMboxResponse preMboxResponse1 = preMboxes.get(0);
List<Option> prefetchOptions1 = preMboxResponse1.getOptions();
assertEquals(1, prefetchOptions1.size());
Option option1 = prefetchOptions1.get(0);
assertEquals(OptionType.JSON, option1.getType());
Map<String, Object> preContent1 = (Map<String, Object>) option1.getContent();
assertEquals(2, preContent1.get("allmatches"));
assertEquals("b", preContent1.get("allmatches2_exp"));
assertEquals("aNT5qgpj/qd5U7cLpV7p05NWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option1.getEventToken());
PrefetchMboxResponse preMboxResponse2 = preMboxes.get(1);
List<Option> prefetchOptions2 = preMboxResponse2.getOptions();
assertEquals(1, prefetchOptions2.size());
Option option2 = prefetchOptions2.get(0);
assertEquals(OptionType.JSON, option2.getType());
Map<String, Object> preContent2 = (Map<String, Object>) option2.getContent();
assertEquals(1, preContent2.get("allmatches"));
assertEquals("a", preContent2.get("allmatches1_exp"));
assertEquals("+hItquQ2BQan0pYxdJmMcGqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option2.getEventToken());
}
use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.
the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestVisitor1.
@Test
void testTargetDeliveryLocalRequestVisitor1() throws IOException, NoSuchFieldException {
fileRuleLoader("DECISIONING_PAYLOAD_ADDRESS.json", localService);
TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.HYBRID, "offer2");
targetDeliveryRequest.getDeliveryRequest().getContext().setAddress(new Address().url("https://test.com?foo=bar"));
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "offer2");
Map<String, Object> expectedContent = new HashMap<String, Object>() {
{
put("baz", 2);
}
};
verifyJSONContent(prefetchOptions, expectedContent, "mWtD0yDAXMnesyQOa7/jS5NWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==");
Option option = prefetchOptions.get(0);
Map<String, Object> responseTokens = option.getResponseTokens();
assertEquals(333312, responseTokens.get("activity.id"));
assertEquals("Form Based Activity - offer2 - Feb 19 2020, 10:34", responseTokens.get("activity.name"));
assertEquals(1, responseTokens.get("experience.id"));
assertEquals("Experience B", responseTokens.get("experience.name"));
assertEquals(630814, responseTokens.get("offer.id"));
assertEquals(3, responseTokens.get("option.id"));
assertEquals("Offer3", responseTokens.get("option.name"));
assertEquals("on-device", responseTokens.get("activity.decisioningMethod"));
}
Aggregations