use of com.adobe.target.edge.client.model.TargetDeliveryRequest 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.edge.client.model.TargetDeliveryRequest 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.edge.client.model.TargetDeliveryRequest 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.edge.client.model.TargetDeliveryRequest 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.edge.client.model.TargetDeliveryRequest 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