Search in sources :

Example 1 with RuleLoader

use of com.adobe.target.edge.client.ondevice.RuleLoader in project target-java-sdk by adobe.

the class TargetDeliveryAttributesTest method init.

@BeforeEach
@SuppressWarnings("unchecked")
void init() throws IOException, NoSuchFieldException {
    Mockito.lenient().doReturn(CompletableFuture.completedFuture(getTestDeliveryResponse())).when(defaultTargetHttpClient).executeAsync(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    ClientConfig clientConfig = ClientConfig.builder().client("emeaprod4").organizationId(TEST_ORG_ID).build();
    VisitorProvider.init(TEST_ORG_ID);
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
    localService = new OnDeviceDecisioningService(clientConfig, targetService, telemetryService);
    targetJavaClient = TargetClient.create(clientConfig);
    FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), defaultTargetHttpClient);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("localService"), localService);
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoaderFromFile("DECISIONING_PAYLOAD_ATTRIBUTES.json");
    OnDeviceDecisioningEvaluator evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("ruleLoader"), testRuleLoader);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("onDeviceDecisioningEvaluator"), evaluator);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), mock(NotificationService.class));
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("clusterLocator"), mock(ClusterLocator.class));
    ObjectMapper mapper = new JacksonObjectMapper().getMapper();
    OnDeviceDecisioningDetailsExecutor decisionHandler = new OnDeviceDecisioningDetailsExecutor(clientConfig, mapper);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("decisionHandler"), decisionHandler);
    ParamsCollator specificTimeCollator = TargetTestDeliveryRequestUtils.getSpecificTimeCollator(1582818503000L);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("timeParamsCollator"), specificTimeCollator);
}
Also used : DefaultTargetService(com.adobe.target.edge.client.service.DefaultTargetService) ParamsCollator(com.adobe.target.edge.client.ondevice.collator.ParamsCollator) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) OnDeviceDecisioningEvaluator(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningEvaluator) OnDeviceDecisioningDetailsExecutor(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningDetailsExecutor) NotificationService(com.adobe.target.edge.client.service.NotificationService) OnDeviceDecisioningService(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService) ClusterLocator(com.adobe.target.edge.client.ondevice.ClusterLocator) RuleLoader(com.adobe.target.edge.client.ondevice.RuleLoader) ClientConfig(com.adobe.target.edge.client.ClientConfig) Map(java.util.Map) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with RuleLoader

use of com.adobe.target.edge.client.ondevice.RuleLoader in project target-java-sdk by adobe.

the class TargetTestDeliveryRequestUtils method getTestRuleLoader.

public static RuleLoader getTestRuleLoader(final String ruleSet) {
    return new RuleLoader() {

        @Override
        public void start(ClientConfig clientConfig, TelemetryService telemetryService) {
        }

        @Override
        public void stop() {
        }

        @Override
        public void refresh() {
        }

        @Override
        public OnDeviceDecisioningRuleSet getLatestRules() {
            if (ruleSet == null) {
                return null;
            }
            ObjectMapper mapper = new ObjectMapper();
            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            mapper.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
            try {
                return mapper.readValue(ruleSet, new TypeReference<OnDeviceDecisioningRuleSet>() {
                });
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public long getPollingInterval() {
            return 0;
        }

        @Override
        public int getNumFetches() {
            return 0;
        }

        @Override
        public Date getLastFetch() {
            return null;
        }

        @Override
        public String getLocation() {
            return null;
        }
    };
}
Also used : RuleLoader(com.adobe.target.edge.client.ondevice.RuleLoader) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) IOException(java.io.IOException) ClientConfig(com.adobe.target.edge.client.ClientConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)

Example 3 with RuleLoader

use of com.adobe.target.edge.client.ondevice.RuleLoader in project target-java-sdk by adobe.

the class TargetTestDeliveryRequestUtils method fileRuleLoader.

public static void fileRuleLoader(String fileName, OnDeviceDecisioningService localService) throws IOException, NoSuchFieldException {
    RuleLoader testRuleLoader = TargetTestDeliveryRequestUtils.getTestRuleLoaderFromFile(fileName);
    OnDeviceDecisioningEvaluator evaluator = new OnDeviceDecisioningEvaluator(testRuleLoader);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("ruleLoader"), testRuleLoader);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("onDeviceDecisioningEvaluator"), evaluator);
}
Also used : RuleLoader(com.adobe.target.edge.client.ondevice.RuleLoader) OnDeviceDecisioningEvaluator(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningEvaluator)

Aggregations

RuleLoader (com.adobe.target.edge.client.ondevice.RuleLoader)3 ClientConfig (com.adobe.target.edge.client.ClientConfig)2 OnDeviceDecisioningEvaluator (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningEvaluator)2 TelemetryService (com.adobe.target.edge.client.service.TelemetryService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JacksonObjectMapper (com.adobe.target.edge.client.http.JacksonObjectMapper)1 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)1 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)1 ClusterLocator (com.adobe.target.edge.client.ondevice.ClusterLocator)1 OnDeviceDecisioningDetailsExecutor (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningDetailsExecutor)1 OnDeviceDecisioningService (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService)1 ParamsCollator (com.adobe.target.edge.client.ondevice.collator.ParamsCollator)1 DefaultTargetService (com.adobe.target.edge.client.service.DefaultTargetService)1 NotificationService (com.adobe.target.edge.client.service.NotificationService)1 IOException (java.io.IOException)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1