Search in sources :

Example 6 with OnDeviceDecisioningRuleSet

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet 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());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 7 with OnDeviceDecisioningRuleSet

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

the class DefaultRuleLoaderTest method testRuleLoaderArtifactPayload.

@Test
void testRuleLoaderArtifactPayload() {
    DefaultRuleLoader defaultRuleLoader = mock(DefaultRuleLoader.class, CALLS_REAL_METHODS);
    String etag = "5b1cf3c050e1a0d16934922bf19ba6ea";
    Mockito.doReturn(null).when(defaultRuleLoader).generateRequest(any(ClientConfig.class));
    Mockito.doReturn(getTestResponse(TEST_RULE_SET, etag, HttpStatus.SC_OK)).when(defaultRuleLoader).executeRequest(any());
    ClientConfig payloadClientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).onDeviceEnvironment("production").defaultDecisioningMethod(DecisioningMethod.ON_DEVICE).exceptionHandler(exceptionHandler).onDeviceDecisioningHandler(executionHandler).onDeviceArtifactPayload(TEST_RULE_SET.getBytes(StandardCharsets.UTF_8)).build();
    defaultRuleLoader.start(payloadClientConfig, telemetryService);
    verify(defaultRuleLoader, timeout(1000)).setLatestRules(any(OnDeviceDecisioningRuleSet.class));
    verify(executionHandler, timeout(1000)).onDeviceDecisioningReady();
    verify(executionHandler, never()).artifactDownloadSucceeded(any());
    verify(executionHandler, never()).artifactDownloadFailed(any());
    OnDeviceDecisioningRuleSet rules = defaultRuleLoader.getLatestRules();
    assertNotNull(rules);
    defaultRuleLoader.refresh();
    verify(exceptionHandler, never()).handleException(any(TargetClientException.class));
    defaultRuleLoader.stop();
}
Also used : TargetClientException(com.adobe.target.edge.client.exception.TargetClientException) ClientConfig(com.adobe.target.edge.client.ClientConfig) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) Test(org.junit.jupiter.api.Test)

Example 8 with OnDeviceDecisioningRuleSet

use of com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet 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());
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ArrayList(java.util.ArrayList) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ViewRequest(com.adobe.target.delivery.v1.model.ViewRequest) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) OnDeviceDecisioningEvaluation(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation) Test(org.junit.jupiter.api.Test)

Example 9 with OnDeviceDecisioningRuleSet

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

the class DefaultRuleLoaderTest method getTestResponse.

