summaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'prh-aai-client/src')
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java)10
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java)6
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClientImpl.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java)23
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java)74
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIExtendedHttpClient.java)10
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiProducerClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java)40
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java)49
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIHttpClientImplTest.java)26
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiProducerClientTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java)63
9 files changed, 155 insertions, 146 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java
index d652ccb7..c9d7820c 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -20,8 +20,8 @@
package org.onap.dcaegen2.services.prh.config;
-
import java.io.Serializable;
+
import java.util.Map;
import org.immutables.gson.Gson;
@@ -33,7 +33,7 @@ import org.springframework.stereotype.Component;
@Value.Immutable(prehash = true)
@Value.Style(builder = "new")
@Gson.TypeAdapters
-public abstract class AAIClientConfiguration implements Serializable {
+public abstract class AaiClientConfiguration implements Serializable {
private static final long serialVersionUID = 1L;
@@ -53,7 +53,7 @@ public abstract class AAIClientConfiguration implements Serializable {
public abstract String aaiUserPassword();
@Value.Parameter
- public abstract Boolean aaiIgnoreSSLCertificateErrors();
+ public abstract Boolean aaiIgnoreSslCertificateErrors();
@Value.Parameter
public abstract String aaiBasePath();
@@ -62,6 +62,6 @@ public abstract class AAIClientConfiguration implements Serializable {
public abstract String aaiPnfPath();
@Value.Parameter
- public abstract Map<String,String> aaiHeaders();
+ public abstract Map<String, String> aaiHeaders();
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java
index 09d7f6ae..2d0f9eca 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.prh.service;
import org.apache.http.impl.client.CloseableHttpClient;
@FunctionalInterface
-public interface AAIClient {
- CloseableHttpClient getAAIHttpClient();
+public interface AaiClient {
+ CloseableHttpClient getAaiHttpClient();
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClientImpl.java
index 04652020..f9252578 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClientImpl.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -20,6 +20,10 @@
package org.onap.dcaegen2.services.prh.service;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -31,34 +35,31 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-public class AAIClientImpl implements AAIClient {
+public class AaiClientImpl implements AaiClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private AAIClientConfiguration aaiClientConfig;
+ private AaiClientConfiguration aaiClientConfig;
- public AAIClientImpl(AAIClientConfiguration aaiClientConfiguration) {
+ AaiClientImpl(AaiClientConfiguration aaiClientConfiguration) {
this.aaiClientConfig = aaiClientConfiguration;
}
@Override
- public CloseableHttpClient getAAIHttpClient() {
+ public CloseableHttpClient getAaiHttpClient() {
final HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties();
- final boolean aaiIgnoreSSLCertificateErrors = aaiClientConfig.aaiIgnoreSSLCertificateErrors();
+ final boolean aaiIgnoreSslCertificateErrors = aaiClientConfig.aaiIgnoreSslCertificateErrors();
TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
- if (aaiIgnoreSSLCertificateErrors) {
+ if (aaiIgnoreSslCertificateErrors) {
try {
logger.info("Setting SSL Context for AAI HTTP Client");
httpClientBuilder.setSSLContext(new SSLContextBuilder()
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClient.java
index fafe6e04..0a00048b 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClient.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -20,6 +20,13 @@
package org.onap.dcaegen2.services.prh.service;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
import org.apache.http.HttpEntity;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
@@ -27,20 +34,14 @@ import org.apache.http.client.methods.HttpRequestBase;
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.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
import org.slf4j.Logger;
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 {
+public class AaiConsumerClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -49,11 +50,15 @@ public class AAIConsumerClient {
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
private final String aaiPath;
- private final Map<String,String> aaiHeaders;
-
-
- public AAIConsumerClient(AAIClientConfiguration aaiClientConfiguration) {
- closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient();
+ private final Map<String, String> aaiHeaders;
+
+ /**
+ * AAI client for consuming data.
+ *
+ * @param aaiClientConfiguration - client config
+ */
+ public AaiConsumerClient(AaiClientConfiguration aaiClientConfiguration) {
+ closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient();
aaiHost = aaiClientConfiguration.aaiHost();
aaiProtocol = aaiClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber();
@@ -61,6 +66,13 @@ public class AAIConsumerClient {
aaiHeaders = aaiClientConfiguration.aaiHeaders();
}
+ /**
+ * Function which call http client for getting object from AAI.
+ *
+ * @param consumerDmaapModel - helper object for uri generation
+ * @return - status code of operation
+ * @throws IOException - Apache HTTP client exception
+ */
public Optional<String> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
@@ -71,33 +83,33 @@ public class AAIConsumerClient {
}
}
- private URI createAAIExtendedURI(String pnfName) {
+ private URI createAaiExtendedUri(String pnfName) {
- URI extendedURI = null;
+ URI extendedUri = null;
final URIBuilder uriBuilder = new URIBuilder()
- .setScheme(aaiProtocol)
- .setHost(aaiHost)
- .setPort(aaiHostPortNumber)
- .setPath(aaiPath + "/" + pnfName);
+ .setScheme(aaiProtocol)
+ .setHost(aaiHost)
+ .setPort(aaiHostPortNumber)
+ .setPath(aaiPath + "/" + pnfName);
try {
- extendedURI = uriBuilder.build();
- logger.trace("Building extended URI: {}", extendedURI);
+ extendedUri = uriBuilder.build();
+ logger.trace("Building extended URI: {}", extendedUri);
} catch (URISyntaxException e) {
logger.warn("Exception while building extended URI: {}", e);
}
- return extendedURI;
+ return extendedUri;
}
private ResponseHandler<Optional<String>> aaiResponseHandler() {
- return httpResponse -> {
+ return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
logger.info("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
- if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
+ if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
logger.trace("HTTP response successful.");
final String aaiResponse = EntityUtils.toString(responseEntity);
return Optional.of(aaiResponse);
@@ -109,17 +121,17 @@ public class AAIConsumerClient {
};
}
- private HttpRequestBase createHttpRequest(URI extendedURI) {
- return isExtendedURINotNull(extendedURI) ? new HttpGet(extendedURI) : null;
+ private HttpRequestBase createHttpRequest(URI extendedUri) {
+ return isExtendedUriNotNull(extendedUri) ? new HttpGet(extendedUri) : null;
}
- private Boolean isExtendedURINotNull(URI extendedURI) {
- return extendedURI != null;
+ private Boolean isExtendedUriNotNull(URI extendedUri) {
+ return extendedUri != null;
}
private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
- final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
- HttpRequestBase request = createHttpRequest(extendedURI);
+ final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName());
+ HttpRequestBase request = createHttpRequest(extendedUri);
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/prh/service/AAIExtendedHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java
index 14c7e8f3..8e424fe6 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIExtendedHttpClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -17,15 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.service;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+package org.onap.dcaegen2.services.prh.service;
import java.net.URISyntaxException;
import java.util.Optional;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+
@FunctionalInterface
-public interface AAIExtendedHttpClient {
+public interface AaiExtendedHttpClient {
+
Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException;
}
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiProducerClient.java
index 0c2a12a3..f4301f6b 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiProducerClient.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -20,6 +20,14 @@
package org.onap.dcaegen2.services.prh.service;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Base64;
+import java.util.Map;
+import java.util.Optional;
+
import java.util.function.Predicate;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -29,22 +37,14 @@ import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.CommonFunctions;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Base64;
-import java.util.Map;
-import java.util.Optional;
-
-public class AAIProducerClient implements AAIExtendedHttpClient {
+public class AaiProducerClient implements AaiExtendedHttpClient {
private static final String EXCEPTION_MESSAGE = "Exception while executing http client: ";
private static Predicate<String> isEmpty = String::isEmpty;
@@ -59,8 +59,8 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
private final String aaiUserPassword;
- public AAIProducerClient(AAIClientConfiguration aaiClientConfiguration) {
- closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient();
+ public AaiProducerClient(AaiClientConfiguration aaiClientConfiguration) {
+ closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient();
aaiHost = aaiClientConfiguration.aaiHost();
aaiProtocol = aaiClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber();
@@ -84,11 +84,11 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
}
private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException {
- final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
- return createHttpRequest(extendedURI, consumerDmaapModel);
+ final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName());
+ return createHttpRequest(extendedUri, consumerDmaapModel);
}
- private URI createAAIExtendedURI(final String pnfName) throws URISyntaxException {
+ private URI createAaiExtendedUri(final String pnfName) throws URISyntaxException {
return new URIBuilder()
.setScheme(aaiProtocol)
.setHost(aaiHost)
@@ -96,12 +96,12 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
.setPath(aaiPath + "/" + pnfName).build();
}
- Optional<HttpRequestBase> createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
+ private Optional<HttpRequestBase> createHttpRequest(URI extendedUri, ConsumerDmaapModel consumerDmaapModel) {
return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(isEmpty.negate())
.flatMap(myJson -> {
try {
logger.info("AAI: sending json {}", myJson);
- return Optional.of(createHttpPatch(extendedURI, myJson));
+ return Optional.of(createHttpPatch(extendedUri, myJson));
} catch (UnsupportedEncodingException e) {
logger.warn(EXCEPTION_MESSAGE, e);
}
@@ -109,8 +109,8 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
});
}
- HttpPatch createHttpPatch(URI extendedURI, String jsonBody) throws UnsupportedEncodingException {
- HttpPatch httpPatch = new HttpPatch(extendedURI);
+ HttpPatch createHttpPatch(URI extendedUri, String jsonBody) throws UnsupportedEncodingException {
+ HttpPatch httpPatch = new HttpPatch(extendedUri);
httpPatch.setEntity(new StringEntity(jsonBody));
aaiHeaders.forEach(httpPatch::addHeader);
httpPatch.addHeader("Content-Type", "application/merge-patch+json");
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java
index 6045c007..8b4a2110 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -20,14 +20,9 @@
package org.onap.dcaegen2.services.prh.service;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -35,21 +30,27 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-public class AAIConsumerClientTest {
+class AaiConsumerClientTest {
- private static AAIConsumerClient testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ private static AaiConsumerClient testedObject;
+ private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.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 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 {
+ static void setup() throws NoSuchFieldException, IllegalAccessException {
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
@@ -70,18 +71,18 @@ public class AAIConsumerClientTest {
when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME);
- testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
+ testedObject = new AaiConsumerClient(aaiHttpClientConfigurationMock);
setField();
}
@Test
- public void getExtendedDetails_returnsSuccess() throws IOException {
+ void getExtendedDetails_returnsSuccess() throws IOException {
- when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
- thenReturn(Optional.of(JSON_MESSAGE));
- Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
- Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
+ when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class)))
+ .thenReturn(Optional.of(JSON_MESSAGE));
+ 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/prh/service/AAIHttpClientImplTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java
index 0e713856..419fe32b 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIHttpClientImplTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
@@ -17,40 +17,38 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.service;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+package org.onap.dcaegen2.services.prh.service;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
-public class AAIHttpClientImplTest {
+class AaiHttpClientImplTest {
- private static AAIClientImpl testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock;
+ private static AaiClientImpl testedObject;
@BeforeAll
public static void setup() {
- aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PNF");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PNF");
- when(aaiHttpClientConfigurationMock.aaiIgnoreSSLCertificateErrors()).thenReturn(true);
+ when(aaiHttpClientConfigurationMock.aaiIgnoreSslCertificateErrors()).thenReturn(true);
- testedObject = new AAIClientImpl(aaiHttpClientConfigurationMock);
+ testedObject = new AaiClientImpl(aaiHttpClientConfigurationMock);
}
@Test
- public void getAAIHttpClientObject_shouldNotBeNull() {
- testedObject.getAAIHttpClient();
- assertNotNull(testedObject.getAAIHttpClient());
+ public void getAaiHttpClientObject_shouldNotBeNull() {
+ assertNotNull(testedObject.getAaiHttpClient());
}
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiProducerClientTest.java
index b7515ad5..27cb374d 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiProducerClientTest.java
@@ -20,6 +20,21 @@
package org.onap.dcaegen2.services.prh.service;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -29,40 +44,22 @@ import org.apache.http.client.methods.HttpPatch;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.model.CommonFunctions;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AAIProducerClientTest {
+class AaiProducerClientTest {
private static final Integer SUCCESS = 200;
- private static AAIProducerClient testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ private static final HttpResponse httpResponseMock = mock(HttpResponse.class);
+ private static final HttpEntity httpEntityMock = mock(HttpEntity.class);
+ private static final StatusLine statusLineMock = mock(StatusLine.class);
+
+ private static AaiProducerClient testedObject;
+ private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
- private final static HttpResponse httpResponseMock = mock(HttpResponse.class);
- private final static HttpEntity httpEntityMock = mock(HttpEntity.class);
- private final static StatusLine statusLineMock = mock(StatusLine.class);
-
-
-
@BeforeAll
static void setup() throws NoSuchFieldException, IllegalAccessException {
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net");
@@ -74,7 +71,7 @@ class AAIProducerClientTest {
when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(setupHeaders());
- testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
+ testedObject = new AaiProducerClient(aaiHttpClientConfigurationMock);
setField();
}
@@ -82,19 +79,18 @@ class AAIProducerClientTest {
void getHttpResponse_shouldReturnSuccessStatusCode() throws IOException, URISyntaxException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenReturn(Optional.of(SUCCESS));
+ .thenReturn(Optional.of(SUCCESS));
Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel);
// then
assertEquals(SUCCESS, actualResult.get());
}
@Test
- void getHttpResponse_shouldHandleIOException() throws IOException, URISyntaxException {
+ void getHttpResponse_shouldHandleIoException() throws IOException, URISyntaxException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenThrow(new IOException("Error occur"));
+ .thenThrow(new IOException("Error occur"));
- testedObject.getHttpResponse(consumerDmaapModel);
// then
assertNotNull(testedObject.getHttpResponse(consumerDmaapModel));
}
@@ -103,8 +99,7 @@ class AAIProducerClientTest {
void createHttpRequest_shouldCatchUnsupportedEncodingException() throws URISyntaxException, IOException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenThrow(new UnsupportedEncodingException("A new Error"));
- testedObject.getHttpResponse(consumerDmaapModel);
+ .thenThrow(new UnsupportedEncodingException("A new Error"));
// then
assertNotNull(testedObject.getHttpResponse(consumerDmaapModel));
}
@@ -158,7 +153,7 @@ class AAIProducerClientTest {
field.set(testedObject, closeableHttpClientMock);
}
- private static Map<String,String> setupHeaders() {
+ private static Map<String, String> setupHeaders() {
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "vv-temp");