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);
}
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();
}
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);
}
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);
}
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();
}
Aggregations