Search in sources :

Example 11 with ClientConfig

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

the class DefaultTargetHttpClientTest method testExecute.

@Test
void testExecute() 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 = "/url";
    DeliveryRequest deliveryRequest = new DeliveryRequest();
    HttpResponse<Object> mockHttpResponse = Mockito.mock(HttpResponse.class);
    when(unirestInstance.post(eq(url)).queryString(eq(queryParams)).body(eq(deliveryRequest)).asObject(ArgumentMatchers.<Function<RawResponse, Object>>any())).thenAnswer(invocation -> {
        RawResponse rawResponse = TargetTestDeliveryRequestUtils.getRawTestResponse(HttpStatus.SC_OK);
        Function<RawResponse, Object> function = (Function<RawResponse, Object>) invocation.getArguments()[0];
        function.apply(rawResponse);
        return mockHttpResponse;
    });
    ResponseWrapper<MockRawResponse> responseWrapper = defaultTargetHttpClient.execute(queryParams, url, deliveryRequest, MockRawResponse.class);
    assertNotNull(responseWrapper);
    assertEquals(mockHttpResponse, responseWrapper.getHttpResponse());
}
Also used : DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) HashMap(java.util.HashMap) Function(java.util.function.Function) UnirestInstance(kong.unirest.UnirestInstance) MockRawResponse(com.adobe.target.edge.client.utils.MockRawResponse) ClientConfig(com.adobe.target.edge.client.ClientConfig) MockRawResponse(com.adobe.target.edge.client.utils.MockRawResponse) RawResponse(kong.unirest.RawResponse) Test(org.junit.jupiter.api.Test)

Example 12 with ClientConfig

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

the class DefaultTargetHttpClientTest method testProxyConfigSetWithNoAuthentication.

@Test
void testProxyConfigSetWithNoAuthentication() {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).proxyConfig(new ClientProxyConfig(PROXY_HOST, PROXY_PORT)).build();
    DefaultTargetHttpClient targetClient = new DefaultTargetHttpClient(clientConfig);
    UnirestInstance unirestInstance = targetClient.getUnirestInstance();
    Proxy unirestProxy = unirestInstance.config().getProxy();
    assertNotNull(unirestProxy);
    assertEquals(PROXY_HOST, unirestProxy.getHost());
    assertEquals(PROXY_PORT, unirestProxy.getPort());
    assertNull(unirestProxy.getUsername());
    assertNull(unirestProxy.getPassword());
    targetClient.close();
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) UnirestInstance(kong.unirest.UnirestInstance) Proxy(kong.unirest.Proxy) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 13 with ClientConfig

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

the class DefaultTargetHttpClientTest method testProxyConfigSetWithAuthentication.

@Test
void testProxyConfigSetWithAuthentication() {
    ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).proxyConfig(new ClientProxyConfig(PROXY_HOST, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD)).build();
    DefaultTargetHttpClient targetClient = new DefaultTargetHttpClient(clientConfig);
    UnirestInstance unirestInstance = targetClient.getUnirestInstance();
    Proxy unirestProxy = unirestInstance.config().getProxy();
    assertNotNull(unirestProxy);
    assertEquals(PROXY_HOST, unirestProxy.getHost());
    assertEquals(PROXY_PORT, unirestProxy.getPort());
    assertEquals(PROXY_USERNAME, unirestProxy.getUsername());
    assertEquals(PROXY_PASSWORD, unirestProxy.getPassword());
    targetClient.close();
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) UnirestInstance(kong.unirest.UnirestInstance) Proxy(kong.unirest.Proxy) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 14 with ClientConfig

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

Example 15 with ClientConfig

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

the class TargetDeliveryRequestLocalViewTest method init.

@BeforeEach
@SuppressWarnings("unchecked")
void init() 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().client("emeaprod4").organizationId(TEST_ORG_ID).build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
    localService = new OnDeviceDecisioningService(clientConfig, targetService, telemetryService);
    ObjectMapper mapper = new JacksonObjectMapper().getMapper();
    OnDeviceDecisioningDetailsExecutor decisionHandler = new OnDeviceDecisioningDetailsExecutor(clientConfig, mapper);
    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);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("decisionHandler"), decisionHandler);
    ParamsCollator specificTimeCollator = TargetTestDeliveryRequestUtils.getSpecificTimeCollator(1582818503000L);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("timeParamsCollator"), specificTimeCollator);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), mock(NotificationService.class));
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("clusterLocator"), mock(ClusterLocator.class));
}
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) 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) ClientConfig(com.adobe.target.edge.client.ClientConfig) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

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