From fc36a6eeebbc05d640d20bfe761037e23d20f1e0 Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Thu, 5 Dec 2019 08:58:17 +0100 Subject: Refactor AaiClient API - package structure - Removed redundant get/patch packages - Flattened aii api package structure to 'api' and 'main' Issue-ID: DCAEGEN2-1955 Signed-off-by: Michal Kabaj Change-Id: I9025245f70c5dd0bb03e7289f8bc7dbf08853687 --- .../prh/configuration/AaiHttpClientConfig.java | 10 +-- .../prh/configuration/CbsConfiguration.java | 2 +- .../prh/configuration/CbsContentParser.java | 4 +- .../services/prh/configuration/Config.java | 2 +- .../services/prh/tasks/AaiQueryTaskImpl.java | 4 +- .../services/prh/TestAppConfiguration.java | 2 +- .../ConsulConfigurationParserTest.java | 4 +- .../prh/tasks/AaiProducerTaskImplTest.java | 4 +- .../services/prh/tasks/AaiQueryTaskImplTest.java | 2 +- .../services/prh/tasks/BbsActionsTaskTest.java | 2 +- .../adapter/aai/api/AaiClientConfiguration.java | 88 -------------------- .../aai/api/AaiGetServiceInstanceClient.java | 68 ++++++++++++++++ .../prh/adapter/aai/api/AaiHttpGetClient.java | 54 ++++++++++++ .../prh/adapter/aai/api/AaiHttpPatchClient.java | 65 +++++++++++++++ .../aai/api/AaiServiceInstanceQueryModel.java | 31 +++++++ .../aai/api/get/AaiGetServiceInstanceClient.java | 70 ---------------- .../prh/adapter/aai/api/get/AaiHttpGetClient.java | 55 ------------- .../adapter/aai/api/patch/AaiHttpPatchClient.java | 66 --------------- .../adapter/aai/main/AaiClientConfiguration.java | 88 ++++++++++++++++++++ .../prh/adapter/aai/main/AaiHttpClientFactory.java | 1 - .../aai/model/AaiServiceInstanceQueryModel.java | 31 ------- .../prh/adapter/aai/AaiClientConfigurations.java | 60 -------------- .../prh/adapter/aai/AbstractHttpClientTest.java | 41 ---------- .../adapter/aai/api/AaiClientConfigurations.java | 60 ++++++++++++++ .../aai/api/AaiGetServiceInstanceClientTest.java | 69 ++++++++++++++++ .../prh/adapter/aai/api/AaiHttpGetClientTest.java | 80 ++++++++++++++++++ .../adapter/aai/api/AaiHttpPatchClientTest.java | 93 +++++++++++++++++++++ .../adapter/aai/api/AbstractHttpClientTest.java | 41 ++++++++++ .../aai/get/AaiGetServiceInstanceClientTest.java | 72 ---------------- .../prh/adapter/aai/get/AaiHttpGetClientTest.java | 82 ------------------- .../adapter/aai/patch/AaiHttpPatchClientTest.java | 95 ---------------------- 31 files changed, 667 insertions(+), 679 deletions(-) delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfiguration.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceQueryModel.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiGetServiceInstanceClient.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiClientConfiguration.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiServiceInstanceQueryModel.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AaiClientConfigurations.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfigurations.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AbstractHttpClientTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiGetServiceInstanceClientTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiHttpGetClientTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/patch/AaiHttpPatchClientTest.java diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java index d8f6d966..d05edf44 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java @@ -22,13 +22,13 @@ package org.onap.dcaegen2.services.prh.configuration; import java.nio.charset.StandardCharsets; import java.util.function.BiFunction; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiGetServiceInstanceClient; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiGetServiceInstanceClient; -import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiHttpGetClient; -import org.onap.dcaegen2.services.prh.adapter.aai.api.patch.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpGetClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java index d594222b..8373018d 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsConfiguration.java @@ -22,7 +22,7 @@ package org.onap.dcaegen2.services.prh.configuration; import com.google.gson.JsonObject; import java.util.Optional; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.DmaapClientFactory; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsContentParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsContentParser.java index 869d537f..ed935501 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsContentParser.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CbsContentParser.java @@ -28,8 +28,8 @@ import com.google.gson.JsonObject; import java.nio.file.Paths; import java.time.Duration; import java.util.Map; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.ImmutableAaiClientConfiguration; import org.onap.dcaegen2.services.sdk.model.streams.RawDataStream; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSource; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java index adfc8c16..b1302cbd 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.prh.configuration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java index 9489a501..23cd2dd6 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java @@ -24,8 +24,8 @@ import java.util.List; import java.util.Optional; import java.util.stream.Stream; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; -import org.onap.dcaegen2.services.prh.adapter.aai.model.ImmutableAaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableAaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java index a3f024f4..bb79516e 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java @@ -21,7 +21,7 @@ package org.onap.dcaegen2.services.prh; import java.time.Duration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.ImmutableAaiClientConfiguration; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSink; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSource; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.ContentType; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java index 89717a58..9c65a178 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/ConsulConfigurationParserTest.java @@ -33,8 +33,8 @@ import java.time.Duration; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.prh.TestAppConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.ImmutableAaiClientConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.ContentType; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java index f699a9e4..075cdadd 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java @@ -37,8 +37,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; import org.onap.dcaegen2.services.prh.TestAppConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.patch.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.CbsConfiguration; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java index b2702a9d..3eb883f1 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java @@ -34,7 +34,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java index 44c4509c..fe45262a 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java @@ -44,7 +44,7 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.onap.dcaegen2.services.prh.TestAppConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.CbsConfiguration; import org.onap.dcaegen2.services.prh.exceptions.AaiFailureException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfiguration.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfiguration.java deleted file mode 100644 index 53e76892..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfiguration.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ============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.prh.adapter.aai.api; - -import java.io.Serializable; -import java.util.Map; -import org.immutables.gson.Gson; -import org.immutables.value.Value; - -@Value.Immutable(prehash = true) -@Value.Style(builder = "new") -@Gson.TypeAdapters -public abstract class AaiClientConfiguration implements Serializable { - - private static final String PNF_PATH = "/network/pnfs/pnf"; - private static final String SERVICE_INSTANCE_PATH = "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}"; - - private static final long serialVersionUID = 1L; - - @Value.Parameter - @Value.Default - public String baseUrl() { - return ""; - } - - /** - * Please use baseUrl() instead - */ - @Deprecated - @Value.Default - public String pnfUrl() { - return baseUrl() + PNF_PATH; - } - - @Value.Parameter - public abstract String aaiUserName(); - - @Value.Parameter - public abstract String aaiUserPassword(); - - @Value.Parameter - public abstract Boolean aaiIgnoreSslCertificateErrors(); - - /** - * Please use baseUrl() instead - */ - @Deprecated - @Value.Default - public String aaiServiceInstancePath() { - return SERVICE_INSTANCE_PATH; - } - - @Value.Parameter - public abstract Map aaiHeaders(); - - @Value.Parameter - public abstract String trustStorePath(); - - @Value.Parameter - public abstract String trustStorePasswordPath(); - - @Value.Parameter - public abstract String keyStorePath(); - - @Value.Parameter - public abstract String keyStorePasswordPath(); - - @Value.Parameter - public abstract Boolean enableAaiCertAuth(); -} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java new file mode 100644 index 00000000..c41bb906 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java @@ -0,0 +1,68 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.apache.commons.text.StringSubstitutor; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import reactor.core.publisher.Mono; + +public class AaiGetServiceInstanceClient implements + AaiHttpClient { + + private static final String CUSTOMER = "customer"; + private static final String SERVICE_TYPE = "serviceType"; + private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + + private final RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + + public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration, + final RxHttpClient httpClient) { + this.configuration = configuration; + this.httpClient = httpClient; + } + + @Override + public Mono getAaiResponse(AaiServiceInstanceQueryModel aaiModel) { + final Map mapping = HashMap.of( + CUSTOMER, aaiModel.customerId(), + SERVICE_TYPE, aaiModel.serviceType(), + SERVICE_INSTANCE_ID, aaiModel.serviceInstanceId()); + + final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap()); + final String endpoint = substitutor.replace(configuration.aaiServiceInstancePath()); + + return httpClient.call(ImmutableHttpRequest.builder() + .method(HttpMethod.GET) + .url(configuration.baseUrl() + endpoint) + .customHeaders(HashMap.ofAll(configuration.aaiHeaders())) + .diagnosticContext(createRequestDiagnosticContext()) + .build()); + } +} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java new file mode 100644 index 00000000..d50344ee --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java @@ -0,0 +1,54 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import io.vavr.collection.HashMap; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; +import reactor.core.publisher.Mono; + +public final class AaiHttpGetClient implements AaiHttpClient { + + private final RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + + + public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) { + this.configuration = configuration; + this.httpClient = httpClient; + } + + @Override + public Mono getAaiResponse(ConsumerDmaapModel aaiModel) { + return httpClient.call(ImmutableHttpRequest.builder() + .method(HttpMethod.GET) + .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) + .customHeaders(HashMap.ofAll(configuration.aaiHeaders())) + .diagnosticContext(createRequestDiagnosticContext()) + .build()); + } +} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClient.java new file mode 100644 index 00000000..ab1066aa --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClient.java @@ -0,0 +1,65 @@ +/*- + * ============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.prh.adapter.aai.api; + +import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +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.adapters.http.RxHttpClient; +import reactor.core.publisher.Mono; + +public final class AaiHttpPatchClient implements AaiHttpClient { + + private final static Map CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json"); + + private RxHttpClient httpClient; + private final AaiClientConfiguration configuration; + private final AaiJsonBodyBuilderImpl jsonBodyBuilder; + + + public AaiHttpPatchClient(final AaiClientConfiguration configuration, AaiJsonBodyBuilderImpl jsonBodyBuilder, + RxHttpClient httpClient) { + this.configuration = configuration; + this.jsonBodyBuilder = jsonBodyBuilder; + this.httpClient = httpClient; + } + + public Mono getAaiResponse(ConsumerDmaapModel aaiModel) { + final Map headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders())); + String jsonBody = jsonBodyBuilder.createJsonBody(aaiModel); + + return httpClient.call(ImmutableHttpRequest.builder() + .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) + .customHeaders(headers) + .diagnosticContext(createRequestDiagnosticContext()) + .body(RequestBody.fromString(jsonBody)) + .method(HttpMethod.PATCH) + .build()); + } +} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceQueryModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceQueryModel.java new file mode 100644 index 00000000..8a9a396c --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceQueryModel.java @@ -0,0 +1,31 @@ +/* + * ============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.prh.adapter.aai.api; + +import org.immutables.value.Value; + +@Value.Style(stagedBuilder = true) +@Value.Immutable +public interface AaiServiceInstanceQueryModel { + String customerId(); + String serviceType(); + String serviceInstanceId(); +} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiGetServiceInstanceClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiGetServiceInstanceClient.java deleted file mode 100644 index 89f35154..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiGetServiceInstanceClient.java +++ /dev/null @@ -1,70 +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.prh.adapter.aai.api.get; - -import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.apache.commons.text.StringSubstitutor; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import reactor.core.publisher.Mono; - -public class AaiGetServiceInstanceClient implements - AaiHttpClient { - - private static final String CUSTOMER = "customer"; - private static final String SERVICE_TYPE = "serviceType"; - private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; - - private final RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - - public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration, - final RxHttpClient httpClient) { - this.configuration = configuration; - this.httpClient = httpClient; - } - - @Override - public Mono getAaiResponse(AaiServiceInstanceQueryModel aaiModel) { - final Map mapping = HashMap.of( - CUSTOMER, aaiModel.customerId(), - SERVICE_TYPE, aaiModel.serviceType(), - SERVICE_INSTANCE_ID, aaiModel.serviceInstanceId()); - - final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap()); - final String endpoint = substitutor.replace(configuration.aaiServiceInstancePath()); - - return httpClient.call(ImmutableHttpRequest.builder() - .method(HttpMethod.GET) - .url(configuration.baseUrl() + endpoint) - .customHeaders(HashMap.ofAll(configuration.aaiHeaders())) - .diagnosticContext(createRequestDiagnosticContext()) - .build()); - } -} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java deleted file mode 100644 index 122a6097..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============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.prh.adapter.aai.api.get; - -import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; - -import io.vavr.collection.HashMap; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; -import reactor.core.publisher.Mono; - -public final class AaiHttpGetClient implements AaiHttpClient { - - private final RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - - - public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) { - this.configuration = configuration; - this.httpClient = httpClient; - } - - @Override - public Mono getAaiResponse(ConsumerDmaapModel aaiModel) { - return httpClient.call(ImmutableHttpRequest.builder() - .method(HttpMethod.GET) - .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) - .customHeaders(HashMap.ofAll(configuration.aaiHeaders())) - .diagnosticContext(createRequestDiagnosticContext()) - .build()); - } -} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java deleted file mode 100644 index efae2d54..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java +++ /dev/null @@ -1,66 +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.prh.adapter.aai.api.patch; - -import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory.createRequestDiagnosticContext; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -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.adapters.http.RxHttpClient; -import reactor.core.publisher.Mono; - -public final class AaiHttpPatchClient implements AaiHttpClient { - - private final static Map CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json"); - - private RxHttpClient httpClient; - private final AaiClientConfiguration configuration; - private final AaiJsonBodyBuilderImpl jsonBodyBuilder; - - - public AaiHttpPatchClient(final AaiClientConfiguration configuration, AaiJsonBodyBuilderImpl jsonBodyBuilder, - RxHttpClient httpClient) { - this.configuration = configuration; - this.jsonBodyBuilder = jsonBodyBuilder; - this.httpClient = httpClient; - } - - public Mono getAaiResponse(ConsumerDmaapModel aaiModel) { - final Map headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders())); - String jsonBody = jsonBodyBuilder.createJsonBody(aaiModel); - - return httpClient.call(ImmutableHttpRequest.builder() - .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) - .customHeaders(headers) - .diagnosticContext(createRequestDiagnosticContext()) - .body(RequestBody.fromString(jsonBody)) - .method(HttpMethod.PATCH) - .build()); - } -} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiClientConfiguration.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiClientConfiguration.java new file mode 100644 index 00000000..9b029cf2 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiClientConfiguration.java @@ -0,0 +1,88 @@ +/* + * ============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.prh.adapter.aai.main; + +import java.io.Serializable; +import java.util.Map; +import org.immutables.gson.Gson; +import org.immutables.value.Value; + +@Value.Immutable(prehash = true) +@Value.Style(builder = "new") +@Gson.TypeAdapters +public abstract class AaiClientConfiguration implements Serializable { + + private static final String PNF_PATH = "/network/pnfs/pnf"; + private static final String SERVICE_INSTANCE_PATH = "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}"; + + private static final long serialVersionUID = 1L; + + @Value.Parameter + @Value.Default + public String baseUrl() { + return ""; + } + + /** + * Please use baseUrl() instead + */ + @Deprecated + @Value.Default + public String pnfUrl() { + return baseUrl() + PNF_PATH; + } + + @Value.Parameter + public abstract String aaiUserName(); + + @Value.Parameter + public abstract String aaiUserPassword(); + + @Value.Parameter + public abstract Boolean aaiIgnoreSslCertificateErrors(); + + /** + * Please use baseUrl() instead + */ + @Deprecated + @Value.Default + public String aaiServiceInstancePath() { + return SERVICE_INSTANCE_PATH; + } + + @Value.Parameter + public abstract Map aaiHeaders(); + + @Value.Parameter + public abstract String trustStorePath(); + + @Value.Parameter + public abstract String trustStorePasswordPath(); + + @Value.Parameter + public abstract String keyStorePath(); + + @Value.Parameter + public abstract String keyStorePasswordPath(); + + @Value.Parameter + public abstract Boolean enableAaiCertAuth(); +} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiHttpClientFactory.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiHttpClientFactory.java index 69b5cf83..7005edba 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiHttpClientFactory.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/main/AaiHttpClientFactory.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.prh.adapter.aai.main; import java.nio.file.Paths; import java.util.UUID; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; 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; diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiServiceInstanceQueryModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiServiceInstanceQueryModel.java deleted file mode 100644 index b2819f23..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiServiceInstanceQueryModel.java +++ /dev/null @@ -1,31 +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.prh.adapter.aai.model; - -import org.immutables.value.Value; - -@Value.Style(stagedBuilder = true) -@Value.Immutable -public interface AaiServiceInstanceQueryModel { - String customerId(); - String serviceType(); - String serviceInstanceId(); -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AaiClientConfigurations.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AaiClientConfigurations.java deleted file mode 100644 index 072fa2d4..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AaiClientConfigurations.java +++ /dev/null @@ -1,60 +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.prh.adapter.aai; - -import java.util.HashMap; -import java.util.Map; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableAaiClientConfiguration; - -public final class AaiClientConfigurations { - - private AaiClientConfigurations() { - } - - public static AaiClientConfiguration secureConfiguration() { - return secureConfiguration(new HashMap<>()); - } - - public static AaiClientConfiguration secureConfiguration(Map headers) { - return validConfiguration(headers, true); - } - - public static AaiClientConfiguration insecureConfiguration() { - return validConfiguration(new HashMap<>(), false); - } - - private static AaiClientConfiguration validConfiguration(Map headers, boolean secure) { - return new ImmutableAaiClientConfiguration.Builder() - .baseUrl("https://aai.onap.svc.cluster.local:8443/aai/v12") - .aaiUserName("sample-username") - .aaiUserPassword("sample-password") - .aaiIgnoreSslCertificateErrors(false) - .trustStorePath("/trust.pkcs12") - .trustStorePasswordPath("/trust.pass") - .keyStorePath("/server.pkcs12") - .keyStorePasswordPath("/server.pass") - .enableAaiCertAuth(secure) - .aaiHeaders(headers) - .aaiServiceInstancePath( - "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}") - .build(); - } -} \ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java deleted file mode 100644 index fd9523a9..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java +++ /dev/null @@ -1,41 +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.prh.adapter.aai; - -import static org.mockito.Mockito.mock; - -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; - -public class AbstractHttpClientTest { - - protected final ConsumerDmaapModel aaiModel = mock(ConsumerDmaapModel.class); - protected final RxHttpClient httpClient = mock(RxHttpClient.class); - protected final AaiJsonBodyBuilderImpl bodyBuilder = mock(AaiJsonBodyBuilderImpl.class); - protected final HttpResponse response = mock(HttpResponse.class); - - - protected String constructAaiUri(AaiClientConfiguration configuration, String pnfName) { - return configuration.pnfUrl() + "/" + pnfName; - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfigurations.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfigurations.java new file mode 100644 index 00000000..ab29e02a --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfigurations.java @@ -0,0 +1,60 @@ +/* + * ============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.prh.adapter.aai.api; + +import java.util.HashMap; +import java.util.Map; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.adapter.aai.main.ImmutableAaiClientConfiguration; + +public final class AaiClientConfigurations { + + private AaiClientConfigurations() { + } + + public static AaiClientConfiguration secureConfiguration() { + return secureConfiguration(new HashMap<>()); + } + + public static AaiClientConfiguration secureConfiguration(Map headers) { + return validConfiguration(headers, true); + } + + public static AaiClientConfiguration insecureConfiguration() { + return validConfiguration(new HashMap<>(), false); + } + + private static AaiClientConfiguration validConfiguration(Map headers, boolean secure) { + return new ImmutableAaiClientConfiguration.Builder() + .baseUrl("https://aai.onap.svc.cluster.local:8443/aai/v12") + .aaiUserName("sample-username") + .aaiUserPassword("sample-password") + .aaiIgnoreSslCertificateErrors(false) + .trustStorePath("/trust.pkcs12") + .trustStorePasswordPath("/trust.pass") + .keyStorePath("/server.pkcs12") + .keyStorePasswordPath("/server.pass") + .enableAaiCertAuth(secure) + .aaiHeaders(headers) + .aaiServiceInstancePath( + "/business/customers/customer/${customer}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}") + .build(); + } +} \ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java new file mode 100644 index 00000000..551f93fb --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java @@ -0,0 +1,69 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.mockito.ArgumentMatchers.any; +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.prh.adapter.aai.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest { + + public static final String SERVICE_INSTANCE_PATH = + "https://aai.onap.svc.cluster.local:8443/aai/v12/business/customers/customer/Demonstration/" + + "service-subscriptions/service-subscription/VCPE/service-instances/service-instance/df018f76-7fc8-46ab-8444-7d67e1efc284"; + + @Test + void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { + + // given + AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class); + Map headers = HashMap.of("sample-key", "sample-value"); + AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()), + httpClient); + + given(model.customerId()).willReturn("Demonstration"); + given(model.serviceInstanceId()).willReturn("df018f76-7fc8-46ab-8444-7d67e1efc284"); + given(model.serviceType()).willReturn("VCPE"); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(model)) + .expectNext(response) + .verifyComplete(); + + //then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers) && + httpRequest.url().equals(SERVICE_INSTANCE_PATH))); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java new file mode 100644 index 00000000..f69fca54 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java @@ -0,0 +1,80 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiHttpGetClientTest extends AbstractHttpClientTest { + + @Test + void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { + + // given + Map 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(); + + //then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); + } + + @Test + void getAaiResponse_shouldCallGetMethod_withProperUri() { + + // given + AaiClientConfiguration configuration = secureConfiguration(); + String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); + AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient); + + given(httpClient.call(any(HttpRequest.class))) + .willReturn(Mono.just(response)); + + // when + StepVerifier + .create(cut.getAaiResponse(aaiModel)) + .expectNext(response) + .verifyComplete(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.url().equals(uri))); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClientTest.java new file mode 100644 index 00000000..de53d4d4 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClientTest.java @@ -0,0 +1,93 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.mockito.ArgumentMatchers.any; +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.prh.adapter.aai.api.AaiClientConfigurations.secureConfiguration; + +import io.vavr.collection.HashMap; +import io.vavr.collection.Map; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +class AaiHttpPatchClientTest extends AbstractHttpClientTest { + + private final Map DEFAULT_PATCH_HEADERS = + HashMap.of("Content-Type", "application/merge-patch+json"); + + @Test + void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() { + + // given + Map headers = HashMap.of("sample-key", "sample-value"); + Map expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers); + + AaiHttpPatchClient cut = + new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient); + + 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(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders))); + } + + @Test + void getAaiResponse_shouldCallPatchMethod_withProperUri() { + + // given + AaiClientConfiguration configuration = secureConfiguration(); + String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); + AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient); + + 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(); + + // then + verify(httpClient) + .call(argThat(httpRequest -> httpRequest.url().equals(uri))); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AbstractHttpClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AbstractHttpClientTest.java new file mode 100644 index 00000000..1ccb8cbd --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AbstractHttpClientTest.java @@ -0,0 +1,41 @@ +/* + * ============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.prh.adapter.aai.api; + +import static org.mockito.Mockito.mock; + +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; + +public class AbstractHttpClientTest { + + protected final ConsumerDmaapModel aaiModel = mock(ConsumerDmaapModel.class); + protected final RxHttpClient httpClient = mock(RxHttpClient.class); + protected final AaiJsonBodyBuilderImpl bodyBuilder = mock(AaiJsonBodyBuilderImpl.class); + protected final HttpResponse response = mock(HttpResponse.class); + + + protected String constructAaiUri(AaiClientConfiguration configuration, String pnfName) { + return configuration.pnfUrl() + "/" + pnfName; + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiGetServiceInstanceClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiGetServiceInstanceClientTest.java deleted file mode 100644 index 77317414..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiGetServiceInstanceClientTest.java +++ /dev/null @@ -1,72 +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.prh.adapter.aai.get; - -import static org.mockito.ArgumentMatchers.any; -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.prh.adapter.aai.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.adapter.aai.AbstractHttpClientTest; -import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiGetServiceInstanceClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest { - - public static final String SERVICE_INSTANCE_PATH = - "https://aai.onap.svc.cluster.local:8443/aai/v12/business/customers/customer/Demonstration/" - + "service-subscriptions/service-subscription/VCPE/service-instances/service-instance/df018f76-7fc8-46ab-8444-7d67e1efc284"; - - @Test - void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { - - // given - AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class); - Map headers = HashMap.of("sample-key", "sample-value"); - AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()), - httpClient); - - given(model.customerId()).willReturn("Demonstration"); - given(model.serviceInstanceId()).willReturn("df018f76-7fc8-46ab-8444-7d67e1efc284"); - given(model.serviceType()).willReturn("VCPE"); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(model)) - .expectNext(response) - .verifyComplete(); - - //then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers) && - httpRequest.url().equals(SERVICE_INSTANCE_PATH))); - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiHttpGetClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiHttpGetClientTest.java deleted file mode 100644 index 10fc0f49..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/get/AaiHttpGetClientTest.java +++ /dev/null @@ -1,82 +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.prh.adapter.aai.get; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.onap.dcaegen2.services.prh.adapter.aai.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.adapter.aai.AbstractHttpClientTest; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiHttpGetClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiHttpGetClientTest extends AbstractHttpClientTest { - - @Test - void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() { - - // given - Map 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(); - - //then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers))); - } - - @Test - void getAaiResponse_shouldCallGetMethod_withProperUri() { - - // given - AaiClientConfiguration configuration = secureConfiguration(); - String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); - AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient); - - given(httpClient.call(any(HttpRequest.class))) - .willReturn(Mono.just(response)); - - // when - StepVerifier - .create(cut.getAaiResponse(aaiModel)) - .expectNext(response) - .verifyComplete(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.url().equals(uri))); - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/patch/AaiHttpPatchClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/patch/AaiHttpPatchClientTest.java deleted file mode 100644 index 6493b567..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/patch/AaiHttpPatchClientTest.java +++ /dev/null @@ -1,95 +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.prh.adapter.aai.patch; - -import static org.mockito.ArgumentMatchers.any; -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.prh.adapter.aai.AaiClientConfigurations.secureConfiguration; - -import io.vavr.collection.HashMap; -import io.vavr.collection.Map; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.adapter.aai.AbstractHttpClientTest; -import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.api.patch.AaiHttpPatchClient; -import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class AaiHttpPatchClientTest extends AbstractHttpClientTest { - - private final Map DEFAULT_PATCH_HEADERS = - HashMap.of("Content-Type", "application/merge-patch+json"); - - @Test - void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() { - - // given - Map headers = HashMap.of("sample-key", "sample-value"); - Map expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers); - - AaiHttpPatchClient cut = - new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient); - - 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(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders))); - } - - @Test - void getAaiResponse_shouldCallPatchMethod_withProperUri() { - - // given - AaiClientConfiguration configuration = secureConfiguration(); - String uri = constructAaiUri(configuration, aaiModel.getCorrelationId()); - AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient); - - 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(); - - // then - verify(httpClient) - .call(argThat(httpRequest -> httpRequest.url().equals(uri))); - } -} -- cgit 1.2.3-korg