aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2019-05-23 14:02:25 +0200
committerJakub Dudycz <jakub.dudycz@nokia.com>2019-05-23 15:24:35 +0200
commit2b9110c11b481d9cc57600f554be37caaf8bcb50 (patch)
treeda10cb1544dc66f919e2e715a73dba7bc2c1d979
parent9c9f9e2663d0a1adbb00553a4c32f9fb9f0befd2 (diff)
Remove CloudHttpClient usages from aai-client module
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com> Issue-ID: DCAEGEN2-1526 Change-Id: Ic83dab9f61c0b8ebc54d291002c3036ff85867ca
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java36
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java84
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java18
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java17
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java14
-rw-r--r--rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java15
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java73
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java4
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java23
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java52
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java54
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java59
12 files changed, 221 insertions, 228 deletions
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java
index 9c097ef1..5e51b832 100644
--- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactory.java
@@ -20,20 +20,19 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service;
-import io.netty.handler.ssl.SslContext;
import io.vavr.control.Try;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys;
import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore;
import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
-import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,37 +41,28 @@ public class AaiHttpClientFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class);
private final AaiClientConfiguration configuration;
- private final SslFactory sslFactory;
public AaiHttpClientFactory(AaiClientConfiguration configuration) {
- this(configuration, new SslFactory());
- }
-
- public AaiHttpClientFactory(AaiClientConfiguration configuration, SslFactory sslFactory) {
this.configuration = configuration;
- this.sslFactory = sslFactory;
}
- public CloudHttpClient build() {
+ public RxHttpClient build() {
LOGGER.debug("Setting ssl context");
- return new CloudHttpClient(createSslContext());
- }
- private SslContext createSslContext() {
if (configuration.enableAaiCertAuth()) {
- final SecurityKeys collectorSecurityKeys = ImmutableSecurityKeys.builder()
- .keyStore(ImmutableSecurityKeysStore.of(resource(configuration.keyStorePath()).get()))
- .keyStorePassword(Passwords.fromResource(configuration.keyStorePasswordPath()))
- .trustStore(ImmutableSecurityKeysStore.of(resource(configuration.trustStorePath()).get()))
- .trustStorePassword(Passwords.fromResource(configuration.trustStorePasswordPath()))
- .build();
- return sslFactory.createSecureClientContext(collectorSecurityKeys);
+ return RxHttpClientFactory.create(createSslKeys());
+ } else {
+ return RxHttpClientFactory.createInsecure();
}
- return sslFactory.createInsecureClientContext();
}
- private Try<Path> resource(String resource) {
- return Try.of(() -> Paths.get(Passwords.class.getResource(resource).toURI()));
+ private SecurityKeys createSslKeys() {
+ return ImmutableSecurityKeys.builder()
+ .keyStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.keyStorePath())))
+ .keyStorePassword(Passwords.fromPath(Paths.get(configuration.keyStorePasswordPath())))
+ .trustStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.trustStorePath())))
+ .trustStorePassword(Passwords.fromPath(Paths.get(configuration.trustStorePasswordPath())))
+ .build();
}
public static RequestDiagnosticContext createRequestDiagnosticContext() {
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java
new file mode 100644
index 00000000..9a40dc57
--- /dev/null
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AaiRequests.java
@@ -0,0 +1,84 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http;
+
+import io.vavr.collection.HashMap;
+import java.util.Map;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody;
+import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel;
+import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+
+public final class AaiRequests {
+
+ private AaiRequests(){}
+
+ public static HttpRequest createAaiPatchRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
+
+ return buildAaiRequestWithBody(url, context, customHeaders,
+ jsonBodyBuilder, clientModel, HttpMethod.PATCH);
+ }
+
+ public static HttpRequest createAaiPutRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
+
+ return buildAaiRequestWithBody(url, context, customHeaders,
+ jsonBodyBuilder, clientModel, HttpMethod.PUT);
+ }
+
+ private static HttpRequest buildAaiRequestWithBody(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel,
+ HttpMethod method) {
+
+ String jsonBody = jsonBodyBuilder.createJsonBody(clientModel);
+
+ return ImmutableHttpRequest.builder()
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .body(RequestBody.fromString(jsonBody))
+ .method(method)
+ .build();
+ }
+
+ public static HttpRequest createAaiGetRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders) {
+ return ImmutableHttpRequest.builder()
+ .method(HttpMethod.GET)
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .build();
+ }
+}
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java
index 1838ce4a..30e28a47 100644
--- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClient.java
@@ -20,6 +20,7 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import io.vavr.collection.HashMap;
@@ -27,8 +28,9 @@ import io.vavr.collection.Map;
import org.apache.commons.text.StringSubstitutor;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
import reactor.core.publisher.Mono;
@@ -41,13 +43,13 @@ public class AaiGetServiceInstanceClient implements
private static final String SERVICE_TYPE = "serviceType";
private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
- private final CloudHttpClient httpGetClient;
+ private final RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration,
- final CloudHttpClient httpGetClient) {
+ final RxHttpClient httpClient) {
this.configuration = configuration;
- this.httpGetClient = httpGetClient;
+ this.httpClient = httpClient;
}
@Override
@@ -60,10 +62,10 @@ public class AaiGetServiceInstanceClient implements
final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap());
final String replaced = substitutor.replace(configuration.aaiServiceInstancePath());
- return httpGetClient.get(
- getUri(replaced),
- createRequestDiagnosticContext(),
- configuration.aaiHeaders());
+ final HttpRequest getRequest = createAaiGetRequest(getUri(replaced),
+ createRequestDiagnosticContext(), configuration.aaiHeaders());
+
+ return httpClient.call(getRequest);
}
private String getUri(final String endpoint) {
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java
index 7d511a9c..d78953da 100644
--- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java
@@ -20,33 +20,38 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
import reactor.core.publisher.Mono;
public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpResponse> {
- private final CloudHttpClient httpGetClient;
+ private final RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
- public AaiHttpGetClient(AaiClientConfiguration configuration, CloudHttpClient httpGetClient) {
+ public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) {
this.configuration = configuration;
- this.httpGetClient = httpGetClient;
+ this.httpClient = httpClient;
}
@Override
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
- return httpGetClient
- .get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders());
+ final HttpRequest getRequest = createAaiGetRequest(getUri(aaiModel.getCorrelationId()),
+ createRequestDiagnosticContext(), configuration.aaiHeaders());
+
+ return httpClient.call(getRequest);
}
+
private String getUri(String pnfName) {
return new URI.URIBuilder()
.scheme(configuration.aaiProtocol())
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java
index 679d9f18..4d0af7ea 100644
--- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java
@@ -20,14 +20,16 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiPatchRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
@@ -37,27 +39,29 @@ public final class AaiHttpPatchClient implements AaiHttpClient<AaiModel, HttpRes
private final static Map<String, String> CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json");
- private CloudHttpClient httpPatchClient;
+ private RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
private final JsonBodyBuilder jsonBodyBuilder;
public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder,
- CloudHttpClient httpPatchClient) {
+ RxHttpClient httpClient) {
this.configuration = configuration;
this.jsonBodyBuilder = jsonBodyBuilder;
- this.httpPatchClient = httpPatchClient;
+ this.httpClient = httpClient;
}
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
final Map<String, String> headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders()));
- return httpPatchClient.patch(
+ final HttpRequest aaiPatchRequest = createAaiPatchRequest(
getUri(aaiModel.getCorrelationId()),
createRequestDiagnosticContext(),
headers.toJavaMap(),
jsonBodyBuilder,
aaiModel);
+
+ return httpClient.call(aaiPatchRequest);
}
private String getUri(String pnfName) {
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java
index ce9eccc3..821d07ef 100644
--- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java
+++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java
@@ -21,34 +21,37 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.put;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiPutRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import reactor.core.publisher.Mono;
public class AaiHttpPutClient implements AaiHttpClient<AaiModel, HttpResponse> {
- private CloudHttpClient httpPutClient;
+ private RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
private final JsonBodyBuilder jsonBodyBuilder;
private final String uri;
public AaiHttpPutClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, String uri,
- CloudHttpClient httpPutClient) {
+ RxHttpClient httpClient) {
this.configuration = configuration;
this.jsonBodyBuilder = jsonBodyBuilder;
this.uri = uri;
- this.httpPutClient = httpPutClient;
+ this.httpClient = httpClient;
}
@Override
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
- return httpPutClient
- .put(uri, createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ final HttpRequest aaiPutRequest = createAaiPutRequest(uri, createRequestDiagnosticContext(),
+ configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ return httpClient.call(aaiPutRequest);
}
}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java
deleted file mode 100644
index 7f5096e5..00000000
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.insecureConfiguration;
-import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-
-import io.netty.handler.ssl.SslContext;
-import javax.net.ssl.SSLException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
-import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory;
-
-class AaiHttpClientFactoryTest {
-
- private SslFactory sslFactory;
-
- @BeforeEach
- void setup() {
- this.sslFactory = Mockito.mock(SslFactory.class);
- }
-
- @Test
- void createRequestDiagnosticContext_shouldReturnNonNullContext() {
- assertNotNull(AaiHttpClientFactory.createRequestDiagnosticContext());
- }
-
- @Test
- void build_onSecureConfigurationProvided_shouldReturnSecureClient() throws SSLException {
- when(sslFactory.createSecureClientContext(any())).thenReturn(SslContext.newClientContext());
- AaiHttpClientFactory cut = new AaiHttpClientFactory(secureConfiguration(), sslFactory);
-
- cut.build();
-
- verify(sslFactory).createSecureClientContext(any(SecurityKeys.class));
- verify(sslFactory, never()).createInsecureClientContext();
- }
-
- @Test
- void build_onInsecureConfigurationProvided_shouldReturnInsecureClient() throws SSLException {
- when(sslFactory.createInsecureClientContext()).thenReturn(SslContext.newClientContext());
- AaiHttpClientFactory cut = new AaiHttpClientFactory(insecureConfiguration(), sslFactory);
-
- cut.build();
-
- verify(sslFactory).createInsecureClientContext();
- verify(sslFactory, never()).createSecureClientContext(any(SecurityKeys.class));
- }
-}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java
index ee428713..7a8d39d1 100644
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java
+++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java
@@ -22,8 +22,8 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http;
import static org.mockito.Mockito.mock;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
@@ -31,7 +31,7 @@ import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
public class AbstractHttpClientTest {
protected final AaiModel aaiModel = () -> "test-id";
- protected final CloudHttpClient httpClient = mock(CloudHttpClient.class);
+ protected final RxHttpClient httpClient = mock(RxHttpClient.class);
protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class);
protected final HttpResponse response = mock(HttpResponse.class);
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java
index d6199acd..ce5d2c95 100644
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java
+++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java
@@ -20,20 +20,18 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -41,19 +39,24 @@ class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest {
@Test
void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() {
+
+ // given
AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class);
- Map<String, String> headers = new HashMap<>();
- AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers), httpClient);
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()),
+ httpClient);
- given(httpClient.get(anyString(), any(RequestDiagnosticContext.class), anyMap()))
+ given(httpClient.call(any(HttpRequest.class)))
.willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(model))
.expectNext(response)
.verifyComplete();
+ //then
verify(httpClient)
- .get(anyString(), any(RequestDiagnosticContext.class), eq(headers));
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java
index 1dddc27e..758ef601 100644
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java
+++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java
@@ -20,19 +20,17 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -40,48 +38,44 @@ class AaiHttpGetClientTest extends AbstractHttpClientTest {
@Test
void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() {
- Map<String, String> headers = new HashMap<>();
- AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers), httpClient);
- given(httpClient.get(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap()
- )).willReturn(Mono.just(response));
+ // given
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers.toJavaMap()), httpClient);
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).get(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(headers)
- );
+ //then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
@Test
void getAaiResponse_shouldCallGetMethod_withProperUri() {
+
+ // given
AaiClientConfiguration configuration = secureConfiguration();
- String expectedUri = constructAaiUri(configuration, aaiModel.getCorrelationId());
+ String uri = constructAaiUri(configuration, aaiModel.getCorrelationId());
AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient);
- given(httpClient.get(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap()
- )).willReturn(Mono.just(response));
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).get(
- eq(expectedUri),
- any(RequestDiagnosticContext.class),
- anyMap()
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
}
}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java
index 302395ac..2def498c 100644
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java
+++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java
@@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.pat
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
@@ -32,6 +33,7 @@ import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
@@ -46,58 +48,52 @@ class AaiHttpPatchClientTest extends AbstractHttpClientTest {
@Test
void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() {
+ // given
Map<String, String> headers = HashMap.of("sample-key", "sample-value");
Map<String, String> expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers);
+
AaiHttpPatchClient cut =
new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient);
- given(httpClient.patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(expectedHeaders.toJavaMap()),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders)));
}
@Test
void getAaiResponse_shouldCallPatchMethod_withProperUri() {
+
+ // given
AaiClientConfiguration configuration = secureConfiguration();
- String expectedUri = constructAaiUri(configuration, aaiModel.getCorrelationId());
+ String uri = constructAaiUri(configuration, aaiModel.getCorrelationId());
AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient);
- given(httpClient.patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).patch(
- eq(expectedUri),
- any(RequestDiagnosticContext.class),
- anyMap(),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
}
}
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java
index 7ce47a00..d14eca18 100644
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java
+++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java
@@ -20,20 +20,17 @@
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.put;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -41,29 +38,23 @@ class AaiHttpPutClientTest extends AbstractHttpClientTest {
@Test
void getAaiResponse_shouldCallPutMethod_withGivenAaiHeaders() {
- Map<String, String> headers = new HashMap<>();
- AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers), bodyBuilder, "", httpClient);
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, "",
+ httpClient);
- given(httpClient.put(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).put(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(headers),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
@Test
@@ -71,25 +62,19 @@ class AaiHttpPutClientTest extends AbstractHttpClientTest {
String uri = "test-uri";
AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(), bodyBuilder, uri, httpClient);
- given(httpClient.put(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).put(
- eq(uri),
- any(RequestDiagnosticContext.class),
- anyMap(),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
+
}
}