summaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-05-07 16:58:20 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-05-11 12:29:25 +0200
commita393ae34963a919b842127cc8943a94f2d7c1bc7 (patch)
tree666c78e8d10b0fd65e55494e2e27d52643cf92a2 /prh-aai-client/src
parent8c88efe7a0abe051e8a4c4d271c84eb8e68c29f0 (diff)
AAI client configuration & tasks changed
Change-Id: I86a2f2ed62565263f2be2c9078a092f993234a19 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-aai-client/src')
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java11
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java3
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java60
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java5
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java76
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java46
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java2
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java17
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java29
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java4
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java61
11 files changed, 108 insertions, 206 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
index 60a022b4..5a3bffc6 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java
@@ -22,6 +22,8 @@ package org.onap.dcaegen2.services.config;
import java.io.Serializable;
+import java.util.Map;
+
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import org.springframework.stereotype.Component;
@@ -53,4 +55,13 @@ public abstract class AAIClientConfiguration implements Serializable {
@Value.Parameter
public abstract Boolean aaiIgnoreSSLCertificateErrors();
+ @Value.Parameter
+ public abstract String aaiBasePath();
+
+ @Value.Parameter
+ public abstract String aaiPnfPath();
+
+ @Value.Parameter
+ public abstract Map<String,String> aaiHeaders();
+
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
index c2b40b9a..f58919e5 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java
@@ -34,7 +34,6 @@ import org.apache.http.ssl.TrustStrategy;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
@@ -46,7 +45,7 @@ public class AAIClientImpl implements AAIClient {
private AAIClientConfiguration aaiHttpClientConfig;
- @Autowired
+
public AAIClientImpl(AAIClientConfiguration aaiHttpClientConfiguration) {
this.aaiHttpClientConfig = aaiHttpClientConfiguration;
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
index 24790be2..ffaf1aff 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
@@ -28,7 +28,7 @@ import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,9 +36,11 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
-public class AAIConsumerClient implements AAIExtendedHttpClient {
+public class AAIConsumerClient {
Logger logger = LoggerFactory.getLogger(AAIConsumerClient.class);
@@ -46,33 +48,30 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
private final String aaiHost;
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
+ private final String aaiPath;
+ private final Map<String,String> aaiHeaders;
public AAIConsumerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
- final AAIClient aaiClient = new AAIClientImpl(aaiHttpClientConfiguration);
- closeableHttpClient = aaiClient.getAAIHttpClient();
+ closeableHttpClient = new AAIClientImpl(aaiHttpClientConfiguration).getAAIHttpClient();
aaiHost = aaiHttpClientConfiguration.aaiHost();
aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiHttpClientConfiguration.aaiHostPortNumber();
+ aaiPath = aaiHttpClientConfiguration.aaiBasePath() + aaiHttpClientConfiguration.aaiPnfPath();
+ aaiHeaders = aaiHttpClientConfiguration.aaiHeaders();
}
- @Override
- public Optional<String> getHttpResponse(HttpRequestDetails requestDetails) {
-
- Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
-
+ public Optional<String> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
- extendedDetails = closeableHttpClient.execute(request.get(), aaiResponseHandler());
+ return closeableHttpClient.execute(request.get(), aaiResponseHandler());
} catch (IOException e) {
- logger.error("Exception while executing HTTP request: {}", e);
+ logger.warn("Exception while executing http client: ", e);
+ throw new IOException();
}
-
- return extendedDetails;
}
-
- private URI createAAIExtendedURI(final String path, String pnfName) {
+ private URI createAAIExtendedURI(String pnfName) {
URI extendedURI = null;
@@ -80,13 +79,13 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
.setScheme(aaiProtocol)
.setHost(aaiHost)
.setPort(aaiHostPortNumber)
- .setPath(path + "/" + pnfName);
+ .setPath(aaiPath + "/" + pnfName);
try {
extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}", extendedURI);
+ logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ logger.warn("Exception while building extended URI: {}", e);
}
return extendedURI;
@@ -95,39 +94,34 @@ public class AAIConsumerClient implements AAIExtendedHttpClient {
private ResponseHandler<Optional<String>> aaiResponseHandler() {
return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
- logger.info("Status code of operation: {}", responseCode);
+ logger.trace("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
- logger.info("HTTP response successful.");
+ logger.trace("HTTP response successful.");
final String aaiResponse = EntityUtils.toString(responseEntity);
return Optional.of(aaiResponse);
} else {
String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
- logger.error("HTTP response not successful : {}", aaiResponse);
- return Optional.of("" + responseCode);
+ logger.warn("HTTP response not successful : {}", aaiResponse);
+ return Optional.of(String.valueOf(responseCode));
}
};
}
private HttpRequestBase createHttpRequest(URI extendedURI) {
-
- if (isExtendedURINotNull(extendedURI)) {
- return new HttpGet(extendedURI);
- } else {
- return null;
- }
+ return isExtendedURINotNull(extendedURI) ? new HttpGet(extendedURI) : null;
}
private Boolean isExtendedURINotNull(URI extendedURI) {
return extendedURI != null;
}
- private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
-
- final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
+ final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
HttpRequestBase request = createHttpRequest(extendedURI);
- requestDetails.headers().forEach(request::addHeader);
+ aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader);
+ Objects.requireNonNull(request).addHeader("Content-Type", "application/json");
return Optional.of(request);
}
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
index 24149e6d..71c94b68 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClient.java
@@ -19,12 +19,13 @@
*/
package org.onap.dcaegen2.services.service;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import java.io.IOException;
import java.util.Optional;
@FunctionalInterface
public interface AAIExtendedHttpClient {
- Optional<String> getHttpResponse(HttpRequestDetails httpRequestDetails);
+ Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException;
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
index 0b82578a..788d997e 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java
@@ -30,7 +30,8 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.CommonFunctions;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +40,8 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
public class AAIProducerClient implements AAIExtendedHttpClient {
@@ -48,71 +51,69 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
private final String aaiHost;
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
+ private final String aaiPath;
+ private final Map<String,String> aaiHeaders;
public AAIProducerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
- final AAIClient aaiHttpClient = new AAIClientImpl(aaiHttpClientConfiguration);
- closeableHttpClient = aaiHttpClient.getAAIHttpClient();
+ closeableHttpClient = new AAIClientImpl(aaiHttpClientConfiguration).getAAIHttpClient();
aaiHost = aaiHttpClientConfiguration.aaiHost();
aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiHttpClientConfiguration.aaiHostPortNumber();
+ aaiPath = aaiHttpClientConfiguration.aaiBasePath() + aaiHttpClientConfiguration.aaiPnfPath();
+ aaiHeaders = aaiHttpClientConfiguration.aaiHeaders();
}
- @Override
- public Optional<String> getHttpResponse(HttpRequestDetails requestDetails) {
-
- Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
+ @Override
+ public Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
- extendedDetails = closeableHttpClient.execute(request.get(), aaiResponseHandler());
+ return closeableHttpClient.execute(request.get(), aaiResponseHandler());
} catch (IOException e) {
- logger.error("Exception while executing HTTP request: {}", e);
+ logger.warn("Exception while executing http client: ", e);
+ throw new IOException();
}
-
- return extendedDetails;
}
- private URI createAAIExtendedURI(final String path, final String pnfName) {
-
+ private URI createAAIExtendedURI(final String pnfName) {
URI extendedURI = null;
-
final URIBuilder uriBuilder = new URIBuilder()
.setScheme(aaiProtocol)
.setHost(aaiHost)
.setPort(aaiHostPortNumber)
- .setPath(path + "/" + pnfName);
-
+ .setPath(aaiPath + "/" + pnfName);
try {
extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}", extendedURI);
+ logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ logger.warn("Exception while building extended URI: ", e);
}
-
return extendedURI;
}
- private ResponseHandler<Optional<String>> aaiResponseHandler() {
+ private ResponseHandler<Optional<Integer>> aaiResponseHandler() {
return (HttpResponse httpResponse) -> {
- final int responseCode = httpResponse.getStatusLine().getStatusCode();
- logger.info("Status code of operation: {}", responseCode);
+ final Integer responseCode = httpResponse.getStatusLine().getStatusCode();
+ logger.trace("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
- logger.info("HTTP response successful.");
- return Optional.of("" + responseCode);
+ logger.trace("HTTP response successful.");
+ return Optional.of(responseCode);
} else {
String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
- logger.error("HTTP response not successful : {}", aaiResponse);
- return Optional.of("" + responseCode);
+ logger.warn("HTTP response not successful : {}", aaiResponse);
+ return Optional.of(responseCode);
}
};
}
- private HttpRequestBase createHttpRequest(URI extendedURI, HttpRequestDetails httpRequestDetails) {
- if (isExtendedURINotNull(extendedURI) && httpRequestDetails.jsonBody().isPresent()) {
- return createHttpPatch(extendedURI, httpRequestDetails.jsonBody());
+ private HttpRequestBase createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
+ String jsonBody = CommonFunctions.createJsonBody(consumerDmaapModel);
+
+ if (isExtendedURINotNull(extendedURI) && jsonBody != null && !"".equals(jsonBody)) {
+ return createHttpPatch(extendedURI, Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)));
} else {
return null;
}
@@ -122,6 +123,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
return extendedURI != null;
}
+
private Optional<StringEntity> createStringEntity(Optional<String> jsonBody) {
return Optional.of(parseJson(jsonBody).get());
}
@@ -135,21 +137,19 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
private Optional<StringEntity> parseJson(Optional<String> jsonBody) {
Optional<StringEntity> stringEntity = Optional.empty();
-
try {
stringEntity = Optional.of(new StringEntity(jsonBody.get()));
} catch (UnsupportedEncodingException e) {
- logger.error("Exception while parsing JSON: {}", e);
+ logger.warn("Exception while parsing JSON: ", e);
}
-
return stringEntity;
}
- private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
-
- final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
- HttpRequestBase request = createHttpRequest(extendedURI, requestDetails);
- requestDetails.headers().forEach(request::addHeader);
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
+ final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
+ HttpRequestBase request = createHttpRequest(extendedURI, consumerDmaapModel);
+ aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader);
+ Objects.requireNonNull(request).addHeader("Content-Type", "application/merge-patch+json");
return Optional.of(request);
}
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
deleted file mode 100644
index 37e6b860..00000000
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
+++ /dev/null
@@ -1,46 +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.utils;
-
-
-import org.immutables.value.Value;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Optional;
-
-@Value.Immutable(prehash = true)
-@Value.Style(stagedBuilder = true)
-public abstract class HttpRequestDetails implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Value.Parameter
- public abstract String aaiAPIPath();
-
- @Value.Parameter
- public abstract Optional<String> jsonBody();
-
- @Value.Parameter
- public abstract String pnfName();
-
- @Value.Parameter
- public abstract Map<String,String> headers();
-}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
index eac7f83a..20bc7e00 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpUtils.java
@@ -23,8 +23,6 @@ import org.apache.http.HttpStatus;
public final class HttpUtils implements HttpStatus {
- public static final String JSON_APPLICATION_TYPE = "application/json";
-
private HttpUtils() {}
public static boolean isSuccessfulResponseCode(Integer statusCode) {
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
index b95cc8d6..5e45d844 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -44,8 +44,9 @@ public class AAIConsumerClientTest {
private static AAIConsumerClient testedObject;
private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }";
+ private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class);
+ private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
@BeforeAll
public static void setup() throws NoSuchFieldException, IllegalAccessException {
@@ -54,7 +55,7 @@ public class AAIConsumerClientTest {
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "9999");
aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("authentication", "Basic QUFJOkFBSQ==");
+ aaiHeaders.put("Authorization", "Basic QUFJOkFBSQ==");
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/json");
@@ -63,11 +64,11 @@ public class AAIConsumerClientTest {
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
- when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.pnfName()).thenReturn("pnf-nokia-45fsfcx");
- when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE));
+ when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME);
testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
setField();
@@ -79,7 +80,7 @@ public class AAIConsumerClientTest {
when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
thenReturn(Optional.of(JSON_MESSAGE));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
index 7f3978bd..59c90dc8 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
@@ -27,7 +27,9 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModelForUnitTest;
+
import java.io.IOException;
import java.lang.reflect.Field;
@@ -41,17 +43,17 @@ import static org.mockito.Mockito.when;
public class AAIProducerClientTest {
+ private static final Integer SUCCESS = 200;
private static AAIProducerClient testedObject;
private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
- private static final String JsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}";
- private static final String SUCCESS = "200";
- private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
+ private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
+
@BeforeAll
public static void init() throws NoSuchFieldException, IllegalAccessException {
+ //given
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "vv-temp");
@@ -59,29 +61,28 @@ public class AAIProducerClientTest {
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/merge-patch+json");
+ //when
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net");
when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
-
- when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
-
- when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
- when(httpRequestDetailsMock.pnfName()).thenReturn(PNF_NAME);
- when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JsonBody));
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
setField();
}
@Test
- public void getHttpResponsePatch_success() throws IOException {
-
+ public void getHttpResponsePatch_shouldReturnSuccessStatusCode() throws IOException {
+ //when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
.thenReturn(Optional.of(SUCCESS));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel);
+ //then
Assertions.assertEquals(SUCCESS, actualResult.get());
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
index 29a00927..447e0ecc 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
@@ -33,6 +33,8 @@ public class AAIHttpClientConfigurationTest {
private static final Integer PORT = 1234;
private static final String PROTOCOL = "https";
private static final String USER_NAME_PASSWORD = "PRH";
+ private static final String BASE_PATH = "/aai/v11";
+ private static final String PNF_PATH = "/network/pnfs/pnf";
@BeforeAll
public static void init() {
@@ -43,6 +45,8 @@ public class AAIHttpClientConfigurationTest {
.aaiUserName(USER_NAME_PASSWORD)
.aaiUserPassword(USER_NAME_PASSWORD)
.aaiIgnoreSSLCertificateErrors(true)
+ .aaiBasePath(BASE_PATH)
+ .aaiPnfPath(PNF_PATH)
.build();
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
deleted file mode 100644
index 0deb8adb..00000000
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
+++ /dev/null
@@ -1,61 +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.service.utils;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
-import org.onap.dcaegen2.services.utils.ImmutableHttpRequestDetails;
-import org.onap.dcaegen2.services.utils.RequestVerbs;
-
-import java.util.Optional;
-
-
-public class HttpRequestDetailsTest {
-
- private static HttpRequestDetails testObject;
-
- private static final String AAI_PATH = "aaiPathTest";
- private static final String HEADERS_KEY1 = "headersKey1";
- private static final String HEADERS_VALUE1 = "headersValue1";
- private static final String JSON_MESSAGE = "{\"dare_to\": \"dream_big\"}";
- private static final String PNF_NAME = "pnf-nokia-5454885485";
-
- @BeforeAll
- public static void init() {
- testObject = ImmutableHttpRequestDetails.builder()
- .aaiAPIPath(AAI_PATH)
- .pnfName(PNF_NAME)
- .putHeaders(HEADERS_KEY1,HEADERS_VALUE1)
- .jsonBody(JSON_MESSAGE)
- .build();
- }
-
- @Test
- public void testGetters_success() {
- Assertions.assertEquals(AAI_PATH, testObject.aaiAPIPath());
- Assertions.assertEquals(HEADERS_VALUE1, testObject.headers().get(HEADERS_KEY1));
- Assertions.assertEquals(PNF_NAME, testObject.pnfName());
- Assertions.assertEquals(Optional.of(JSON_MESSAGE), testObject.jsonBody());
- }
-}