use of com.adobe.target.delivery.v1.model.ViewRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluator method allViewNames.
private List<String> allViewNames(TargetDeliveryRequest request) {
if (request == null) {
return Collections.emptyList();
}
List<String> viewNames = new ArrayList<>();
PrefetchRequest prefetch = request.getDeliveryRequest().getPrefetch();
if (prefetch != null) {
List<ViewRequest> views = prefetch.getViews();
if (views != null) {
for (ViewRequest viewRequest : views) {
viewNames.add(viewRequest.getName());
}
}
}
return viewNames;
}
use of com.adobe.target.delivery.v1.model.ViewRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testLocalAndRemoteView.
@Test
public void testLocalAndRemoteView() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> views = new ArrayList<>();
views.add("test");
views.add("test2");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), views);
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), views);
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertFalse(evaluation.isAllLocal());
List<String> remoteViews = evaluation.getRemoteViews();
remoteViews.sort(Comparator.naturalOrder());
assertEquals(views, remoteViews);
assertNull(evaluation.getRemoteMBoxes());
}
use of com.adobe.target.delivery.v1.model.ViewRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testUnknownView.
@Test
public void testUnknownView() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> views = new ArrayList<>();
views.add("test");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), views);
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), new ArrayList<>());
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertFalse(evaluation.isAllLocal());
List<String> remoteViews = new ArrayList<>();
remoteViews.add("test2");
assertEquals(remoteViews, evaluation.getRemoteViews());
assertNull(evaluation.getRemoteMBoxes());
}
use of com.adobe.target.delivery.v1.model.ViewRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testAllLocalNoRemoteView.
@Test
public void testAllLocalNoRemoteView() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> localViews = new ArrayList<>();
localViews.add("test");
localViews.add("test2");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), localViews);
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), new ArrayList<String>());
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest().name("test")).addViewsItem(new ViewRequest().name("test2"))).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertTrue(evaluation.isAllLocal());
assertNull(evaluation.getRemoteMBoxes());
assertNull(evaluation.getRemoteViews());
}
use of com.adobe.target.delivery.v1.model.ViewRequest in project target-java-sdk by adobe.
the class OnDeviceDecisioningEvaluatorTest method testRemoteAllViews.
@Test
public void testRemoteAllViews() throws JsonProcessingException, NoSuchFieldException {
OnDeviceDecisioningRuleSet ruleSet = new OnDeviceDecisioningRuleSet();
List<String> views = new ArrayList<>();
views.add("test");
views.add("test2");
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("localViews"), new ArrayList<>());
FieldSetter.setField(ruleSet, ruleSet.getClass().getDeclaredField("remoteViews"), views);
String serializedRuleSet = objectMapper.writeValueAsString(ruleSet);
RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoader(serializedRuleSet);
evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
TargetDeliveryRequest request = TargetDeliveryRequest.builder().prefetch(new PrefetchRequest().addViewsItem(new ViewRequest())).build();
OnDeviceDecisioningEvaluation evaluation = evaluator.evaluateLocalExecution(request);
assertFalse(evaluation.isAllLocal());
List<String> remoteViews = evaluation.getRemoteViews();
remoteViews.sort(Comparator.naturalOrder());
assertEquals(views, remoteViews);
assertNull(evaluation.getRemoteMBoxes());
}
Aggregations