Search in sources :

Example 1 with GeoClient

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

the class TargetDeliveryLocalGeoTest 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().client("adobesummit2018").organizationId("org").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);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), mock(NotificationService.class));
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("clusterLocator"), mock(ClusterLocator.class));
    fileRuleLoader(GEO_TEST_FILE, localService);
    Geo geoResult = new Geo().city("san francisco").stateCode("ca").countryCode("us").latitude(37.74f).longitude(-122.24f);
    mockGeoClient = Mockito.spy(new GeoClient() {

        @Override
        public void start(ClientConfig clientConfig) {
        }

        @Override
        public Geo lookupGeo(String ip) {
            return geoResult;
        }

        @Override
        public void close() {
        }
    });
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("geoClient"), mockGeoClient);
}
Also used : DefaultTargetService(com.adobe.target.edge.client.service.DefaultTargetService) GeoClient(com.adobe.target.edge.client.ondevice.client.geo.GeoClient) 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)

Aggregations

ClientConfig (com.adobe.target.edge.client.ClientConfig)1 JacksonObjectMapper (com.adobe.target.edge.client.http.JacksonObjectMapper)1 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)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 GeoClient (com.adobe.target.edge.client.ondevice.client.geo.GeoClient)1 DefaultTargetService (com.adobe.target.edge.client.service.DefaultTargetService)1 NotificationService (com.adobe.target.edge.client.service.NotificationService)1 TelemetryService (com.adobe.target.edge.client.service.TelemetryService)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1