use of com.adobe.target.delivery.v1.model.ExecuteRequest 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.ExecuteRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testUnknownMbox.
@Test
public void testUnknownMbox() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> mboxes = new ArrayList<>();
mboxes.add("test");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localMboxes"), mboxes);
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteMboxes"), new ArrayList<>());
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().addMboxesItem(new MboxRequest().name("test")).addMboxesItem(new MboxRequest().name("test2"))).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertFalse(evaluation.isAllLocal());
List<String> remoteMboxes = new ArrayList<>();
remoteMboxes.add("test2");
assertEquals(remoteMboxes, evaluation.getRemoteMBoxes());
assertNull(evaluation.getRemoteViews());
}
use of com.adobe.target.delivery.v1.model.ExecuteRequest in project target-java-sdk by adobe.
the class CustomParamsCollatorTest method testCollator.
@Test
public void testCollator() {
VisitorProvider.init("testOrgId");
Map<String, String> params = new HashMap<String, String>() {
{
put("foo", "bar");
put("BAZ", "BUZ");
}
};
RequestDetails pageLoad = new RequestDetails().parameters(params);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).build();
CustomParamsCollator collator = new CustomParamsCollator();
Map<String, Object> result = collator.collateParams(request, pageLoad);
assertEquals("bar", result.get("foo"));
assertEquals("bar", result.get("foo" + CustomParamsCollator.LOWER_CASE_POSTFIX));
assertEquals("BUZ", result.get("BAZ"));
assertEquals("buz", result.get("BAZ" + CustomParamsCollator.LOWER_CASE_POSTFIX));
}
use of com.adobe.target.delivery.v1.model.ExecuteRequest in project target-java-sdk by adobe.
the class GeoParamsCollatorTest method testCollator.
@Test
public void testCollator() {
VisitorProvider.init("testOrgId");
RequestDetails pageLoad = new RequestDetails();
Geo geo = new Geo();
geo.setCity("san francisco");
geo.setStateCode("ca");
geo.setCountryCode("us");
geo.setLatitude(37.74f);
geo.setLongitude(-122.24f);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).context(new Context().geo(geo)).build();
GeoParamsCollator collator = new GeoParamsCollator();
Map<String, Object> result = collator.collateParams(request, pageLoad);
assertEquals("SANFRANCISCO", result.get(GeoParamsCollator.GEO_CITY));
assertEquals("CA", result.get(GeoParamsCollator.GEO_REGION));
assertEquals("US", result.get(GeoParamsCollator.GEO_COUNTRY));
assertEquals(37.74f, (Float) result.get(GeoParamsCollator.GEO_LATITUDE), 0.01);
assertEquals(-122.24f, (Float) result.get(GeoParamsCollator.GEO_LONGITUDE), 0.01);
}
use of com.adobe.target.delivery.v1.model.ExecuteRequest in project target-java-sdk by adobe.
the class TimeParamsCollatorTest method testCollator.
@Test
public void testCollator() {
VisitorProvider.init("testOrgId");
TimeParamsCollator collator = mock(TimeParamsCollator.class, CALLS_REAL_METHODS);
long now = 1592433971000L;
Mockito.doReturn(now).when(collator).currentTimestamp();
RequestDetails pageLoad = new RequestDetails();
TargetDeliveryRequest request = TargetDeliveryRequest.builder().execute(new ExecuteRequest().pageLoad(pageLoad)).build();
Map<String, Object> result = collator.collateParams(request, pageLoad);
assertEquals(now, result.get(TimeParamsCollator.CURRENT_TIMESTAMP));
assertEquals("3", result.get(TimeParamsCollator.CURRENT_DAY));
assertEquals("2246", result.get(TimeParamsCollator.CURRENT_TIME));
}
Aggregations