Search in sources :

Example 6 with ClientConfig

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

the class DefaultTargetHttpClientTest method testExecuteAsync.

@Test
void testExecuteAsync() throws NoSuchFieldException {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).telemetryEnabled(false).build();
    DefaultTargetHttpClient defaultTargetHttpClient = new DefaultTargetHttpClient(clientConfig);
    UnirestInstance unirestInstance = Mockito.mock(UnirestInstance.class, Mockito.RETURNS_DEEP_STUBS);
    FieldSetter.setField(defaultTargetHttpClient, defaultTargetHttpClient.getClass().getDeclaredField("unirestInstance"), unirestInstance);
    Map<String, Object> queryParams = new HashMap<>();
    String url = "/testUrl";
    DeliveryRequest deliveryRequest = new DeliveryRequest();
    when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObjectAsync(ArgumentMatchers.<Function<RawResponse, Object>>any()).thenApply(ArgumentMatchers.<Function<HttpResponse<Object>, CompletableFuture<ResponseWrapper<Object>>>>any())).thenAnswer(invocation -> {
        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
        Function<HttpResponse, Object> function = (Function<HttpResponse, Object>) invocation.getArguments()[0];
        function.apply(httpResponse);
        return null;
    });
    CompletableFuture<ResponseWrapper<MockRawResponse>> completableFuture = defaultTargetHttpClient.executeAsync(queryParams, url, deliveryRequest, MockRawResponse.class);
    assertNotNull(completableFuture);
}
Also used : DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) HashMap(java.util.HashMap) HttpResponse(kong.unirest.HttpResponse) Function(java.util.function.Function) UnirestInstance(kong.unirest.UnirestInstance) CompletableFuture(java.util.concurrent.CompletableFuture) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 7 with ClientConfig

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

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

the class DefaultTargetServiceTest method init.

@BeforeEach
void init() throws NoSuchFieldException {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).telemetryEnabled(true).build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    targetService = new DefaultTargetService(clientConfig, telemetryService);
    TargetClient targetJavaClient = TargetClient.create(clientConfig);
    FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), targetHttpClient);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
}
Also used : ClientConfig(com.adobe.target.edge.client.ClientConfig) TargetClient(com.adobe.target.edge.client.TargetClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ClientConfig

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

the class TargetDeliveryRequestTest method setup.

void setup(boolean isTelemetryEnabled) throws NoSuchFieldException {
    Mockito.lenient().doReturn(getTestDeliveryResponse()).when(defaultTargetHttpClient).execute(any(Map.class), any(String.class), any(DeliveryRequest.class), any(Class.class));
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).defaultPropertyToken(TEST_PROPERTY_TOKEN).telemetryEnabled(isTelemetryEnabled).build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    targetService = new DefaultTargetService(clientConfig, telemetryService);
    targetJavaClient = TargetClient.create(clientConfig);
    FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), defaultTargetHttpClient);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
}
Also used : DefaultTargetService(com.adobe.target.edge.client.service.DefaultTargetService) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) ClientConfig(com.adobe.target.edge.client.ClientConfig)

Example 10 with ClientConfig

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

the class DefaultTargetHttpClientTest method testProxyConfigNotSet.

@Test
void testProxyConfigNotSet() {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).build();
    DefaultTargetHttpClient targetClient = new DefaultTargetHttpClient(clientConfig);
    UnirestInstance unirestInstance = targetClient.getUnirestInstance();
    Proxy unirestProxy = unirestInstance.config().getProxy();
    assertNull(unirestProxy);
    targetClient.close();
}
Also used : UnirestInstance(kong.unirest.UnirestInstance) Proxy(kong.unirest.Proxy) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ClientConfig (com.adobe.target.edge.client.ClientConfig)18 TelemetryService (com.adobe.target.edge.client.service.TelemetryService)9 Test (org.junit.jupiter.api.Test)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)8 DefaultTargetService (com.adobe.target.edge.client.service.DefaultTargetService)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 OnDeviceDecisioningService (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 JacksonObjectMapper (com.adobe.target.edge.client.http.JacksonObjectMapper)5 ClusterLocator (com.adobe.target.edge.client.ondevice.ClusterLocator)5 OnDeviceDecisioningDetailsExecutor (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningDetailsExecutor)5 NotificationService (com.adobe.target.edge.client.service.NotificationService)5 Map (java.util.Map)5 UnirestInstance (kong.unirest.UnirestInstance)5 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)3 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)3 ParamsCollator (com.adobe.target.edge.client.ondevice.collator.ParamsCollator)3 Proxy (kong.unirest.Proxy)3 ClientProxyConfig (com.adobe.target.edge.client.ClientProxyConfig)2 TargetClientException (com.adobe.target.edge.client.exception.TargetClientException)2