summaryrefslogtreecommitdiffstats
path: root/prh-commons/src
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2019-12-04 12:51:19 +0100
committerMichal Kabaj <michal.kabaj@nokia.com>2019-12-04 13:18:57 +0100
commit2532f556a8bda4d6eec02d5120553262e65c7329 (patch)
treec39374d379454bf6d90256c0f5701185c259e6a0 /prh-commons/src
parent26b3fd4c057a8e1ac38bcc48c920c4aef61da9e2 (diff)
Refactor AaiClient API - remove interfaces
- Removed JsonBodyBuilder because it had only one impl - AaiJsonBodyBuilderImpl - Removed AaiModel because it had only one impl - ConsumerDmaapModel - Replaced usages of removed interfaces with concrete implementations Issue-ID: DCAEGEN2-1955 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com> Change-Id: I6cd651b2061e8520a508e3a62091d1cb15002c99
Diffstat (limited to 'prh-commons/src')
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java6
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java14
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java27
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java34
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java11
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java3
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java8
7 files changed, 17 insertions, 86 deletions
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java
index f97c57be..122a6097 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java
@@ -25,14 +25,14 @@ import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFacto
import io.vavr.collection.HashMap;
import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel;
+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<AaiModel, HttpResponse> {
+public final class AaiHttpGetClient implements AaiHttpClient<ConsumerDmaapModel, HttpResponse> {
private final RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
@@ -44,7 +44,7 @@ public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpRespo
}
@Override
- public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
+ public Mono<HttpResponse> getAaiResponse(ConsumerDmaapModel aaiModel) {
return httpClient.call(ImmutableHttpRequest.builder()
.method(HttpMethod.GET)
.url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId())
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java
index fdeb5e3c..efae2d54 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java
@@ -26,8 +26,8 @@ import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.JsonBodyBuilder;
+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;
@@ -35,28 +35,28 @@ 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<AaiModel, HttpResponse> {
+public final class AaiHttpPatchClient implements AaiHttpClient<ConsumerDmaapModel, HttpResponse> {
private final static Map<String, String> CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json");
private RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
- private final JsonBodyBuilder jsonBodyBuilder;
+ private final AaiJsonBodyBuilderImpl jsonBodyBuilder;
- public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder,
+ public AaiHttpPatchClient(final AaiClientConfiguration configuration, AaiJsonBodyBuilderImpl jsonBodyBuilder,
RxHttpClient httpClient) {
this.configuration = configuration;
this.jsonBodyBuilder = jsonBodyBuilder;
this.httpClient = httpClient;
}
- public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
+ public Mono<HttpResponse> getAaiResponse(ConsumerDmaapModel aaiModel) {
final Map<String, String> headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders()));
String jsonBody = jsonBodyBuilder.createJsonBody(aaiModel);
return httpClient.call(ImmutableHttpRequest.builder()
- .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId())
+ .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId())
.customHeaders(headers)
.diagnosticContext(createRequestDiagnosticContext())
.body(RequestBody.fromString(jsonBody))
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java
deleted file mode 100644
index f0353d74..00000000
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.services.prh.adapter.aai.model;
-
-@FunctionalInterface
-public interface AaiModel {
-
- String getCorrelationId();
-}
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java
deleted file mode 100644
index db8839ea..00000000
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.services.prh.adapter.aai.model;
-
-@FunctionalInterface
-public interface JsonBodyBuilder<T> {
-
- /**
- * Method for serialization object by GSON.
- *
- * @param t - object which will be serialized
- * @return string from serialization
- */
-
- String createJsonBody(T t);
-} \ 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
index c53da879..43e4ebbe 100644
--- 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * 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.
@@ -23,19 +23,12 @@ 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.adapter.aai.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder;
import org.springframework.util.StringUtils;
-public class AaiJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> {
+public class AaiJsonBodyBuilderImpl {
- /**
- * Method for serialization object by GSON.
- *
- * @param consumerDmaapModel - object which will be serialized
- * @return string from serialization
- */
public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
GsonBuilder gsonBuilder = new GsonBuilder();
ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
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
index d813116d..9ed36823 100644
--- 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
@@ -24,7 +24,6 @@ import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import org.immutables.gson.Gson;
import org.immutables.value.Value;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel;
import org.springframework.lang.Nullable;
/**
@@ -33,7 +32,7 @@ import org.springframework.lang.Nullable;
@Value.Immutable
@Gson.TypeAdapters(fieldNamingStrategy = true)
-public interface ConsumerDmaapModel extends AaiModel {
+public interface ConsumerDmaapModel {
@SerializedName(value = "correlationId", alternate = "correlationId")
String getCorrelationId();
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java
index d717e245..fd9523a9 100644
--- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java
+++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java
@@ -22,16 +22,16 @@ package org.onap.dcaegen2.services.prh.adapter.aai;
import static org.mockito.Mockito.mock;
import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel;
-import org.onap.dcaegen2.services.prh.adapter.aai.model.JsonBodyBuilder;
+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 AaiModel aaiModel = () -> "test-id";
+ protected final ConsumerDmaapModel aaiModel = mock(ConsumerDmaapModel.class);
protected final RxHttpClient httpClient = mock(RxHttpClient.class);
- protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class);
+ protected final AaiJsonBodyBuilderImpl bodyBuilder = mock(AaiJsonBodyBuilderImpl.class);
protected final HttpResponse response = mock(HttpResponse.class);