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