static HttpResponse<OnDeviceDecisioningRuleSet> getTestResponse(final String ruleSet, final String etag, final int status) {
    return new HttpResponse<OnDeviceDecisioningRuleSet>() {

        @Override
        public int getStatus() {
            return status;
        }

        @Override
        public String getStatusText() {
            return null;
        }

        @Override
        public Headers getHeaders() {
            Headers headers = new Headers();
            if (etag != null) {
                headers.add("ETag", etag);
            }
            return headers;
        }

        @Override
        public OnDeviceDecisioningRuleSet getBody() {
            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 Optional<UnirestParsingException> getParsingError() {
            return Optional.empty();
        }

        @Override
        public <V> V mapBody(Function<OnDeviceDecisioningRuleSet, V> func) {
            return null;
        }

        @Override
        public <V> HttpResponse<V> map(Function<OnDeviceDecisioningRuleSet, V> func) {
            return null;
        }

        @Override
        public HttpResponse<OnDeviceDecisioningRuleSet> ifSuccess(Consumer<HttpResponse<OnDeviceDecisioningRuleSet>> consumer) {
            return null;
        }

        @Override
        public HttpResponse<OnDeviceDecisioningRuleSet> ifFailure(Consumer<HttpResponse<OnDeviceDecisioningRuleSet>> consumer) {
            return null;
        }

        @Override
        public <E> HttpResponse<OnDeviceDecisioningRuleSet> ifFailure(Class<? extends E> errorClass, Consumer<HttpResponse<E>> consumer) {
            return null;
        }

        @Override
        public boolean isSuccess() {
            return false;
        }

        @Override
        public <E> E mapError(Class<? extends E> errorClass) {
            return null;
        }

        @Override
        public Cookies getCookies() {
            return null;
        }
    };
}
Also used : OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) Function(java.util.function.Function) Consumer(java.util.function.Consumer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 10 with OnDeviceDecisioningRuleSet

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

the class DefaultRuleLoaderTest method testDefaultRuleLoader.

@Test
void testDefaultRuleLoader() {
    DefaultRuleLoader defaultRuleLoader = mock(DefaultRuleLoader.class, CALLS_REAL_METHODS);
    String etag = "5b1cf3c050e1a0d16934922bf19ba6ea";
    Mockito.doReturn(null).when(defaultRuleLoader).generateRequest(any(ClientConfig.class));
    Mockito.doReturn(getTestResponse(TEST_RULE_SET, etag, HttpStatus.SC_OK)).when(defaultRuleLoader).executeRequest(any());
    defaultRuleLoader.start(clientConfig, telemetryService);
    verify(defaultRuleLoader, timeout(1000)).setLatestRules(any(OnDeviceDecisioningRuleSet.class));
    verify(defaultRuleLoader, timeout(1000)).setLatestETag(eq(etag));
    verify(executionHandler, timeout(1000)).onDeviceDecisioningReady();
    verify(executionHandler, timeout(1000)).artifactDownloadSucceeded(any());
    verify(executionHandler, never()).artifactDownloadFailed(any());
    OnDeviceDecisioningRuleSet rules = defaultRuleLoader.getLatestRules();
    assertNotNull(rules);
    defaultRuleLoader.stop();
    // do it again, make sure starting works again after a stop
    reset(executionHandler);
    defaultRuleLoader.start(clientConfig, telemetryService);
    verify(defaultRuleLoader, timeout(1000)).setLatestRules(any(OnDeviceDecisioningRuleSet.class));
    verify(defaultRuleLoader, timeout(1000)).setLatestETag(eq(etag));
    verify(executionHandler, timeout(1000)).onDeviceDecisioningReady();
    verify(executionHandler, timeout(1000)).artifactDownloadSucceeded(any());
    verify(executionHandler, never()).artifactDownloadFailed(any());
    rules = defaultRuleLoader.getLatestRules();
    assertNotNull(rules);
    Mockito.doReturn(getTestResponse(TEST_RULE_SET, "5b1cf3c050e1a0d16934922bf19ba6ea", HttpStatus.SC_NOT_MODIFIED)).when(defaultRuleLoader).executeRequest(any());
    defaultRuleLoader.refresh();
    verify(exceptionHandler, never()).handleException(any(TargetClientException.class));
    defaultRuleLoader.stop();
}
Also used : TargetClientException(com.adobe.target.edge.client.exception.TargetClientException) ClientConfig(com.adobe.target.edge.client.ClientConfig) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) Test(org.junit.jupiter.api.Test)

Aggregations

OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)17 Test (org.junit.jupiter.api.Test)11 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)10 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)9 ArrayList (java.util.ArrayList)9 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)5 ViewRequest (com.adobe.target.delivery.v1.model.ViewRequest)5 TargetClientException (com.adobe.target.edge.client.exception.TargetClientException)4 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)3 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)3 ClientConfig (com.adobe.target.edge.client.ClientConfig)3 TargetExceptionHandler (com.adobe.target.edge.client.exception.TargetExceptionHandler)2 OnDeviceDecisioningHandler (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler)2 TimingTool (com.adobe.target.edge.client.utils.TimingTool)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)1 Notification (com.adobe.target.delivery.v1.model.Notification)1 RequestDetails (com.adobe.target.delivery.v1.model.RequestDetails)1 ClientProxyConfig (com.adobe.target.edge.client.ClientProxyConfig)1