From 487cbcc2327cb2f578f969d1f133903ae128df89 Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Thu, 5 Dec 2019 14:44:37 +0100 Subject: Refactor AaiClient API - package restructure - Reorganized aaiclient related classes between api/impl/main packages Issue-ID: DCAEGEN2-1955 Signed-off-by: Michal Kabaj Change-Id: Ie68f74cd94a6de0806c192046c1746af25979170 --- .../prh/configuration/AaiHttpClientConfig.java | 14 +- .../prh/service/DmaapConsumerJsonParser.java | 37 ++-- .../services/prh/tasks/AaiProducerTask.java | 2 +- .../services/prh/tasks/AaiProducerTaskImpl.java | 2 +- .../dcaegen2/services/prh/tasks/AaiQueryTask.java | 2 +- .../services/prh/tasks/AaiQueryTaskImpl.java | 6 +- .../services/prh/tasks/BbsActionsTask.java | 2 +- .../services/prh/tasks/BbsActionsTaskImpl.java | 4 +- .../services/prh/tasks/DmaapConsumerTask.java | 2 +- .../services/prh/tasks/DmaapConsumerTaskImpl.java | 2 +- .../services/prh/tasks/DmaapPublisherTask.java | 2 +- .../services/prh/tasks/DmaapPublisherTaskImpl.java | 7 +- .../services/prh/tasks/ScheduledTasks.java | 17 +- .../prh/service/DmaapConsumerJsonParserTest.java | 11 +- .../prh/tasks/AaiProducerTaskImplTest.java | 6 +- .../services/prh/tasks/AaiQueryTaskImplTest.java | 6 +- .../services/prh/tasks/BbsActionsTaskTest.java | 4 +- .../prh/tasks/DmaapPublisherTaskImplTest.java | 10 +- .../services/prh/tasks/ScheduledTasksTest.java | 23 ++- .../aai/api/AaiGetServiceInstanceClient.java | 68 ------- .../prh/adapter/aai/api/AaiHttpGetClient.java | 54 ------ .../prh/adapter/aai/api/AaiHttpPatchClient.java | 65 ------- .../prh/adapter/aai/api/AaiPnfResultModel.java | 208 ++++++++++++++++++++ .../aai/api/AaiServiceInstanceResultModel.java | 211 +++++++++++++++++++++ .../prh/adapter/aai/api/ConsumerDmaapModel.java | 75 ++++++++ .../aai/impl/AaiGetServiceInstanceClient.java | 70 +++++++ .../prh/adapter/aai/impl/AaiHttpGetClient.java | 55 ++++++ .../prh/adapter/aai/impl/AaiHttpPatchClient.java | 65 +++++++ .../adapter/aai/impl/AaiJsonBodyBuilderImpl.java | 59 ++++++ .../adapter/aai/impl/PnfReadyJsonBodyBuilder.java | 49 +++++ .../services/prh/model/AaiJsonBodyBuilderImpl.java | 57 ------ .../services/prh/model/AaiPnfResultModel.java | 206 -------------------- .../prh/model/AaiServiceInstanceResultModel.java | 209 -------------------- .../services/prh/model/ConsumerDmaapModel.java | 75 -------- .../prh/model/PnfReadyJsonBodyBuilder.java | 47 ----- .../adapter/aai/api/AaiClientConfigurations.java | 60 ------ .../aai/api/AaiGetServiceInstanceClientTest.java | 69 ------- .../prh/adapter/aai/api/AaiHttpGetClientTest.java | 80 -------- .../adapter/aai/api/AaiHttpPatchClientTest.java | 93 --------- .../prh/adapter/aai/api/AaiPnfResultModelTest.java | 88 +++++++++ .../aai/api/AaiServiceInstanceResultModelTest.java | 90 +++++++++ .../adapter/aai/api/AbstractHttpClientTest.java | 41 ---- .../adapter/aai/impl/AaiClientConfigurations.java | 60 ++++++ .../aai/impl/AaiGetServiceInstanceClientTest.java | 70 +++++++ .../prh/adapter/aai/impl/AaiHttpGetClientTest.java | 80 ++++++++ .../adapter/aai/impl/AaiHttpPatchClientTest.java | 93 +++++++++ .../adapter/aai/impl/AaiJsonBodyBuilderTest.java | 114 +++++++++++ .../adapter/aai/impl/AbstractHttpClientTest.java | 40 ++++ .../aai/impl/PnfReadyJsonBodyBuilderTest.java | 84 ++++++++ .../services/prh/model/AaiJsonBodyBuilderTest.java | 114 ----------- .../services/prh/model/AaiPnfResultModelTest.java | 87 --------- .../model/AaiServiceInstanceResultModelTest.java | 89 --------- .../prh/model/PnfReadyJsonBodyBuilderTest.java | 82 -------- 53 files changed, 1588 insertions(+), 1578 deletions(-) delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java delete 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/AaiPnfResultModel.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModel.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/ConsumerDmaapModel.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpGetClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpPatchClient.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderImpl.java create mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilder.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java delete mode 100644 prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiClientConfigurations.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java delete 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/AaiPnfResultModelTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModelTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AbstractHttpClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiClientConfigurations.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpGetClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpPatchClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AbstractHttpClientTest.java create mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilderTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java delete mode 100644 prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.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 d05edf44..39369329 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,17 +22,17 @@ 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.AaiGetServiceInstanceClient; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -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.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.AaiGetServiceInstanceClient; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.AaiHttpGetClient; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.AaiJsonBodyBuilderImpl; 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.model.AaiJsonBodyBuilderImpl; -import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; -import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java index 11939b53..f98e952f 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java @@ -20,24 +20,6 @@ package org.onap.dcaegen2.services.prh.service; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import io.vavr.collection.List; -import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.util.Optional; -import java.util.stream.StreamSupport; - import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.ADDITIONAL_FIELDS; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_EVENT_HEADER; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_FORMAT_FOR_JSON_OBJECT; @@ -55,6 +37,23 @@ import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SERIA import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SOURCE_NAME; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SW_VERSION; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import io.vavr.collection.List; +import java.util.Optional; +import java.util.stream.StreamSupport; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + /** * @author Przemysław Wąsala on 5/8/18 @@ -76,7 +75,7 @@ public class DmaapConsumerJsonParser { private JsonObject pnfAdditionalFields; /** - * Extract info from string and create @see {@link org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel}. + * Extract info from string and create @see {@link ConsumerDmaapModel}. * * @param monoMessage - results from DMaaP * @return reactive DMaaPModel diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTask.java index 123eb5a3..35eb948b 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTask.java @@ -20,8 +20,8 @@ package org.onap.dcaegen2.services.prh.tasks; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import reactor.core.publisher.Mono; @FunctionalInterface diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java index fd7f11c0..21c5b54b 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java @@ -21,10 +21,10 @@ package org.onap.dcaegen2.services.prh.tasks; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.HttpUtils; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.slf4j.Logger; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java index b4ab10f0..11ff369a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import reactor.core.publisher.Mono; @FunctionalInterface 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 23cd2dd6..3db4887a 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,11 +24,11 @@ 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.api.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceQueryModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; 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; import org.onap.dcaegen2.services.prh.model.Relationship; import org.onap.dcaegen2.services.prh.model.RelationshipData; import org.onap.dcaegen2.services.prh.model.RelationshipDict; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTask.java index 12e13140..5700c2fc 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTask.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import reactor.core.publisher.Mono; @FunctionalInterface diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskImpl.java index 8b893211..201f1bc0 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskImpl.java @@ -30,10 +30,10 @@ import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMet import com.google.gson.JsonObject; import io.vavr.collection.HashMap; import io.vavr.collection.Map; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiPnfResultModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.configuration.Config; import org.onap.dcaegen2.services.prh.exceptions.AaiFailureException; -import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableRelationshipDict; import org.onap.dcaegen2.services.prh.model.Relationship; import org.onap.dcaegen2.services.prh.model.RelationshipDict; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java index 2deafd8d..52bdfacc 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import reactor.core.publisher.Flux; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index a990e502..4ebfa2ca 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -20,8 +20,8 @@ package org.onap.dcaegen2.services.prh.tasks; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.configuration.Config; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java index 0cdc40ea..ef79f9c9 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java @@ -20,8 +20,8 @@ package org.onap.dcaegen2.services.prh.tasks; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; import reactor.core.publisher.Flux; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java index 2890d195..9769a2c2 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java @@ -20,9 +20,10 @@ package org.onap.dcaegen2.services.prh.tasks; +import java.util.function.Supplier; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.PnfReadyJsonBodyBuilder; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.PnfReadyJsonBodyBuilder; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; @@ -30,8 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; -import java.util.function.Supplier; - /** * @author Przemysław Wąsala on 4/13/18 */ diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java index 0d268003..68a44ebc 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java @@ -20,9 +20,16 @@ package org.onap.dcaegen2.services.prh.tasks; +import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.INSTANCE_UUID; +import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.RESPONSE_CODE; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.function.Predicate; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables; import org.slf4j.Logger; @@ -37,14 +44,6 @@ import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.function.Predicate; - -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.INSTANCE_UUID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.RESPONSE_CODE; - /** * @author Przemysław Wąsala on 3/23/18 */ diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java index 342460e3..9dab7aaa 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java @@ -20,24 +20,23 @@ package org.onap.dcaegen2.services.prh.service; +import static org.mockito.Mockito.spy; + import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.vavr.collection.List; +import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterSubscribeResponse; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeResponse; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.util.Optional; - -import static org.mockito.Mockito.spy; - /** * @author Przemysław Wąsala on 5/8/18 */ 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 075cdadd..17936ae5 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,12 +37,12 @@ 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.AaiHttpPatchClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.impl.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; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; 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 3eb883f1..e81b3746 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,10 +34,10 @@ 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.api.AaiPnfResultModel; 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; +import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableRelationshipData; import org.onap.dcaegen2.services.prh.model.Relationship; import org.onap.dcaegen2.services.prh.model.RelationshipData; 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 fe45262a..bc754bf8 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,11 +44,11 @@ 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.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; 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; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; 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.ImmutableHttpResponse; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java index 7e00a441..37414150 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java @@ -20,6 +20,10 @@ package org.onap.dcaegen2.services.prh.tasks; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; + import com.google.gson.JsonElement; import com.google.gson.JsonParser; import org.junit.jupiter.api.Test; @@ -29,9 +33,9 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSink; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; @@ -40,10 +44,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRo import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; - /** * @author Przemysław Wąsala on 5/17/18 */ diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java index 346421ec..c067cdb6 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java @@ -19,27 +19,26 @@ */ package org.onap.dcaegen2.services.prh.tasks; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import java.util.Collections; +import java.util.Map; +import javax.net.ssl.SSLException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; 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.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import javax.net.ssl.SSLException; -import java.util.Collections; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - @ExtendWith(MockitoExtension.class) class ScheduledTasksTest { private final static ConsumerDmaapModel DMAAP_MODEL = 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 deleted file mode 100644 index c41bb906..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClient.java +++ /dev/null @@ -1,68 +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; - -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 deleted file mode 100644 index d50344ee..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClient.java +++ /dev/null @@ -1,54 +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 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 deleted file mode 100644 index ab1066aa..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClient.java +++ /dev/null @@ -1,65 +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; - -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/AaiPnfResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiPnfResultModel.java new file mode 100644 index 00000000..cae63853 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiPnfResultModel.java @@ -0,0 +1,208 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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 com.google.gson.annotations.SerializedName; +import org.immutables.gson.Gson; +import org.immutables.value.Value; +import org.onap.dcaegen2.services.prh.model.ImmutableRelationship; +import org.onap.dcaegen2.services.prh.model.Relationship; +import org.springframework.lang.Nullable; + + +/** + * PNF represents a physical network function. typically equipment used in the D1 world. in 1607, this will be populated by SDN-C to represent a premises router that a uCPE connects to. But this can be used to represent any physical device that is not an AIC node or uCPE. ###### Related Nodes - TO complex( pnf LocatedIn complex, MANY2ONE) - TO instance-group( pnf MemberOf instance-group, MANY2MANY) - TO zone( pnf LocatedIn zone, MANY2ONE) - FROM configuration( configuration AppliesTo pnf, ONE2MANY) - FROM esr-thirdparty-sdnc( esr-thirdparty-sdnc AppliesTo pnf, ONE2MANY) - FROM generic-vnf( generic-vnf HostedOn pnf, MANY2MANY) - FROM lag-interface (CHILD of pnf, lag-interface BindsTo pnf, MANY2ONE)(1) - FROM logical-link( logical-link BridgedTo pnf, MANY2MANY) - FROM p-interface (CHILD of pnf, p-interface BindsTo pnf, MANY2ONE)(1) - FROM service-instance( service-instance ComposedOf pnf, ONE2MANY) -(1) IF this PNF node is deleted, this FROM node is DELETED also + */ +@Value.Immutable +@Gson.TypeAdapters(fieldNamingStrategy = true) +public interface AaiPnfResultModel { + + /** + * unique name of Physical Network Function. + **/ + @Nullable + @SerializedName("pnf-name") + String getPnfName(); + + /** + * name of Physical Network Function. + **/ + @Nullable + @SerializedName("pnf-name2") + String getPnfName2(); + + /** + * URL to endpoint where AAI can get more details. + **/ + @Nullable + @SerializedName("selflink") + String getSelflink(); + + /** + * source of name2 + **/ + @Nullable + @SerializedName("pnf-name2-source") + String getPnfName2Source(); + + /** + * id of pnf + **/ + @Nullable + @SerializedName("pnf-id") + String getPnfId(); + + /** + * Equipment type. Source of truth should define valid values. + **/ + @Nullable + @SerializedName("equip-type") + String getEquipType(); + + /** + * Equipment vendor. Source of truth should define valid values. + **/ + @Nullable + @SerializedName("equip-vendor") + String getEquipVendor(); + + /** + * Equipment model. Source of truth should define valid values. + **/ + @Nullable + @SerializedName("equip-model") + String getEquipModel(); + + /** + * identifier of managed by ATT or customer + **/ + @Nullable + @SerializedName("management-option") + String getManagementOption(); + + /** + * ipv4-oam-address with new naming convention for IP addresses + **/ + @Nullable + @SerializedName("ipaddress-v4-oam") + String getIpaddressV4Oam(); + + /** + * sw-version is the version of SW for the hosted application on the PNF. + **/ + @Nullable + @SerializedName("sw-version") + String getSwVersion(); + + /** + * Used to indicate whether or not this object is in maintenance mode (maintenance mode = true). This field (in conjunction with prov-status) is used to suppress alarms and vSCL on VNFs/VMs. + **/ + @Nullable + @SerializedName("in-maint") + Boolean isInMaint(); + + /** + * ID of the physical frame (relay rack) where pnf is installed. + **/ + @Nullable + @SerializedName("frame-id") + String getFrameId(); + + /** + * Serial number of the device + **/ + @Nullable + @SerializedName("serial-number") + String getSerialNumber(); + + /** + * IPV4 Loopback 0 address + **/ + @Nullable + @SerializedName("ipaddress-v4-loopback-0") + String getIpaddressV4Loopback0(); + + /** + * IPV6 Loopback 0 address + **/ + @Nullable + @SerializedName("ipaddress-v6-loopback-0") + String getIpaddressV6Loopback0(); + + /** + * IPV4 AIM address + **/ + @Nullable + @SerializedName("ipaddress-v4-aim") + String getIpaddressV4Aim(); + + /** + * IPV6 AIM address + **/ + @Nullable + @SerializedName("ipaddress-v6-aim") + String getIpaddressV6Aim(); + + /** + * IPV6 OAM address + **/ + @Nullable + @SerializedName("ipaddress-v6-oam") + String getIpaddressV6Oam(); + + /** + * CANOPI's inventory status. Only set with values exactly as defined by CANOPI. + **/ + @Nullable + @SerializedName("inv-status") + String getInvStatus(); + + /** + * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete. + **/ + @Nullable + @SerializedName("resource-version") + String getResourceVersion(); + + /** + * Prov Status of this device (not under canopi control) Valid values [PREPROV/NVTPROV/PROV] + **/ + @Nullable + @SerializedName("prov-status") + String getProvStatus(); + + /** + * Nf Role is the role performed by this instance in the network. + **/ + @Nullable + @SerializedName("nf-role") + String getNfRole(); + + /** + * Get relationshipList + **/ + @SerializedName("relationship-list") + @Value.Default + default Relationship getRelationshipList() { + return ImmutableRelationship.builder().build(); + } +} + diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModel.java new file mode 100644 index 00000000..f74c1a5a --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModel.java @@ -0,0 +1,211 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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 com.google.gson.annotations.SerializedName; +import org.immutables.gson.Gson; +import org.immutables.value.Value; +import org.onap.dcaegen2.services.prh.model.ImmutableRelationship; +import org.onap.dcaegen2.services.prh.model.Relationship; +import org.springframework.lang.Nullable; + +@Value.Immutable +@Gson.TypeAdapters(fieldNamingStrategy = true) +public interface AaiServiceInstanceResultModel { + + /** + * Uniquely identifies this instance of a service + **/ + @Nullable + @SerializedName("service-instance-id") + String getServiceInstanceId(); + + /** + * This field will store a name assigned to the service-instance. + **/ + @Nullable + @SerializedName("service-instance-name") + String getServiceInstanceName(); + + /** + * String capturing type of service. + **/ + @Nullable + @SerializedName("service-type") + String getServiceType(); + + /** + * String capturing the service role. + **/ + @Nullable + @SerializedName("service-role") + String getServiceRole(); + + /** + * This field will store the environment context assigned to the service-instance. + **/ + @Nullable + @SerializedName("environment-context") + String getEnvironmentContext(); + + /** + * This field will store the workload context assigned to the service-instance. + **/ + @Nullable + @SerializedName("workload-context") + String getWorkloadContext(); + + /** + * createGson time of Network Service. + **/ + @Nullable + @SerializedName("created-at") + String getCreatedAt(); + + /** + * last update of Network Service. + **/ + @Nullable + @SerializedName("updated-at") + String getUpdatedAt(); + + /** + * short description for service-instance. + **/ + @Nullable + @SerializedName("description") + String getDescription(); + + /** + * the ASDC model id for this resource or service model. + **/ + @Nullable + @SerializedName("model-invariant-id") + String getModelInvariantId(); + + /** + * the ASDC model version for this resource or service model. + **/ + @Nullable + @SerializedName("model-version-id") + String getModelVersionId(); + + /** + * the ASDC model version for this resource or service model. + **/ + @Nullable + @SerializedName("persona-model-version") + String getPersonaModelVersion(); + + /** + * the ASDC data dictionary widget model. This maps directly to the A&AI widget. + **/ + @Nullable + @SerializedName("widget-model-id") + String getWidgetModelId(); + + /** + * the ASDC data dictionary version of the widget model.This maps directly to the A&AI version of the widget. + **/ + @Nullable + @SerializedName("widget-model-version") + String getWidgetModelVersion(); + + /** + * Indicates the total bandwidth to be used for this service. + **/ + @Nullable + @SerializedName("bandwidth-total") + String getBandwidthTotal(); + + /** + * indicates the upstream bandwidth this service will use on the WAN1 port of the physical device. + **/ + @Nullable + @SerializedName("bandwidth-up-wan1") + String getBandwidthUpWan1(); + + /** + * indicates the downstream bandwidth this service will use on the WAN1 port of the physical device. + **/ + @Nullable + @SerializedName("bandwidth-down-wan1") + String getBandwidthDownWan1(); + + /** + * indicates the upstream bandwidth this service will use on the WAN2 port of the physical device. + **/ + @Nullable + @SerializedName("bandwidth-up-wan2") + String getBandwidthUpWan2(); + + /** + * indicates the downstream bandwidth this service will use on the WAN2 port of the physical device. + **/ + @Nullable + @SerializedName("bandwidth-down-wan2") + String getBandwidthDownWan2(); + + /** + * URL customers will use to access the vHN Portal. + **/ + @Nullable + @SerializedName("vhn-portal-url") + String getVhnPortalUrl(); + + /** + * An identifier that customers assign to the location where this service is being used. + **/ + @Nullable + @SerializedName("service-instance-location-id") + String getServiceInstanceLocationId(); + + /** + * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete. + **/ + @Nullable + @SerializedName("resource-version") + String getResourceVersion(); + + /** + * Path to the controller object. + **/ + @Nullable + @SerializedName("selflink") + String getSelflink(); + + /** + * Orchestration status of this service. + **/ + @Nullable + @SerializedName("orchestration-status") + String getOrchestrationStatus(); + + /** + * Get relationshipList + **/ + @SerializedName("relationship-list") + @Value.Default + default Relationship getRelationshipList() { + return ImmutableRelationship.builder().build(); + } + +} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/ConsumerDmaapModel.java new file mode 100644 index 00000000..4d417a5e --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/ConsumerDmaapModel.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * 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 com.google.gson.JsonObject; +import com.google.gson.annotations.SerializedName; +import org.immutables.gson.Gson; +import org.immutables.value.Value; +import org.springframework.lang.Nullable; + +/** + * @author Przemysław Wąsala on 5/8/18 + */ + +@Value.Immutable +@Gson.TypeAdapters(fieldNamingStrategy = true) +public interface ConsumerDmaapModel { + + @SerializedName(value = "correlationId", alternate = "correlationId") + String getCorrelationId(); + + @Nullable + @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam") + String getIpv4(); + + @Nullable + @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam") + String getIpv6(); + + @Nullable + @SerializedName(value = "serial-number", alternate = "serial-number") + String getSerialNumber(); + + @Nullable + @SerializedName(value = "equip-vendor", alternate = "equip-vendor") + String getEquipVendor(); + + @Nullable + @SerializedName(value = "equip-model", alternate = "equip-model") + String getEquipModel(); + + @Nullable + @SerializedName(value = "equip-type", alternate = "equip-type") + String getEquipType(); + + @Nullable + @SerializedName(value = "nf-role", alternate = "nf-role") + String getNfRole(); + + @Nullable + @SerializedName(value = "sw-version", alternate = "sw-version") + String getSwVersion(); + + @Nullable + @SerializedName(value = "additionalFields", alternate = "additionalFields") + JsonObject getAdditionalFields(); +} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClient.java new file mode 100644 index 00000000..26fb8491 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClient.java @@ -0,0 +1,70 @@ +/* + * ============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.impl; + +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.AaiHttpClient; +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.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/impl/AaiHttpGetClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpGetClient.java new file mode 100644 index 00000000..2ae28089 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpGetClient.java @@ -0,0 +1,55 @@ +/* + * ============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.impl; + +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.AaiHttpClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +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 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/impl/AaiHttpPatchClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpPatchClient.java new file mode 100644 index 00000000..38ee680a --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/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.impl; + +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.AaiHttpClient; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +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.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/impl/AaiJsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderImpl.java new file mode 100644 index 00000000..21277e85 --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderImpl.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * 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.impl; + +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapterFactory; +import java.util.ServiceLoader; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel.Builder; +import org.springframework.util.StringUtils; + + +public class AaiJsonBodyBuilderImpl { + + public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { + GsonBuilder gsonBuilder = new GsonBuilder(); + ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); + + Builder builder = ImmutableConsumerDmaapModel.builder() + .correlationId(consumerDmaapModel.getCorrelationId()) + .serialNumber(consumerDmaapModel.getSerialNumber()) + .equipVendor(consumerDmaapModel.getEquipVendor()) + .equipModel(consumerDmaapModel.getEquipModel()) + .equipType(consumerDmaapModel.getEquipType()) + .nfRole(consumerDmaapModel.getNfRole()) + .swVersion(consumerDmaapModel.getSwVersion()) + .additionalFields(consumerDmaapModel.getAdditionalFields()); + + String ipv4 = consumerDmaapModel.getIpv4(); + if (!StringUtils.isEmpty(ipv4)) { + builder.ipv4(ipv4); + } + String ipv6 = consumerDmaapModel.getIpv6(); + if (!StringUtils.isEmpty(ipv6)) { + builder.ipv6(ipv6); + } + + return gsonBuilder.create().toJson(builder.build()); + } +} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilder.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilder.java new file mode 100644 index 00000000..3088226e --- /dev/null +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilder.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.impl; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel.Builder; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + + +public class PnfReadyJsonBodyBuilder { + + /** + * Method for serialization object by GSON. + * + * @param consumerDmaapModel - object which will be serialized + * @return string from serialization + */ + public JsonElement createJsonBody(ConsumerDmaapModel consumerDmaapModel) { + Builder builder = ImmutableConsumerDmaapModel.builder() + .correlationId(consumerDmaapModel.getCorrelationId()); + + JsonObject additionalFields = consumerDmaapModel.getAdditionalFields(); + if(additionalFields != null && !additionalFields.equals(new JsonObject())) { + builder.additionalFields(additionalFields); + } + return PrhModelAwareGsonBuilder.createGson().toJsonTree(builder.build()); + } +} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java deleted file mode 100644 index 43e4ebbe..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * 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.model; - -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapterFactory; -import java.util.ServiceLoader; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder; -import org.springframework.util.StringUtils; - - -public class AaiJsonBodyBuilderImpl { - - public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { - GsonBuilder gsonBuilder = new GsonBuilder(); - ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); - - Builder builder = ImmutableConsumerDmaapModel.builder() - .correlationId(consumerDmaapModel.getCorrelationId()) - .serialNumber(consumerDmaapModel.getSerialNumber()) - .equipVendor(consumerDmaapModel.getEquipVendor()) - .equipModel(consumerDmaapModel.getEquipModel()) - .equipType(consumerDmaapModel.getEquipType()) - .nfRole(consumerDmaapModel.getNfRole()) - .swVersion(consumerDmaapModel.getSwVersion()) - .additionalFields(consumerDmaapModel.getAdditionalFields()); - - String ipv4 = consumerDmaapModel.getIpv4(); - if (!StringUtils.isEmpty(ipv4)) { - builder.ipv4(ipv4); - } - String ipv6 = consumerDmaapModel.getIpv6(); - if (!StringUtils.isEmpty(ipv6)) { - builder.ipv6(ipv6); - } - - return gsonBuilder.create().toJson(builder.build()); - } -} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java deleted file mode 100644 index 424d7f83..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 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.model; - -import com.google.gson.annotations.SerializedName; -import org.immutables.gson.Gson; -import org.immutables.value.Value; -import org.springframework.lang.Nullable; - - -/** - * PNF represents a physical network function. typically equipment used in the D1 world. in 1607, this will be populated by SDN-C to represent a premises router that a uCPE connects to. But this can be used to represent any physical device that is not an AIC node or uCPE. ###### Related Nodes - TO complex( pnf LocatedIn complex, MANY2ONE) - TO instance-group( pnf MemberOf instance-group, MANY2MANY) - TO zone( pnf LocatedIn zone, MANY2ONE) - FROM configuration( configuration AppliesTo pnf, ONE2MANY) - FROM esr-thirdparty-sdnc( esr-thirdparty-sdnc AppliesTo pnf, ONE2MANY) - FROM generic-vnf( generic-vnf HostedOn pnf, MANY2MANY) - FROM lag-interface (CHILD of pnf, lag-interface BindsTo pnf, MANY2ONE)(1) - FROM logical-link( logical-link BridgedTo pnf, MANY2MANY) - FROM p-interface (CHILD of pnf, p-interface BindsTo pnf, MANY2ONE)(1) - FROM service-instance( service-instance ComposedOf pnf, ONE2MANY) -(1) IF this PNF node is deleted, this FROM node is DELETED also - */ -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface AaiPnfResultModel { - - /** - * unique name of Physical Network Function. - **/ - @Nullable - @SerializedName("pnf-name") - String getPnfName(); - - /** - * name of Physical Network Function. - **/ - @Nullable - @SerializedName("pnf-name2") - String getPnfName2(); - - /** - * URL to endpoint where AAI can get more details. - **/ - @Nullable - @SerializedName("selflink") - String getSelflink(); - - /** - * source of name2 - **/ - @Nullable - @SerializedName("pnf-name2-source") - String getPnfName2Source(); - - /** - * id of pnf - **/ - @Nullable - @SerializedName("pnf-id") - String getPnfId(); - - /** - * Equipment type. Source of truth should define valid values. - **/ - @Nullable - @SerializedName("equip-type") - String getEquipType(); - - /** - * Equipment vendor. Source of truth should define valid values. - **/ - @Nullable - @SerializedName("equip-vendor") - String getEquipVendor(); - - /** - * Equipment model. Source of truth should define valid values. - **/ - @Nullable - @SerializedName("equip-model") - String getEquipModel(); - - /** - * identifier of managed by ATT or customer - **/ - @Nullable - @SerializedName("management-option") - String getManagementOption(); - - /** - * ipv4-oam-address with new naming convention for IP addresses - **/ - @Nullable - @SerializedName("ipaddress-v4-oam") - String getIpaddressV4Oam(); - - /** - * sw-version is the version of SW for the hosted application on the PNF. - **/ - @Nullable - @SerializedName("sw-version") - String getSwVersion(); - - /** - * Used to indicate whether or not this object is in maintenance mode (maintenance mode = true). This field (in conjunction with prov-status) is used to suppress alarms and vSCL on VNFs/VMs. - **/ - @Nullable - @SerializedName("in-maint") - Boolean isInMaint(); - - /** - * ID of the physical frame (relay rack) where pnf is installed. - **/ - @Nullable - @SerializedName("frame-id") - String getFrameId(); - - /** - * Serial number of the device - **/ - @Nullable - @SerializedName("serial-number") - String getSerialNumber(); - - /** - * IPV4 Loopback 0 address - **/ - @Nullable - @SerializedName("ipaddress-v4-loopback-0") - String getIpaddressV4Loopback0(); - - /** - * IPV6 Loopback 0 address - **/ - @Nullable - @SerializedName("ipaddress-v6-loopback-0") - String getIpaddressV6Loopback0(); - - /** - * IPV4 AIM address - **/ - @Nullable - @SerializedName("ipaddress-v4-aim") - String getIpaddressV4Aim(); - - /** - * IPV6 AIM address - **/ - @Nullable - @SerializedName("ipaddress-v6-aim") - String getIpaddressV6Aim(); - - /** - * IPV6 OAM address - **/ - @Nullable - @SerializedName("ipaddress-v6-oam") - String getIpaddressV6Oam(); - - /** - * CANOPI's inventory status. Only set with values exactly as defined by CANOPI. - **/ - @Nullable - @SerializedName("inv-status") - String getInvStatus(); - - /** - * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete. - **/ - @Nullable - @SerializedName("resource-version") - String getResourceVersion(); - - /** - * Prov Status of this device (not under canopi control) Valid values [PREPROV/NVTPROV/PROV] - **/ - @Nullable - @SerializedName("prov-status") - String getProvStatus(); - - /** - * Nf Role is the role performed by this instance in the network. - **/ - @Nullable - @SerializedName("nf-role") - String getNfRole(); - - /** - * Get relationshipList - **/ - @SerializedName("relationship-list") - @Value.Default - default Relationship getRelationshipList() { - return ImmutableRelationship.builder().build(); - } -} - diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java deleted file mode 100644 index 67d6ff90..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 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.model; - -import com.google.gson.annotations.SerializedName; -import org.immutables.gson.Gson; -import org.immutables.value.Value; -import org.springframework.lang.Nullable; - -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface AaiServiceInstanceResultModel { - - /** - * Uniquely identifies this instance of a service - **/ - @Nullable - @SerializedName("service-instance-id") - String getServiceInstanceId(); - - /** - * This field will store a name assigned to the service-instance. - **/ - @Nullable - @SerializedName("service-instance-name") - String getServiceInstanceName(); - - /** - * String capturing type of service. - **/ - @Nullable - @SerializedName("service-type") - String getServiceType(); - - /** - * String capturing the service role. - **/ - @Nullable - @SerializedName("service-role") - String getServiceRole(); - - /** - * This field will store the environment context assigned to the service-instance. - **/ - @Nullable - @SerializedName("environment-context") - String getEnvironmentContext(); - - /** - * This field will store the workload context assigned to the service-instance. - **/ - @Nullable - @SerializedName("workload-context") - String getWorkloadContext(); - - /** - * createGson time of Network Service. - **/ - @Nullable - @SerializedName("created-at") - String getCreatedAt(); - - /** - * last update of Network Service. - **/ - @Nullable - @SerializedName("updated-at") - String getUpdatedAt(); - - /** - * short description for service-instance. - **/ - @Nullable - @SerializedName("description") - String getDescription(); - - /** - * the ASDC model id for this resource or service model. - **/ - @Nullable - @SerializedName("model-invariant-id") - String getModelInvariantId(); - - /** - * the ASDC model version for this resource or service model. - **/ - @Nullable - @SerializedName("model-version-id") - String getModelVersionId(); - - /** - * the ASDC model version for this resource or service model. - **/ - @Nullable - @SerializedName("persona-model-version") - String getPersonaModelVersion(); - - /** - * the ASDC data dictionary widget model. This maps directly to the A&AI widget. - **/ - @Nullable - @SerializedName("widget-model-id") - String getWidgetModelId(); - - /** - * the ASDC data dictionary version of the widget model.This maps directly to the A&AI version of the widget. - **/ - @Nullable - @SerializedName("widget-model-version") - String getWidgetModelVersion(); - - /** - * Indicates the total bandwidth to be used for this service. - **/ - @Nullable - @SerializedName("bandwidth-total") - String getBandwidthTotal(); - - /** - * indicates the upstream bandwidth this service will use on the WAN1 port of the physical device. - **/ - @Nullable - @SerializedName("bandwidth-up-wan1") - String getBandwidthUpWan1(); - - /** - * indicates the downstream bandwidth this service will use on the WAN1 port of the physical device. - **/ - @Nullable - @SerializedName("bandwidth-down-wan1") - String getBandwidthDownWan1(); - - /** - * indicates the upstream bandwidth this service will use on the WAN2 port of the physical device. - **/ - @Nullable - @SerializedName("bandwidth-up-wan2") - String getBandwidthUpWan2(); - - /** - * indicates the downstream bandwidth this service will use on the WAN2 port of the physical device. - **/ - @Nullable - @SerializedName("bandwidth-down-wan2") - String getBandwidthDownWan2(); - - /** - * URL customers will use to access the vHN Portal. - **/ - @Nullable - @SerializedName("vhn-portal-url") - String getVhnPortalUrl(); - - /** - * An identifier that customers assign to the location where this service is being used. - **/ - @Nullable - @SerializedName("service-instance-location-id") - String getServiceInstanceLocationId(); - - /** - * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete. - **/ - @Nullable - @SerializedName("resource-version") - String getResourceVersion(); - - /** - * Path to the controller object. - **/ - @Nullable - @SerializedName("selflink") - String getSelflink(); - - /** - * Orchestration status of this service. - **/ - @Nullable - @SerializedName("orchestration-status") - String getOrchestrationStatus(); - - /** - * Get relationshipList - **/ - @SerializedName("relationship-list") - @Value.Default - default Relationship getRelationshipList() { - return ImmutableRelationship.builder().build(); - } - -} \ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java deleted file mode 100644 index 9ed36823..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * 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.model; - -import com.google.gson.JsonObject; -import com.google.gson.annotations.SerializedName; -import org.immutables.gson.Gson; -import org.immutables.value.Value; -import org.springframework.lang.Nullable; - -/** - * @author Przemysław Wąsala on 5/8/18 - */ - -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface ConsumerDmaapModel { - - @SerializedName(value = "correlationId", alternate = "correlationId") - String getCorrelationId(); - - @Nullable - @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam") - String getIpv4(); - - @Nullable - @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam") - String getIpv6(); - - @Nullable - @SerializedName(value = "serial-number", alternate = "serial-number") - String getSerialNumber(); - - @Nullable - @SerializedName(value = "equip-vendor", alternate = "equip-vendor") - String getEquipVendor(); - - @Nullable - @SerializedName(value = "equip-model", alternate = "equip-model") - String getEquipModel(); - - @Nullable - @SerializedName(value = "equip-type", alternate = "equip-type") - String getEquipType(); - - @Nullable - @SerializedName(value = "nf-role", alternate = "nf-role") - String getNfRole(); - - @Nullable - @SerializedName(value = "sw-version", alternate = "sw-version") - String getSwVersion(); - - @Nullable - @SerializedName(value = "additionalFields", alternate = "additionalFields") - JsonObject getAdditionalFields(); -} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java deleted file mode 100644 index b39c4690..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 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.model; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder; -import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; - - -public class PnfReadyJsonBodyBuilder { - - /** - * Method for serialization object by GSON. - * - * @param consumerDmaapModel - object which will be serialized - * @return string from serialization - */ - public JsonElement createJsonBody(ConsumerDmaapModel consumerDmaapModel) { - Builder builder = ImmutableConsumerDmaapModel.builder() - .correlationId(consumerDmaapModel.getCorrelationId()); - - JsonObject additionalFields = consumerDmaapModel.getAdditionalFields(); - if(additionalFields != null && !additionalFields.equals(new JsonObject())) { - builder.additionalFields(additionalFields); - } - return PrhModelAwareGsonBuilder.createGson().toJsonTree(builder.build()); - } -} \ No newline at end of file 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 deleted file mode 100644 index ab29e02a..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/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.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 deleted file mode 100644 index 551f93fb..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiGetServiceInstanceClientTest.java +++ /dev/null @@ -1,69 +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; - -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 deleted file mode 100644 index f69fca54..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpGetClientTest.java +++ /dev/null @@ -1,80 +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; - -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 deleted file mode 100644 index de53d4d4..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiHttpPatchClientTest.java +++ /dev/null @@ -1,93 +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; - -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/AaiPnfResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiPnfResultModelTest.java new file mode 100644 index 00000000..aa193e8a --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiPnfResultModelTest.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * 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.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import java.io.InputStreamReader; +import java.util.Objects; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.RelationshipData; +import org.onap.dcaegen2.services.prh.model.RelationshipDict; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +class AaiPnfResultModelTest { + + @Test + void shouldParseAaiPnf() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson(new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_pnf.json"))), AaiPnfResultModel.class); + + assertThat(pnf.getPnfName()).isEqualTo("some pnfName"); + assertThat(pnf.getPnfName2()).isEqualTo("some pnfName2"); + assertThat(pnf.getSelflink()).isEqualTo("some selflink"); + assertThat(pnf.getPnfName2Source()).isEqualTo("some pnfName2Source"); + assertThat(pnf.getPnfId()).isEqualTo("some pnfId"); + assertThat(pnf.getEquipType()).isEqualTo("some equipType"); + assertThat(pnf.getEquipVendor()).isEqualTo("some equipVendor"); + assertThat(pnf.getEquipModel()).isEqualTo("some equipModel"); + assertThat(pnf.getManagementOption()).isEqualTo("some managementOption"); + assertThat(pnf.getIpaddressV4Oam()).isEqualTo("some ipaddressV4Oam"); + assertThat(pnf.getSwVersion()).isEqualTo("some swVersion"); + assertThat(pnf.isInMaint()).isFalse(); + assertThat(pnf.getFrameId()).isEqualTo("some frameId"); + assertThat(pnf.getSerialNumber()).isEqualTo("some serialNumber"); + assertThat(pnf.getIpaddressV4Loopback0()).isEqualTo("some ipaddressV4Loopback0"); + assertThat(pnf.getIpaddressV6Loopback0()).isEqualTo("some ipaddressV6Loopback0"); + assertThat(pnf.getIpaddressV4Aim()).isEqualTo("some ipaddressV4Aim"); + assertThat(pnf.getIpaddressV6Aim()).isEqualTo("some ipaddressV6Aim"); + assertThat(pnf.getIpaddressV6Oam()).isEqualTo("some ipaddressV6Oam"); + assertThat(pnf.getInvStatus()).isEqualTo("some invStatus"); + assertThat(pnf.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(pnf.getProvStatus()).isEqualTo("some provStatus"); + assertThat(pnf.getNfRole()).isEqualTo("some nfRole"); + + assertThat(pnf.getRelationshipList().getRelationship()).hasSize(1); + RelationshipDict relationshipDict = pnf.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); + } + + @Test + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson("{}", AaiPnfResultModel.class); + assertThat(pnf.getRelationshipList()).isNotNull(); + assertThat(pnf.getRelationshipList().getRelationship()).isEmpty(); + } + + @Test + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiPnfResultModel.class); + } + +} \ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModelTest.java new file mode 100644 index 00000000..278e8b53 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiServiceInstanceResultModelTest.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * 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.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import java.io.InputStreamReader; +import java.util.Objects; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.RelationshipData; +import org.onap.dcaegen2.services.prh.model.RelationshipDict; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +class AaiServiceInstanceResultModelTest { + + @Test + void shouldParseAaiServiceInstance() { + AaiServiceInstanceResultModel serviceInstance = PrhModelAwareGsonBuilder.createGson().fromJson( + new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_service_instance.json"))), + AaiServiceInstanceResultModel.class); + + assertThat(serviceInstance.getServiceInstanceId()).isEqualTo("some serviceInstanceId"); + assertThat(serviceInstance.getServiceInstanceName()).isEqualTo("some serviceInstanceName"); + assertThat(serviceInstance.getServiceType()).isEqualTo("some serviceType"); + assertThat(serviceInstance.getServiceRole()).isEqualTo("some serviceRole"); + assertThat(serviceInstance.getEnvironmentContext()).isEqualTo("some environmentContext"); + assertThat(serviceInstance.getWorkloadContext()).isEqualTo("some workloadContext"); + assertThat(serviceInstance.getCreatedAt()).isEqualTo("some createdAt"); + assertThat(serviceInstance.getUpdatedAt()).isEqualTo("some updatedAt"); + assertThat(serviceInstance.getDescription()).isEqualTo("some description"); + assertThat(serviceInstance.getModelInvariantId()).isEqualTo("some modelInvariantId"); + assertThat(serviceInstance.getModelVersionId()).isEqualTo("some modelVersionId"); + assertThat(serviceInstance.getPersonaModelVersion()).isEqualTo("some personaModelVersion"); + assertThat(serviceInstance.getWidgetModelId()).isEqualTo("some widgetModelId"); + assertThat(serviceInstance.getWidgetModelVersion()).isEqualTo("some widgetModelVersion"); + assertThat(serviceInstance.getBandwidthTotal()).isEqualTo("some bandwidthTotal"); + assertThat(serviceInstance.getBandwidthUpWan1()).isEqualTo("some bandwidthUpWan1"); + assertThat(serviceInstance.getBandwidthDownWan1()).isEqualTo("some bandwidthDownWan1"); + assertThat(serviceInstance.getBandwidthUpWan2()).isEqualTo("some bandwidthUpWan2"); + assertThat(serviceInstance.getBandwidthDownWan2()).isEqualTo("some bandwidthDownWan2"); + assertThat(serviceInstance.getVhnPortalUrl()).isEqualTo("some vhnPortalUrl"); + assertThat(serviceInstance.getServiceInstanceLocationId()).isEqualTo("some serviceInstanceLocationId"); + assertThat(serviceInstance.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(serviceInstance.getSelflink()).isEqualTo("some selflink"); + assertThat(serviceInstance.getOrchestrationStatus()).isEqualTo("some orchestrationStatus"); + + RelationshipDict relationshipDict = serviceInstance.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); + } + + + @Test + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiServiceInstanceResultModel serviceInstance = gson.fromJson("{}", AaiServiceInstanceResultModel.class); + assertThat(serviceInstance.getRelationshipList()).isNotNull(); + assertThat(serviceInstance.getRelationshipList().getRelationship()).isEmpty(); + } + + @Test + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiServiceInstanceResultModel.class); + } + +} \ No newline at end of file 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 deleted file mode 100644 index 1ccb8cbd..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/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.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/impl/AaiClientConfigurations.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiClientConfigurations.java new file mode 100644 index 00000000..fa04804b --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/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.impl; + +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/impl/AaiGetServiceInstanceClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClientTest.java new file mode 100644 index 00000000..9c7ce60b --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiGetServiceInstanceClientTest.java @@ -0,0 +1,70 @@ +/* + * ============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.impl; + +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.impl.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.api.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/impl/AaiHttpGetClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpGetClientTest.java new file mode 100644 index 00000000..a751584b --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/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.impl; + +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.impl.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/impl/AaiHttpPatchClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiHttpPatchClientTest.java new file mode 100644 index 00000000..18e235dc --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/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.impl; + +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.impl.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/impl/AaiJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderTest.java new file mode 100644 index 00000000..de0a2cff --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AaiJsonBodyBuilderTest.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; + +class AaiJsonBodyBuilderTest { + + @Test + void createJsonBody_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .ipv4("256.22.33.155") + .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4-oam\":\"256.22.33.155\"," + + "\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } + + @Test + void createJsonBodyWithoutIPs_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } + + @Test + void createJsonBodyWithEmptyIPs_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .ipv4("") + .ipv6("") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AbstractHttpClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AbstractHttpClientTest.java new file mode 100644 index 00000000..fe908882 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/AbstractHttpClientTest.java @@ -0,0 +1,40 @@ +/* + * ============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.impl; + +import static org.mockito.Mockito.mock; + +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiClientConfiguration; +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/impl/PnfReadyJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilderTest.java new file mode 100644 index 00000000..5c3d9e06 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/impl/PnfReadyJsonBodyBuilderTest.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 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.impl; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel; + +class PnfReadyJsonBodyBuilderTest { + + @Test + void createJsonBody_shouldReturnJsonInString() { + + JsonObject jsonObject = parse("{\n" + + " \"attachmentPoint\": \"bla-bla-30-3\",\n" + + " \"cvlan\": \"678\",\n" + + " \"svlan\": \"1005\"\n" + + " }"); + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .additionalFields(jsonObject) + .build(); + + JsonObject expectedResult = parse("{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"additionalFields\":{\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}" + + "}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + @Test + void createJsonBodyWithNullableFieldsNotSet_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .build(); + + JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + @Test + void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() { + JsonObject jsonObject = new JsonObject(); + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .additionalFields(jsonObject) + .build(); + + JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + private static JsonObject parse(String jsonString) { + return new JsonParser().parse(jsonString).getAsJsonObject(); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java deleted file mode 100644 index 60ce520c..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 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.model; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.junit.jupiter.api.Test; - -class AaiJsonBodyBuilderTest { - - @Test - void createJsonBody_shouldReturnJsonInString() { - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .ipv4("256.22.33.155") - .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334") - .serialNumber("1234") - .equipVendor("NOKIA") - .equipModel("3310") - .equipType("cell") - .nfRole("role") - .swVersion("1.2.3") - .build(); - - String expectedResult = "{" - + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"ipaddress-v4-oam\":\"256.22.33.155\"," - + "\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"," - + "\"serial-number\":\"1234\"," - + "\"equip-vendor\":\"NOKIA\"," - + "\"equip-model\":\"3310\"," - + "\"equip-type\":\"cell\"," - + "\"nf-role\":\"role\"," - + "\"sw-version\":\"1.2.3\"" - + "}"; - - assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); - } - - @Test - void createJsonBodyWithoutIPs_shouldReturnJsonInString() { - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .serialNumber("1234") - .equipVendor("NOKIA") - .equipModel("3310") - .equipType("cell") - .nfRole("role") - .swVersion("1.2.3") - .build(); - - String expectedResult = "{" - + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"serial-number\":\"1234\"," - + "\"equip-vendor\":\"NOKIA\"," - + "\"equip-model\":\"3310\"," - + "\"equip-type\":\"cell\"," - + "\"nf-role\":\"role\"," - + "\"sw-version\":\"1.2.3\"" - + "}"; - - assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); - } - - @Test - void createJsonBodyWithEmptyIPs_shouldReturnJsonInString() { - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .ipv4("") - .ipv6("") - .serialNumber("1234") - .equipVendor("NOKIA") - .equipModel("3310") - .equipType("cell") - .nfRole("role") - .swVersion("1.2.3") - .build(); - - String expectedResult = "{" - + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"serial-number\":\"1234\"," - + "\"equip-vendor\":\"NOKIA\"," - + "\"equip-model\":\"3310\"," - + "\"equip-type\":\"cell\"," - + "\"nf-role\":\"role\"," - + "\"sw-version\":\"1.2.3\"" - + "}"; - - assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java deleted file mode 100644 index 3f396e82..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * 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.model; - -import com.google.gson.Gson; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; - -import java.io.InputStreamReader; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; - -class AaiPnfResultModelTest { - - @Test - void shouldParseAaiPnf() { - Gson gson = PrhModelAwareGsonBuilder.createGson(); - AaiPnfResultModel pnf = gson.fromJson(new InputStreamReader(Objects.requireNonNull( - ClassLoader.getSystemResourceAsStream("some_aai_pnf.json"))), AaiPnfResultModel.class); - - assertThat(pnf.getPnfName()).isEqualTo("some pnfName"); - assertThat(pnf.getPnfName2()).isEqualTo("some pnfName2"); - assertThat(pnf.getSelflink()).isEqualTo("some selflink"); - assertThat(pnf.getPnfName2Source()).isEqualTo("some pnfName2Source"); - assertThat(pnf.getPnfId()).isEqualTo("some pnfId"); - assertThat(pnf.getEquipType()).isEqualTo("some equipType"); - assertThat(pnf.getEquipVendor()).isEqualTo("some equipVendor"); - assertThat(pnf.getEquipModel()).isEqualTo("some equipModel"); - assertThat(pnf.getManagementOption()).isEqualTo("some managementOption"); - assertThat(pnf.getIpaddressV4Oam()).isEqualTo("some ipaddressV4Oam"); - assertThat(pnf.getSwVersion()).isEqualTo("some swVersion"); - assertThat(pnf.isInMaint()).isFalse(); - assertThat(pnf.getFrameId()).isEqualTo("some frameId"); - assertThat(pnf.getSerialNumber()).isEqualTo("some serialNumber"); - assertThat(pnf.getIpaddressV4Loopback0()).isEqualTo("some ipaddressV4Loopback0"); - assertThat(pnf.getIpaddressV6Loopback0()).isEqualTo("some ipaddressV6Loopback0"); - assertThat(pnf.getIpaddressV4Aim()).isEqualTo("some ipaddressV4Aim"); - assertThat(pnf.getIpaddressV6Aim()).isEqualTo("some ipaddressV6Aim"); - assertThat(pnf.getIpaddressV6Oam()).isEqualTo("some ipaddressV6Oam"); - assertThat(pnf.getInvStatus()).isEqualTo("some invStatus"); - assertThat(pnf.getResourceVersion()).isEqualTo("some resourceVersion"); - assertThat(pnf.getProvStatus()).isEqualTo("some provStatus"); - assertThat(pnf.getNfRole()).isEqualTo("some nfRole"); - - assertThat(pnf.getRelationshipList().getRelationship()).hasSize(1); - RelationshipDict relationshipDict = pnf.getRelationshipList().getRelationship().get(0); - assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); - assertThat(relationshipDict.getRelationshipData()).hasSize(1); - RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); - assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); - assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); - } - - @Test - void shouldProvideEmptyRelationshipListForEmptyJson() { - Gson gson = PrhModelAwareGsonBuilder.createGson(); - AaiPnfResultModel pnf = gson.fromJson("{}", AaiPnfResultModel.class); - assertThat(pnf.getRelationshipList()).isNotNull(); - assertThat(pnf.getRelationshipList().getRelationship()).isEmpty(); - } - - @Test - void shouldIgnoreUnexpectedFieldsInJson() { - Gson gson = PrhModelAwareGsonBuilder.createGson(); - gson.fromJson("{\"foo\":\"bar\"}", AaiPnfResultModel.class); - } - -} \ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java deleted file mode 100644 index 5f9ca14d..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * 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.model; - -import com.google.gson.Gson; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; - -import java.io.InputStreamReader; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; - -class AaiServiceInstanceResultModelTest { - - @Test - void shouldParseAaiServiceInstance() { - AaiServiceInstanceResultModel serviceInstance = PrhModelAwareGsonBuilder.createGson().fromJson( - new InputStreamReader(Objects.requireNonNull( - ClassLoader.getSystemResourceAsStream("some_aai_service_instance.json"))), - AaiServiceInstanceResultModel.class); - - assertThat(serviceInstance.getServiceInstanceId()).isEqualTo("some serviceInstanceId"); - assertThat(serviceInstance.getServiceInstanceName()).isEqualTo("some serviceInstanceName"); - assertThat(serviceInstance.getServiceType()).isEqualTo("some serviceType"); - assertThat(serviceInstance.getServiceRole()).isEqualTo("some serviceRole"); - assertThat(serviceInstance.getEnvironmentContext()).isEqualTo("some environmentContext"); - assertThat(serviceInstance.getWorkloadContext()).isEqualTo("some workloadContext"); - assertThat(serviceInstance.getCreatedAt()).isEqualTo("some createdAt"); - assertThat(serviceInstance.getUpdatedAt()).isEqualTo("some updatedAt"); - assertThat(serviceInstance.getDescription()).isEqualTo("some description"); - assertThat(serviceInstance.getModelInvariantId()).isEqualTo("some modelInvariantId"); - assertThat(serviceInstance.getModelVersionId()).isEqualTo("some modelVersionId"); - assertThat(serviceInstance.getPersonaModelVersion()).isEqualTo("some personaModelVersion"); - assertThat(serviceInstance.getWidgetModelId()).isEqualTo("some widgetModelId"); - assertThat(serviceInstance.getWidgetModelVersion()).isEqualTo("some widgetModelVersion"); - assertThat(serviceInstance.getBandwidthTotal()).isEqualTo("some bandwidthTotal"); - assertThat(serviceInstance.getBandwidthUpWan1()).isEqualTo("some bandwidthUpWan1"); - assertThat(serviceInstance.getBandwidthDownWan1()).isEqualTo("some bandwidthDownWan1"); - assertThat(serviceInstance.getBandwidthUpWan2()).isEqualTo("some bandwidthUpWan2"); - assertThat(serviceInstance.getBandwidthDownWan2()).isEqualTo("some bandwidthDownWan2"); - assertThat(serviceInstance.getVhnPortalUrl()).isEqualTo("some vhnPortalUrl"); - assertThat(serviceInstance.getServiceInstanceLocationId()).isEqualTo("some serviceInstanceLocationId"); - assertThat(serviceInstance.getResourceVersion()).isEqualTo("some resourceVersion"); - assertThat(serviceInstance.getSelflink()).isEqualTo("some selflink"); - assertThat(serviceInstance.getOrchestrationStatus()).isEqualTo("some orchestrationStatus"); - - RelationshipDict relationshipDict = serviceInstance.getRelationshipList().getRelationship().get(0); - assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); - assertThat(relationshipDict.getRelationshipData()).hasSize(1); - RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); - assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); - assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); - } - - - @Test - void shouldProvideEmptyRelationshipListForEmptyJson() { - Gson gson = PrhModelAwareGsonBuilder.createGson(); - AaiServiceInstanceResultModel serviceInstance = gson.fromJson("{}", AaiServiceInstanceResultModel.class); - assertThat(serviceInstance.getRelationshipList()).isNotNull(); - assertThat(serviceInstance.getRelationshipList().getRelationship()).isEmpty(); - } - - @Test - void shouldIgnoreUnexpectedFieldsInJson() { - Gson gson = PrhModelAwareGsonBuilder.createGson(); - gson.fromJson("{\"foo\":\"bar\"}", AaiServiceInstanceResultModel.class); - } - -} \ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java deleted file mode 100644 index 769e1673..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 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.model; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.junit.jupiter.api.Test; - -class PnfReadyJsonBodyBuilderTest { - - @Test - void createJsonBody_shouldReturnJsonInString() { - - JsonObject jsonObject = parse("{\n" - + " \"attachmentPoint\": \"bla-bla-30-3\",\n" - + " \"cvlan\": \"678\",\n" - + " \"svlan\": \"1005\"\n" - + " }"); - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .additionalFields(jsonObject) - .build(); - - JsonObject expectedResult = parse("{" - + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"additionalFields\":{\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}" - + "}"); - - assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); - } - - @Test - void createJsonBodyWithNullableFieldsNotSet_shouldReturnJsonInString() { - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .build(); - - JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); - - assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); - } - - @Test - void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() { - JsonObject jsonObject = new JsonObject(); - - ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .additionalFields(jsonObject) - .build(); - - JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); - - assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); - } - - private static JsonObject parse(String jsonString) { - return new JsonParser().parse(jsonString).getAsJsonObject(); - } -} -- cgit 1.2.3-korg