Search in sources :

Example 1 with ClientConfig

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

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesAllMatches.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesAllMatches() throws IOException, NoSuchFieldException {
    String mbox = "allmatches";
    ArrayList<String> mboxes = new ArrayList<String>() {

        {
            add(mbox);
        }
    };
    ClientConfig clientConfig = ClientConfig.builder().client("targettesting").organizationId(TEST_ORG_ID).onDeviceEnvironment("test").defaultDecisioningMethod(DecisioningMethod.ON_DEVICE).onDeviceAllMatchingRulesMboxes(mboxes).build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
    localService = new OnDeviceDecisioningService(clientConfig, targetService, telemetryService);
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("localService"), localService);
    FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), defaultTargetHttpClient);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
    Context context = getLocalContext();
    PrefetchRequest prefetchRequest = getMboxPrefetchLocalRequest(mbox);
    VisitorId visitorId = new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916873");
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).id(visitorId).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
    Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest, mbox);
    assertNotNull(attrs);
    assertNotNull(attrs.getResponse());
    assertEquals(200, attrs.getResponse().getStatus());
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
    assertEquals(2, attrs.getInteger(mbox, "allmatches", 0));
    assertEquals("a", attrs.getString(mbox, "allmatches1_exp"));
    assertEquals("a", attrs.getString(mbox, "allmatches2_exp"));
}
Also used : DefaultTargetService(com.adobe.target.edge.client.service.DefaultTargetService) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) ArrayList(java.util.ArrayList) Attributes(com.adobe.target.edge.client.Attributes) OnDeviceDecisioningService(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ClientConfig(com.adobe.target.edge.client.ClientConfig) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with ClientConfig

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

the class TargetDeliveryExceptionTest method init.

@BeforeEach
void init() throws NoSuchFieldException {
    Mockito.lenient().doReturn(getTestDeliveryResponseFailure("ERROR: application server timeout.", "ERROR: application server timeout.")).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).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) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) ClientConfig(com.adobe.target.edge.client.ClientConfig) Map(java.util.Map) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ClientConfig

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

the class TargetDeliveryLocalPropertyTest method init.

@BeforeEach
@SuppressWarnings("unchecked")
void init() throws IOException, 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("org").build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
    OnDeviceDecisioningService 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);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), mock(NotificationService.class));
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("clusterLocator"), mock(ClusterLocator.class));
    fileRuleLoader(PROPERTY_TEST_FILE, localService);
}
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) 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) 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 5 with ClientConfig

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

the class DefaultGeoClientTest method testDefaultGeoClient.

@Test
void testDefaultGeoClient() {
    String domain = "test.com";
    ClientConfig clientConfig = ClientConfig.builder().organizationId("testOrgId").onDeviceConfigHostname(domain).build();
    DefaultGeoClient geoClient = spy(DefaultGeoClient.class);
    geoClient.start(clientConfig);
    String ip = "127.0.0.1";
    String url = "https://" + domain + DefaultGeoClient.GEO_PATH;
    String city = "SAN FRANCISCO";
    String regionCode = "CA";
    String countryCode = "US";
    float latitude = 37.74f;
    float longitude = -122.24f;
    GetRequest request = mock(GetRequest.class);
    @SuppressWarnings("rawtypes") HttpResponse response = mock(HttpResponse.class);
    Headers headers = new Headers();
    headers.add(DefaultGeoClient.GEO_HEADER_CITY, city);
    headers.add(DefaultGeoClient.GEO_HEADER_REGION, regionCode);
    headers.add(DefaultGeoClient.GEO_HEADER_COUNTRY, countryCode);
    headers.add(DefaultGeoClient.GEO_HEADER_LATITUDE, String.valueOf(latitude));
    headers.add(DefaultGeoClient.GEO_HEADER_LONGITUDE, String.valueOf(longitude));
    Mockito.doReturn(response).when(request).asEmpty();
    Mockito.doReturn(headers).when(response).getHeaders();
    Mockito.doReturn(request).when(geoClient).geoRequest(any(), any(), any());
    Geo geoResponse = geoClient.lookupGeo(ip);
    verify(geoClient).geoRequest(eq(url), eq(DefaultGeoClient.GEO_IP_HEADER), eq(ip));
    assertEquals(city, geoResponse.getCity());
    assertEquals(regionCode, geoResponse.getStateCode());
    assertEquals(countryCode, geoResponse.getCountryCode());
    assertEquals(latitude, geoResponse.getLatitude(), 0.01);
    assertEquals(longitude, geoResponse.getLongitude(), 0.01);
}
Also used : Geo(com.adobe.target.delivery.v1.model.Geo) Headers(kong.unirest.Headers) GetRequest(kong.unirest.GetRequest) HttpResponse(kong.unirest.HttpResponse) 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