diff options
author | wasala <przemyslaw.wasala@nokia.com> | 2018-07-10 11:47:01 +0200 |
---|---|---|
committer | wasala <przemyslaw.wasala@nokia.com> | 2018-08-07 10:18:47 +0200 |
commit | c1f0313e1f0085afb813d1ba3e2d7fcc71b5833d (patch) | |
tree | 88bece267217d7a1d3d921c85aad2c01778e98f9 | |
parent | 01578219e470c4cd9b6181c0615759a7118c0abb (diff) |
Checkstyle violations
*Correction of violations
without javadoc
Change-Id: Ida177bf32a58605e74feae5fab22198228e970ce
Issue-ID: DCAEGEN2-563
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
64 files changed, 676 insertions, 692 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"); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java index 0cc12d41..21dcf81e 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh; import org.springframework.boot.SpringApplication; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java index f24dd177..e10c51d0 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java @@ -17,15 +17,22 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; +import java.util.Optional; + import java.util.function.Predicate; -import org.onap.dcaegen2.services.prh.config.*; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; -import java.util.Optional; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 @@ -63,8 +70,8 @@ public class AppConfig extends PrhAppConfig { @Value("${dmaap.dmaapConsumerConfiguration.consumerGroup:}") public String consumerGroup; - @Value("${dmaap.dmaapConsumerConfiguration.timeoutMS:}") - public Integer consumerTimeoutMS; + @Value("${dmaap.dmaapConsumerConfiguration.timeoutMs:}") + public Integer consumerTimeoutMs; @Value("${dmaap.dmaapConsumerConfiguration.message-limit:}") public Integer consumerMessageLimit; @@ -105,8 +112,8 @@ public class AppConfig extends PrhAppConfig { @Value("${aai.aaiClientConfiguration.aaiUserPassword:}") public String aaiUserPassword; - @Value("${aai.aaiClientConfiguration.aaiIgnoreSSLCertificateErrors:}") - public Boolean aaiIgnoreSSLCertificateErrors; + @Value("${aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors:}") + public Boolean aaiIgnoreSslCertificateErrors; @Value("${aai.aaiClientConfiguration.aaiBasePath:}") public String aaiBasePath; @@ -141,8 +148,8 @@ public class AppConfig extends PrhAppConfig { .messageLimit( Optional.ofNullable(consumerMessageLimit).filter(p -> !p.toString().isEmpty()) .orElse(dmaapConsumerConfiguration.messageLimit())) - .timeoutMS(Optional.ofNullable(consumerTimeoutMS).filter(p -> !p.toString().isEmpty()) - .orElse(dmaapConsumerConfiguration.timeoutMS())) + .timeoutMs(Optional.ofNullable(consumerTimeoutMs).filter(p -> !p.toString().isEmpty()) + .orElse(dmaapConsumerConfiguration.timeoutMs())) .consumerGroup(Optional.ofNullable(consumerGroup).filter(isEmpty.negate()) .orElse(dmaapConsumerConfiguration.consumerGroup())) .consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate()) @@ -151,15 +158,15 @@ public class AppConfig extends PrhAppConfig { } @Override - public AAIClientConfiguration getAAIClientConfiguration() { - return new ImmutableAAIClientConfiguration.Builder() + public AaiClientConfiguration getAaiClientConfiguration() { + return new ImmutableAaiClientConfiguration.Builder() .aaiHost(Optional.ofNullable(aaiHost).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiHost())) .aaiHostPortNumber( Optional.ofNullable(aaiHostPortNumber).filter(p -> !p.toString().isEmpty()) .orElse(aaiClientConfiguration.aaiHostPortNumber())) - .aaiIgnoreSSLCertificateErrors( - Optional.ofNullable(aaiIgnoreSSLCertificateErrors).filter(p -> !p.toString().isEmpty()) - .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors())) + .aaiIgnoreSslCertificateErrors( + Optional.ofNullable(aaiIgnoreSslCertificateErrors).filter(p -> !p.toString().isEmpty()) + .orElse(aaiClientConfiguration.aaiIgnoreSslCertificateErrors())) .aaiProtocol( Optional.ofNullable(aaiProtocol).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiProtocol())) .aaiUserName( diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java index f3b1b557..776ece6c 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java @@ -17,9 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; @@ -30,7 +31,7 @@ public interface Config { DmaapConsumerConfiguration getDmaapConsumerConfiguration(); - AAIClientConfiguration getAAIClientConfiguration(); + AaiClientConfiguration getAaiClientConfiguration(); DmaapPublisherConfiguration getDmaapPublisherConfiguration(); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java index ab850044..a6ed3146 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java @@ -17,10 +17,27 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; -import com.google.gson.*; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import com.google.gson.TypeAdapterFactory; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.util.ServiceLoader; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; import org.slf4j.Logger; @@ -29,11 +46,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.*; -import java.util.ServiceLoader; - /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 */ @@ -51,7 +63,7 @@ public abstract class PrhAppConfig implements Config { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - AAIClientConfiguration aaiClientConfiguration; + AaiClientConfiguration aaiClientConfiguration; DmaapConsumerConfiguration dmaapConsumerConfiguration; @@ -67,7 +79,7 @@ public abstract class PrhAppConfig implements Config { } @Override - public AAIClientConfiguration getAAIClientConfiguration() { + public AaiClientConfiguration getAaiClientConfiguration() { return aaiClientConfiguration; } @@ -89,7 +101,7 @@ public abstract class PrhAppConfig implements Config { jsonObject = rootElement.getAsJsonObject(); aaiClientConfiguration = deserializeType(gsonBuilder, jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG), - AAIClientConfiguration.class); + AaiClientConfiguration.class); dmaapConsumerConfiguration = deserializeType(gsonBuilder, jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER), diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java index a650fe85..2eb2903d 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; import io.swagger.annotations.ApiOperation; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java index cb598226..b28fb407 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; import org.springframework.context.annotation.Bean; @@ -38,40 +39,40 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @Profile("prod") public class SwaggerConfig extends WebMvcConfigurationSupport { - private static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh"; - private static final String API_TITLE = "PRH app server"; - private static final String DESCRIPTION = "This page lists all the rest apis for PRH app server."; - private static final String VERSION = "1.0"; - private static final String RESOURCES_PATH = "classpath:/META-INF/resources/"; - private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/"; - private static final String SWAGGER_UI = "swagger-ui.html"; - private static final String WEBJARS = "/webjars/**"; + private static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh"; + private static final String API_TITLE = "PRH app server"; + private static final String DESCRIPTION = "This page lists all the rest apis for PRH app server."; + private static final String VERSION = "1.0"; + private static final String RESOURCES_PATH = "classpath:/META-INF/resources/"; + private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/"; + private static final String SWAGGER_UI = "swagger-ui.html"; + private static final String WEBJARS = "/webjars/**"; - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH)) - .paths(PathSelectors.any()) - .build(); - } + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH)) + .paths(PathSelectors.any()) + .build(); + } - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title(API_TITLE) - .description(DESCRIPTION) - .version(VERSION) - .build(); - } + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title(API_TITLE) + .description(DESCRIPTION) + .version(VERSION) + .build(); + } - @Override - protected void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler(SWAGGER_UI) - .addResourceLocations(RESOURCES_PATH); + @Override + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler(SWAGGER_UI) + .addResourceLocations(RESOURCES_PATH); - registry.addResourceHandler(WEBJARS) - .addResourceLocations(WEBJARS_PATH); - } + registry.addResourceHandler(WEBJARS) + .addResourceLocations(WEBJARS_PATH); + } }
\ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/TomcatHttpConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/TomcatHttpConfig.java index 0e9d7fe6..27227251 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/TomcatHttpConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/TomcatHttpConfig.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; import org.apache.catalina.connector.Connector; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java index 989c6fb2..ae5f2277 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.controllers; import io.swagger.annotations.Api; @@ -48,7 +49,7 @@ public class HeartbeatController { @ApiResponse(code = 401, message = "You are not authorized to view the resource"), @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"), @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") - } + } ) public Mono<ResponseEntity<String>> heartbeat() { logger.trace("Receiving heartbeat request"); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java index 418d7667..270fa584 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.controllers; import io.swagger.annotations.Api; diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AaiNotFoundException.java index a01abc56..9cefd891 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AAINotFoundException.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/AaiNotFoundException.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,14 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.exceptions; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ -public class AAINotFoundException extends PrhTaskException { +public class AaiNotFoundException extends PrhTaskException { - public AAINotFoundException(String message) { + public AaiNotFoundException(String message) { super(message); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java index e83a96e2..9e3b3c1a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapEmptyResponseException.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.exceptions; /** diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java index af22284f..8394916d 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/DmaapNotFoundException.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.exceptions; /** diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java index 45597d05..4d543f4c 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/exceptions/PrhTaskException.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.exceptions; /** diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTask.java index 1bb28504..959dc9cd 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTask.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -21,15 +21,15 @@ package org.onap.dcaegen2.services.prh.tasks; import java.util.Optional; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.service.AAIConsumerClient; +import org.onap.dcaegen2.services.prh.service.AaiConsumerClient; -public abstract class AAIConsumerTask { +public abstract class AaiConsumerTask { - abstract Optional<String> consume(ConsumerDmaapModel message) throws AAINotFoundException; + abstract Optional<String> consume(ConsumerDmaapModel message) throws AaiNotFoundException; - abstract AAIConsumerClient resolveClient(); + abstract AaiConsumerClient resolveClient(); - protected abstract String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException; + protected abstract String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException; } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskImpl.java index c545a1be..63d1e0da 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskImpl.java @@ -17,60 +17,61 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import java.io.IOException; import java.util.Optional; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.onap.dcaegen2.services.prh.configuration.Config; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.service.AAIConsumerClient; +import org.onap.dcaegen2.services.prh.service.AaiConsumerClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class AAIConsumerTaskImpl extends AAIConsumerTask { +public class AaiConsumerTaskImpl extends AaiConsumerTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Config prhAppConfig; - private AAIConsumerClient aaiConsumerClient; + private AaiConsumerClient aaiConsumerClient; @Autowired - public AAIConsumerTaskImpl(AppConfig prhAppConfig) { + public AaiConsumerTaskImpl(AppConfig prhAppConfig) { this.prhAppConfig = prhAppConfig; } @Override - Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException { + Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException { logger.trace("Method called with arg {}", consumerDmaapModel); try { return aaiConsumerClient.getHttpResponse(consumerDmaapModel); } catch (IOException e) { logger.warn("Get request not successful", e); - throw new AAINotFoundException("Get request not successful"); + throw new AaiNotFoundException("Get request not successful"); } } @Override - public String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException { + public String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException { consumerDmaapModel = Optional.ofNullable(consumerDmaapModel) - .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task")); + .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task")); logger.trace("Method called with arg {}", consumerDmaapModel); aaiConsumerClient = resolveClient(); - return consume(consumerDmaapModel).orElseThrow(() -> new AAINotFoundException("Null response code")); + return consume(consumerDmaapModel).orElseThrow(() -> new AaiNotFoundException("Null response code")); } - protected AAIClientConfiguration resolveConfiguration() { - return prhAppConfig.getAAIClientConfiguration(); + protected AaiClientConfiguration resolveConfiguration() { + return prhAppConfig.getAaiClientConfiguration(); } @Override - AAIConsumerClient resolveClient() { - return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AAIConsumerClient(resolveConfiguration())); + AaiConsumerClient resolveClient() { + return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AaiConsumerClient(resolveConfiguration())); } } 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 4a763ef3..abd4fc45 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 @@ -17,21 +17,22 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.service.AAIProducerClient; +import org.onap.dcaegen2.services.prh.service.AaiProducerClient; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ -public abstract class AAIProducerTask { +public abstract class AaiProducerTask { - abstract ConsumerDmaapModel publish(ConsumerDmaapModel message) throws AAINotFoundException; + abstract ConsumerDmaapModel publish(ConsumerDmaapModel message) throws AaiNotFoundException; - abstract AAIProducerClient resolveClient(); + abstract AaiProducerClient resolveClient(); protected abstract ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws PrhTaskException; } 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 b12fb5bb..124a5c63 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 @@ -17,17 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import java.net.URISyntaxException; import java.util.Optional; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.onap.dcaegen2.services.prh.configuration.Config; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.HttpUtils; -import org.onap.dcaegen2.services.prh.service.AAIProducerClient; +import org.onap.dcaegen2.services.prh.service.AaiProducerClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -37,47 +38,47 @@ import org.springframework.stereotype.Component; * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @Component -public class AAIProducerTaskImpl extends - AAIProducerTask { +public class AaiProducerTaskImpl extends + AaiProducerTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Config prhAppConfig; - private AAIProducerClient aaiProducerClient; + private AaiProducerClient aaiProducerClient; @Autowired - public AAIProducerTaskImpl(AppConfig prhAppConfig) { + public AaiProducerTaskImpl(AppConfig prhAppConfig) { this.prhAppConfig = prhAppConfig; } @Override - ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException { + ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException { logger.info("Sending PNF model to AAI {}", consumerDmaapModel); try { return aaiProducerClient.getHttpResponse(consumerDmaapModel) .filter(HttpUtils::isSuccessfulResponseCode).map(response -> consumerDmaapModel).orElseThrow(() -> - new AAINotFoundException("Incorrect response code for continuation of tasks workflow")); + new AaiNotFoundException("Incorrect response code for continuation of tasks workflow")); } catch (URISyntaxException e) { logger.warn("Patch request not successful", e); - throw new AAINotFoundException("Patch request not successful"); + throw new AaiNotFoundException("Patch request not successful"); } } @Override - public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException { + public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException { consumerDmaapModel = Optional.ofNullable(consumerDmaapModel) - .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task")); + .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task")); logger.trace("Method called with arg {}", consumerDmaapModel); aaiProducerClient = resolveClient(); return publish(consumerDmaapModel); } - protected AAIClientConfiguration resolveConfiguration() { - return prhAppConfig.getAAIClientConfiguration(); + protected AaiClientConfiguration resolveConfiguration() { + return prhAppConfig.getAaiClientConfiguration(); } @Override - AAIProducerClient resolveClient() { - return Optional.ofNullable(aaiProducerClient).orElseGet(() -> new AAIProducerClient(resolveConfiguration())); + AaiProducerClient resolveClient() { + return Optional.ofNullable(aaiProducerClient).orElseGet(() -> new AaiProducerClient(resolveConfiguration())); } }
\ No newline at end of file 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 93c287b4..a912ca9e 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 @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; 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 45709aa2..812c04e1 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 @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; @@ -40,7 +41,7 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Config prhAppConfig; private DmaapConsumerJsonParser dmaapConsumerJsonParser; - private DMaaPConsumerReactiveHttpClient dMaaPConsumerReactiveHttpClient; + private DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient; @Autowired public DmaapConsumerTaskImpl(AppConfig prhAppConfig) { @@ -61,9 +62,9 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask { @Override public Mono<ConsumerDmaapModel> execute(String object) { - dMaaPConsumerReactiveHttpClient = resolveClient(); + dmaaPConsumerReactiveHttpClient = resolveClient(); logger.trace("Method called with arg {}", object); - return consume((dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse())); + return consume((dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse())); } @Override @@ -78,8 +79,8 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask { @Override DMaaPConsumerReactiveHttpClient resolveClient() { - return dMaaPConsumerReactiveHttpClient == null + return dmaaPConsumerReactiveHttpClient == null ? new DMaaPConsumerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient()) - : dMaaPConsumerReactiveHttpClient; + : dmaaPConsumerReactiveHttpClient; } } 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 f559683d..9a5813d1 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; 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 673e00f3..4949faa7 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 @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import java.util.Optional; @@ -40,7 +41,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Config prhAppConfig; - private DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient; + private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient; @Autowired public DmaapPublisherTaskImpl(AppConfig prhAppConfig) { @@ -51,14 +52,14 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask { Mono<String> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) { logger.info("Publishing on DMaaP topic {} object {}", resolveConfiguration().dmaapTopicName(), consumerDmaapModel); - return dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel); + return dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel); } @Override public Mono<String> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DmaapNotFoundException { consumerDmaapModel = Optional.ofNullable(consumerDmaapModel) .orElseThrow(() -> new DmaapNotFoundException("Invoked null object to DMaaP task")); - dMaaPProducerReactiveHttpClient = resolveClient(); + dmaapProducerReactiveHttpClient = resolveClient(); logger.trace("Method called with arg {}", consumerDmaapModel); return publish(consumerDmaapModel); } @@ -70,8 +71,8 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask { @Override DMaaPProducerReactiveHttpClient resolveClient() { - return dMaaPProducerReactiveHttpClient == null + return dmaapProducerReactiveHttpClient == null ? new DMaaPProducerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient()) - : dMaaPProducerReactiveHttpClient; + : dmaapProducerReactiveHttpClient; } }
\ No newline at end of file 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 365552b7..26b9e6e7 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import java.util.Optional; @@ -41,11 +42,11 @@ public class ScheduledTasks { private final DmaapConsumerTask dmaapConsumerTask; private final DmaapPublisherTask dmaapProducerTask; - private final AAIProducerTask aaiProducerTask; + private final AaiProducerTask aaiProducerTask; @Autowired public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask, - AAIProducerTask aaiPublisherTask) { + AaiProducerTask aaiPublisherTask) { this.dmaapConsumerTask = dmaapConsumerTask; this.dmaapProducerTask = dmaapPublisherTask; this.aaiProducerTask = aaiPublisherTask; @@ -56,8 +57,8 @@ public class ScheduledTasks { Mono<String> dmaapProducerResponse = Mono.fromCallable(consumeFromDMaaPMessage()) .doOnError(DmaapEmptyResponseException.class, error -> logger.warn("Nothing to consume from DMaaP")) - .map(this::publishToAAIConfiguration) - .flatMap(this::publishToDMaaPConfiguration) + .map(this::publishToAaiConfiguration) + .flatMap(this::publishToDmaapConfiguration) .subscribeOn(Schedulers.elastic()); dmaapProducerResponse.subscribe(this::onSuccess, this::onError, this::onComplete); @@ -78,14 +79,13 @@ public class ScheduledTasks { } private Callable<Mono<ConsumerDmaapModel>> consumeFromDMaaPMessage() { - return () -> - { + return () -> { dmaapConsumerTask.initConfigs(); return dmaapConsumerTask.execute(""); }; } - private Mono<ConsumerDmaapModel> publishToAAIConfiguration(Mono<ConsumerDmaapModel> monoDMaaPModel) { + private Mono<ConsumerDmaapModel> publishToAaiConfiguration(Mono<ConsumerDmaapModel> monoDMaaPModel) { return monoDMaaPModel.flatMap(dmaapModel -> { try { return Mono.just(aaiProducerTask.execute(dmaapModel)); @@ -95,9 +95,9 @@ public class ScheduledTasks { }); } - private Mono<String> publishToDMaaPConfiguration(Mono<ConsumerDmaapModel> monoAAIModel) { + private Mono<String> publishToDmaapConfiguration(Mono<ConsumerDmaapModel> monoAaiModel) { try { - return dmaapProducerTask.execute(monoAAIModel); + return dmaapProducerTask.execute(monoAaiModel); } catch (PrhTaskException e) { return Mono.error(e); } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java index 44a52e6c..71c996bd 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.configuration; import static org.mockito.ArgumentMatchers.any; @@ -39,7 +40,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; +import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 @@ -48,8 +49,30 @@ import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; class PrhAppConfigTest { private static final String PRH_ENDPOINTS = "prh_endpoints.json"; - private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}"; - private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}"; + private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":" + + "\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":" + + "\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\"," + + "\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\"," + + "\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}}," + + "\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\"," + + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222," + + "\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\"" + + ":\"admin\",\"messageLimit\":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":" + + "\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\"," + + "\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}"; + + private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":" + + "\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":\"https\"," + + "\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":" + + "\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":" + + "\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\"" + + ":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\"" + + ":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\"" + + ",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\"" + + ":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\"," + + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\"" + + ":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}"; + private static PrhAppConfig prhAppConfig; private static AppConfig appConfig; @@ -57,13 +80,13 @@ class PrhAppConfigTest { .requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).getFile(); @BeforeEach - public void setUp() { + void setUp() { prhAppConfig = spy(PrhAppConfig.class); appConfig = spy(new AppConfig()); } @Test - public void whenApplicationWasStarted_FilePathIsSet() { + void whenApplicationWasStarted_FilePathIsSet() { // // When // @@ -77,7 +100,7 @@ class PrhAppConfigTest { } @Test - public void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration() + void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration() throws IOException { // // Given @@ -92,13 +115,13 @@ class PrhAppConfigTest { prhAppConfig.initFileStreamReader(); appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration(); appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration(); - appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration(); + appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration(); // // Then // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration()); + Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration()); Assertions @@ -106,12 +129,12 @@ class PrhAppConfigTest { Assertions .assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration()); Assertions - .assertEquals(appConfig.getAAIClientConfiguration(), prhAppConfig.getAAIClientConfiguration()); + .assertEquals(appConfig.getAaiClientConfiguration(), prhAppConfig.getAaiClientConfiguration()); } @Test - public void whenFileIsNotExist_ThrowIOException() { + void whenFileIsNotExist_ThrowIoException() { // // Given // @@ -126,14 +149,14 @@ class PrhAppConfigTest { // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNull(prhAppConfig.getAAIClientConfiguration()); + Assertions.assertNull(prhAppConfig.getAaiClientConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); } @Test - public void whenFileIsExistsButJsonIsIncorrect() throws IOException { + void whenFileIsExistsButJsonIsIncorrect() throws IOException { // // Given // @@ -151,7 +174,7 @@ class PrhAppConfigTest { // verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration()); + Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); @@ -159,7 +182,7 @@ class PrhAppConfigTest { @Test - public void whenTheConfigurationFits_ButRootElementIsNotAJsonObject() + void whenTheConfigurationFits_ButRootElementIsNotAJsonObject() throws IOException { // Given InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes( @@ -173,12 +196,12 @@ class PrhAppConfigTest { prhAppConfig.initFileStreamReader(); appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration(); appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration(); - appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration(); + appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration(); // Then verify(prhAppConfig, times(1)).setFilepath(anyString()); verify(prhAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNull(prhAppConfig.getAAIClientConfiguration()); + Assertions.assertNull(prhAppConfig.getAaiClientConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java index 95e00809..3d1d79fe 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PROJECT * ================================================================================ @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.prh.IT; + +package org.onap.dcaegen2.services.prh.integration; import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import java.util.concurrent.Executors; @@ -28,12 +28,9 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; -import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; +import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -66,18 +63,4 @@ class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests { } } -@Configuration -class ServiceMockProvider { - - @Bean - public PrhAppConfig getPrhAppConfig() { - return mock(PrhAppConfig.class); - } - - @Bean - public ConsumerDmaapModel getRequestDetails() { - return mock(ConsumerDmaapModel.class); - } -} - diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPConsumerResponse.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ServiceMockProvider.java index d2c83e73..2660e3e5 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPConsumerResponse.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ServiceMockProvider.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER + * PROJECT * ================================================================================ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. * ================================================================================ @@ -17,16 +17,29 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.prh.response; -import java.util.List; +package org.onap.dcaegen2.services.prh.integration; + +import static org.mockito.Mockito.mock; + +import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; /** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18 + * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/10/18 */ -public interface DMaaPConsumerResponse extends DMaaPResponse { - +@Configuration +class ServiceMockProvider { - List<String> getFetchedMessages(); + @Bean + public PrhAppConfig getPrhAppConfig() { + return mock(PrhAppConfig.class); + } + @Bean + public ConsumerDmaapModel getRequestDetails() { + return mock(ConsumerDmaapModel.class); + } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/junit5/mockito/MockitoExtension.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/junit5/mockito/MockitoExtension.java index c1e2d752..5c19186b 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/junit5/mockito/MockitoExtension.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/junit5/mockito/MockitoExtension.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PROJECT * ================================================================================ @@ -17,7 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.prh.IT.junit5.mockito; + +package org.onap.dcaegen2.services.prh.integration.junit5.mockito; import static org.mockito.Mockito.mock; @@ -29,15 +30,15 @@ import org.junit.jupiter.api.extension.ExtensionContext.Store; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolver; import org.junit.jupiter.api.extension.TestInstancePostProcessor; -import org.mockito.MockitoAnnotations; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18 * - * {@code MockitoExtension} showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension APIs - * of JUnit 5 by providing dependency injection support at the field level and at the method parameter level via Mockito - * 2.x's {@link Mock @Mock} annotation. + * {@code MockitoExtension } showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension + * APIs of JUnit 5 by providing dependency injection support at the field level and at the method parameter level + * viaMockito 2.x's {@link Mock @Mock} annotation. */ public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver { 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 ba01abfb..cc2a593f 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 @@ -43,26 +43,28 @@ class DmaapConsumerJsonParserTest { void whenPassingCorrectJson_validationNotThrowingAnException() { //given String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" + + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\"," - + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\"," - + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]"; + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":" + + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400" + + ",\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" + + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" + + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" + + "\"Nokia\"}}}]"; String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\"," - + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\"," - + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":" + + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" + + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" + + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" + + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" + + "\"Nokia\"}}}"; ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234") .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") .pnfName("NOKQTFCOC540002E").build(); @@ -79,12 +81,12 @@ class DmaapConsumerJsonParserTest { } @Test - void whenPassingCorrectJsonWithoutIPV4_validationNotThrowingAnException() { + void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() { //given String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" + + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}" + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," @@ -103,9 +105,6 @@ class DmaapConsumerJsonParserTest { + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\"" + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; - ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("") - .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") - .pnfName("NOKQTFCOC540002E").build(); //when DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); @@ -115,17 +114,20 @@ class DmaapConsumerJsonParserTest { ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message))) .block(); //then + ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("") + .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") + .pnfName("NOKQTFCOC540002E").build(); Assertions.assertNotNull(consumerDmaapModel); Assertions.assertEquals(expectedObject, consumerDmaapModel); } @Test - void whenPassingCorrectJsonWihoutIPV6_validationNotThrowingAnException() { + void whenPassingCorrectJsonWihoutIpv6_validationNotThrowingAnException() { //given String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" + + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682," + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate" @@ -158,11 +160,11 @@ class DmaapConsumerJsonParserTest { } @Test - void whenPassingCorrectJsonWihoutIPV4andIPV6_validationThrowingAnException() { + void whenPassingCorrectJsonWihoutIpv4andIpv6_validationThrowingAnException() { String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" + + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" @@ -199,10 +201,11 @@ class DmaapConsumerJsonParserTest { .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); String incorrectMessage = "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"" - + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\"" - + ":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\"," - + "\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}}}]"; + + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" + + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3" + + "}}}]"; StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } @@ -211,13 +214,13 @@ class DmaapConsumerJsonParserTest { void whenPassingJsonWithoutPnfSerialNumberOrPnfVendorName_validationThrowingAnException() { String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":" + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"" - + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\"" - + ":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"" - + "<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":\"v4.5.0.1\"," - + "\"pnfType\":\"AirScale\"}}}"; + + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\"," + + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0," + + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"" + + "version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" + + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" + + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":" + + "\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}"; DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) @@ -225,43 +228,45 @@ class DmaapConsumerJsonParserTest { String jsonWithoutPnfVendorAndSerialNumber = "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":" + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"" - + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\"" - + ":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"" - + "<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":\"v4.5.0.1\"," - + "\"pnfType\":\"AirScale\"}}}]"; + + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\"," + + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0," + + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682," + + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\"," + + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\"," + + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}]"; StepVerifier .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutPnfVendorAndSerialNumber))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } @Test - void whenPassingJsonWithoutIPInformation_validationThrowingAnException() { + void whenPassingJsonWithoutIpInformation_validationThrowingAnException() { String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\":" - + "\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},\"lastEpochMicrosec\"" - + ":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\"," - + "\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":" - + "\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1," - + "\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":" - + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," - + "\"pnfVendorName\":\"Nokia\"}}}"; + "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" + + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" + + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" + + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":" + + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":" + + "\"AirScale\"," + "\"pnfVendorName\":\"Nokia\"}}}"; DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - String jsonWithoutIPInformation = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\":" - + "\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},\"lastEpochMicrosec\"" - + ":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\"," - + "\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":" - + "\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1," - + "\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":" - + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," + String jsonWithoutIpInformation = + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" + + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" + + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" + + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSerialNumber\"" + + ":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," + "\"pnfVendorName\":\"Nokia\"}}}]"; - StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIPInformation))) + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskImplTest.java index 570cb2a0..8af562b2 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskImplTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.ArgumentMatchers.any; @@ -34,22 +35,22 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; -import org.onap.dcaegen2.services.prh.config.ImmutableAAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; 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.prh.service.AAIConsumerClient; +import org.onap.dcaegen2.services.prh.service.AaiConsumerClient; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18 */ -class AAIConsumerTaskImplTest { +class AaiConsumerTaskImplTest { private static ConsumerDmaapModel consumerDmaapModel; - private static AAIConsumerTaskImpl aaiConsumerTask; + private static AaiConsumerTaskImpl aaiConsumerTask; private static final String AAI_HOST = "/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E"; private static final Integer PORT = 1234; @@ -58,19 +59,19 @@ class AAIConsumerTaskImplTest { private static final String BASE_PATH = "/aai/v12"; private static final String PNF_PATH = "/network/pnfs/pnf"; - private static AAIClientConfiguration aaiClientConfiguration; - private static AAIConsumerClient aaiConsumerClient; + private static AaiClientConfiguration aaiClientConfiguration; + private static AaiConsumerClient aaiConsumerClient; private static AppConfig appConfig; @BeforeAll - public static void setUp() { - aaiClientConfiguration = new ImmutableAAIClientConfiguration.Builder() + static void setUp() { + aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder() .aaiHost(AAI_HOST) .aaiHostPortNumber(PORT) .aaiProtocol(PROTOCOL) .aaiUserName(USER_NAME_PASSWORD) .aaiUserPassword(USER_NAME_PASSWORD) - .aaiIgnoreSSLCertificateErrors(true) + .aaiIgnoreSslCertificateErrors(true) .aaiBasePath(BASE_PATH) .aaiPnfPath(PNF_PATH) .build(); @@ -82,10 +83,10 @@ class AAIConsumerTaskImplTest { } @Test - public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { + void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { //given/when - when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration); - aaiConsumerTask = new AAIConsumerTaskImpl(appConfig); + when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration); + aaiConsumerTask = new AaiConsumerTaskImpl(appConfig); Executable executableCode = () -> aaiConsumerTask.execute(null); //then Assertions @@ -94,9 +95,9 @@ class AAIConsumerTaskImplTest { } @Test - public void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, IOException { + void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, IOException { //given/when - getAAIConsumerTask_WhenMockingHttpResponseCode("200", false); + getAaiConsumerTask_WhenMockingHttpResponseCode("200", false); String response = aaiConsumerTask.execute(consumerDmaapModel); //then @@ -106,9 +107,9 @@ class AAIConsumerTaskImplTest { } @Test - public void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, AAINotFoundException { + void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, AaiNotFoundException { //given/when - getAAIConsumerTask_WhenMockingHttpResponseCode("400", false); + getAaiConsumerTask_WhenMockingHttpResponseCode("400", false); String response = aaiConsumerTask.execute(consumerDmaapModel); //then @@ -118,9 +119,9 @@ class AAIConsumerTaskImplTest { } @Test - public void whenPassedObjectFits_ThrowsIOExceptionAndHandleIt() throws IOException { + void whenPassedObjectFits_ThrowsIoExceptionAndHandleIt() throws IOException { //given/when - getAAIConsumerTask_WhenMockingHttpResponseCode(null, true); + getAaiConsumerTask_WhenMockingHttpResponseCode(null, true); Executable executableCode = () -> aaiConsumerTask.execute(any(ConsumerDmaapModel.class)); Assertions .assertThrows(PrhTaskException.class, executableCode, "HttpClient throws IOException"); @@ -130,16 +131,16 @@ class AAIConsumerTaskImplTest { } - private static void getAAIConsumerTask_WhenMockingHttpResponseCode(String httpResponseCode, boolean throwsException) + private static void getAaiConsumerTask_WhenMockingHttpResponseCode(String httpResponseCode, boolean throwsException) throws IOException { - aaiConsumerClient = mock(AAIConsumerClient.class); + aaiConsumerClient = mock(AaiConsumerClient.class); if (throwsException) { when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenThrow(IOException.class); } else { when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of(httpResponseCode)); } - when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration); - aaiConsumerTask = spy(new AAIConsumerTaskImpl(appConfig)); + when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration); + aaiConsumerTask = spy(new AaiConsumerTaskImpl(appConfig)); when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration); doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient(); } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskSpy.java index e2b81373..5106269e 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiConsumerTaskSpy.java @@ -17,26 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import static org.mockito.Mockito.*; - - @Configuration -public class AAIConsumerTaskSpy { +public class AaiConsumerTaskSpy { @Bean @Primary - public AAIConsumerTask registerSimpleAAIPublisherTask() { + public AaiConsumerTask registerSimpleAaiPublisherTask() { AppConfig appConfig = mock(AppConfig.class); - when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class)); - return spy(new AAIConsumerTaskImpl(appConfig)); + when(appConfig.getAaiClientConfiguration()).thenReturn(mock(AaiClientConfiguration.class)); + return spy(new AaiConsumerTaskImpl(appConfig)); } }
\ No newline at end of file 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 70da39b7..5e60bf0f 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 @@ -36,19 +36,22 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; -import org.onap.dcaegen2.services.prh.config.ImmutableAAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration; + +import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; + 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.prh.configuration.AppConfig; -import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; -import org.onap.dcaegen2.services.prh.service.AAIProducerClient; + +import org.onap.dcaegen2.services.prh.service.AaiProducerClient; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/14/18 */ -class AAIProducerTaskImplTest { +class AaiProducerTaskImplTest { private static final String AAI_HOST = "/aai/v11/network/pnfs/pnf/NOKQTFCOC540002E"; @@ -59,20 +62,20 @@ class AAIProducerTaskImplTest { private static final String PNF_PATH = "/network/pnfs/pnf"; private static ConsumerDmaapModel consumerDmaapModel; - private static AAIProducerTaskImpl aaiProducerTask; - private static AAIClientConfiguration aaiClientConfiguration; - private static AAIProducerClient aaiProducerClient; + private static AaiProducerTaskImpl aaiProducerTask; + private static AaiClientConfiguration aaiClientConfiguration; + private static AaiProducerClient aaiProducerClient; private static AppConfig appConfig; @BeforeAll - public static void setUp() { - aaiClientConfiguration = new ImmutableAAIClientConfiguration.Builder() + static void setUp() { + aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder() .aaiHost(AAI_HOST) .aaiHostPortNumber(PORT) .aaiProtocol(PROTOCOL) .aaiUserName(USER_NAME_PASSWORD) .aaiUserPassword(USER_NAME_PASSWORD) - .aaiIgnoreSSLCertificateErrors(true) + .aaiIgnoreSslCertificateErrors(true) .aaiBasePath(BASE_PATH) .aaiPnfPath(PNF_PATH) .build(); @@ -84,10 +87,10 @@ class AAIProducerTaskImplTest { } @Test - public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { + void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { //given/when/ - when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration); - aaiProducerTask = new AAIProducerTaskImpl(appConfig); + when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration); + aaiProducerTask = new AaiProducerTaskImpl(appConfig); Executable executableCode = () -> aaiProducerTask.execute(null); //then @@ -96,9 +99,9 @@ class AAIProducerTaskImplTest { } @Test - public void whenPassedObjectFits_ReturnsCorrectStatus() throws AAINotFoundException, URISyntaxException { + void whenPassedObjectFits_ReturnsCorrectStatus() throws AaiNotFoundException, URISyntaxException { //given/when - getAAIProducerTask_whenMockingResponseObject(200, false); + getAaiProducerTask_whenMockingResponseObject(200, false); ConsumerDmaapModel response = aaiProducerTask.execute(consumerDmaapModel); //then @@ -110,9 +113,9 @@ class AAIProducerTaskImplTest { @Test - public void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, URISyntaxException { + void whenPassedObjectFits_butIncorrectResponseReturns() throws URISyntaxException { //given/when - getAAIProducerTask_whenMockingResponseObject(400, false); + getAaiProducerTask_whenMockingResponseObject(400, false); Executable executableCode = () -> aaiProducerTask.execute(consumerDmaapModel); Assertions .assertThrows(PrhTaskException.class, executableCode, "Incorrect status code in response message"); @@ -122,9 +125,9 @@ class AAIProducerTaskImplTest { } @Test - public void whenPassedObjectFits_butHTTPClientThrowsIOExceptionHandleIt() throws URISyntaxException { + void whenPassedObjectFits_butHttpClientThrowsIoExceptionHandleIt() throws URISyntaxException { //given/when - getAAIProducerTask_whenMockingResponseObject(0, true); + getAaiProducerTask_whenMockingResponseObject(0, true); Executable executableCode = () -> aaiProducerTask.execute(consumerDmaapModel); Assertions @@ -135,17 +138,17 @@ class AAIProducerTaskImplTest { } - private static void getAAIProducerTask_whenMockingResponseObject(int statusCode, boolean throwsException) + private static void getAaiProducerTask_whenMockingResponseObject(int statusCode, boolean throwsException) throws URISyntaxException { //given - aaiProducerClient = mock(AAIProducerClient.class); + aaiProducerClient = mock(AaiProducerClient.class); if (throwsException) { when(aaiProducerClient.getHttpResponse(consumerDmaapModel)).thenThrow(URISyntaxException.class); } else { when(aaiProducerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of(statusCode)); } - when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration); - aaiProducerTask = spy(new AAIProducerTaskImpl(appConfig)); + when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration); + aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig)); when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration); doReturn(aaiProducerClient).when(aaiProducerTask).resolveClient(); } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiPublisherTaskSpy.java index 762a251d..3a66bd47 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiPublisherTaskSpy.java @@ -17,31 +17,34 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; -import org.onap.dcaegen2.services.prh.service.AAIProducerClient; +import org.onap.dcaegen2.services.prh.service.AaiProducerClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import static org.mockito.Mockito.*; - /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18 */ @Configuration -public class AAIPublisherTaskSpy { +public class AaiPublisherTaskSpy { @Bean @Primary - public AAIProducerTask registerSimpleAAIPublisherTask() { + public AaiProducerTask registerSimpleAaiPublisherTask() { AppConfig appConfig = spy(AppConfig.class); - doReturn(mock(AAIClientConfiguration.class)).when(appConfig).getAAIClientConfiguration(); - AAIProducerTaskImpl aaiProducerTask = spy(new AAIProducerTaskImpl(appConfig)); - AAIProducerClient aaiProducerClient = mock(AAIProducerClient.class); - doReturn(mock(AAIClientConfiguration.class)).when(aaiProducerTask).resolveConfiguration(); + doReturn(mock(AaiClientConfiguration.class)).when(appConfig).getAaiClientConfiguration(); + AaiProducerTaskImpl aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig)); + AaiProducerClient aaiProducerClient = mock(AaiProducerClient.class); + doReturn(mock(AaiClientConfiguration.class)).when(aaiProducerTask).resolveConfiguration(); doReturn(aaiProducerClient).when(aaiProducerTask).resolveClient(); return aaiProducerTask; } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java index b903fc90..6baa7463 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,7 +31,6 @@ import static org.mockito.Mockito.when; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import java.util.Optional; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -38,7 +38,6 @@ import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; 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.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser; @@ -60,40 +59,42 @@ class DmaapConsumerTaskImplTest { private static String parsed; @BeforeAll - public static void setUp() { + static void setUp() { dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder().consumerGroup("OpenDCAE-c12") .consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234) .dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH") - .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMS(-1).messageLimit(-1).build(); + .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMs(-1).messageLimit(-1).build(); consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234") .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") .pnfName("NOKQTFCOC540002E").build(); appConfig = mock(AppConfig.class); message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" + + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\"," - + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\"," - + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]"; + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" + + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" + + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" + + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" + + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" + + "\"Nokia\"}}}]"; parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}," - + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\"," - + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\"," - + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; + + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682," + + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\"," + + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\"," + + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," + + "\"pnfVendorName\":\"Nokia\"}}}"; } @Test - public void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() throws PrhTaskException { + void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() { //given prepareMocksForDmaapConsumer(Optional.empty()); @@ -105,7 +106,7 @@ class DmaapConsumerTaskImplTest { } @Test - public void whenPassedObjectFits_ReturnsCorrectResponse() throws PrhTaskException { + void whenPassedObjectFits_ReturnsCorrectResponse() { //given prepareMocksForDmaapConsumer(Optional.of(message)); //when diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java index 97c75ce0..2d83b2de 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.Mockito.doReturn; @@ -42,10 +43,10 @@ public class DmaapConsumerTaskSpy { AppConfig appConfig = spy(AppConfig.class); doReturn(mock(DmaapConsumerConfiguration.class)).when(appConfig).getDmaapConsumerConfiguration(); DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig)); - DMaaPConsumerReactiveHttpClient DMaaPConsumerReactiveHttpClient = mock( + DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient = mock( DMaaPConsumerReactiveHttpClient.class); doReturn(mock(DmaapConsumerConfiguration.class)).when(dmaapConsumerTask).resolveConfiguration(); - doReturn(DMaaPConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient(); + doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient(); return dmaapConsumerTask; } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java index ceb0ed81..622ab621 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.Mockito.doReturn; 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 25d1fff6..e0419e8f 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 @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -56,7 +57,7 @@ class DmaapPublisherTaskImplTest { private static DmaapPublisherConfiguration dmaapPublisherConfiguration; @BeforeAll - public static void setUp() { + static void setUp() { dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder() .dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234) .dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH") @@ -68,7 +69,7 @@ class DmaapPublisherTaskImplTest { } @Test - public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { + void whenPassedObjectDoesntFit_ThrowsPrhTaskException() { //given when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration); dmaapPublisherTask = new DmaapPublisherTaskImpl(appConfig); @@ -81,7 +82,7 @@ class DmaapPublisherTaskImplTest { } @Test - public void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException { + void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException { //given prepareMocksForTests(HttpStatus.OK.value()); @@ -97,7 +98,7 @@ class DmaapPublisherTaskImplTest { @Test - public void whenPassedObjectFits_butIncorrectResponseReturns() throws DmaapNotFoundException { + void whenPassedObjectFits_butIncorrectResponseReturns() throws DmaapNotFoundException { //given prepareMocksForTests(HttpStatus.UNAUTHORIZED.value()); diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java index 2bff9e02..28692af3 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduleControllerSpy.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.Mockito.spy; @@ -39,7 +40,7 @@ public class ScheduleControllerSpy { private DmaapPublisherTask dmaapPublisherTaskImplSpy; @Autowired - private AAIProducerTask aaiPublisherTaskImplSpy; + private AaiProducerTask aaiPublisherTaskImplSpy; @Bean @Primary 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 7dba211f..4c99ba3a 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 @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.model; import com.google.gson.annotations.SerializedName; diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelForUnitTest.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelForUnitTest.java index 7b48bd80..76f51749 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelForUnitTest.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelForUnitTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtils.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtils.java index b280949e..11fca099 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtils.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtils.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.model.utils; import org.apache.http.HttpStatus; diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java index 90e42e38..d4c947fd 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java @@ -20,27 +20,24 @@ package org.onap.dcaegen2.services.prh.model; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; import org.apache.http.StatusLine; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.io.IOException; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - class CommonFunctionsTest { + // Given private ConsumerDmaapModel model = 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); + private static final HttpResponse httpResponseMock = mock(HttpResponse.class); + private static final HttpEntity httpEntityMock = mock(HttpEntity.class); + private static final StatusLine statusLineMock = mock(StatusLine.class); @BeforeAll static void setup() { @@ -50,7 +47,8 @@ class CommonFunctionsTest { @Test void createJsonBody_shouldReturnJsonInString() { - String expectedResult = "{\"pnf-name\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}"; + String expectedResult = "{\"pnf-name\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\"" + + ",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}"; assertEquals(expectedResult, CommonFunctions.createJsonBody(model)); } } diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java index c54bac11..6b2f9abc 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -23,28 +23,26 @@ package org.onap.dcaegen2.services.prh.model; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class ConsumerDmaapModelTest { - - // Given - private ConsumerDmaapModel consumerDmaapModel; - private String pnfName = "NOKnhfsadhff"; - private String ipv4 = "11.22.33.155"; - private String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; +class ConsumerDmaapModelTest { @Test - public void consumerDmaapModelBuilder_shouldBuildAnObject() { + void consumerDmaapModelBuilder_shouldBuildAnObject() { // When - consumerDmaapModel = ImmutableConsumerDmaapModel.builder() - .pnfName(pnfName) - .ipv4(ipv4) - .ipv6(ipv6) - .build(); + // Given + String pnfName = "NOKnhfsadhff"; + String ipv4 = "11.22.33.155"; + String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; + ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .pnfName(pnfName) + .ipv4(ipv4) + .ipv6(ipv6) + .build(); // Then Assertions.assertNotNull(consumerDmaapModel); - Assertions.assertEquals(pnfName,consumerDmaapModel.getPnfName()); - Assertions.assertEquals(ipv4,consumerDmaapModel.getIpv4()); - Assertions.assertEquals(ipv6,consumerDmaapModel.getIpv6()); + Assertions.assertEquals(pnfName, consumerDmaapModel.getPnfName()); + Assertions.assertEquals(ipv4, consumerDmaapModel.getIpv4()); + Assertions.assertEquals(ipv6, consumerDmaapModel.getIpv6()); } } diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtilsTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtilsTest.java index d7295071..334bd1bb 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtilsTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/utils/HttpUtilsTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,22 +20,21 @@ package org.onap.dcaegen2.services.prh.model.utils; -import org.apache.http.HttpStatus; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; -public class HttpUtilsTest { +class HttpUtilsTest { @Test - public void isSuccessfulResponseCode_shouldReturnTrue() { + void isSuccessfulResponseCode_shouldReturnTrue() { assertTrue(HttpUtils.isSuccessfulResponseCode(HttpUtils.SC_ACCEPTED)); } @Test - public void isSuccessfulResponseCode_shouldReturnFalse() { + void isSuccessfulResponseCode_shouldReturnFalse() { assertFalse(HttpUtils.isSuccessfulResponseCode(HttpStatus.SC_BAD_GATEWAY)); } }
\ No newline at end of file diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java index 89d3bd4c..6663554e 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapConsumerConfiguration.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.config; import org.immutables.gson.Gson; @@ -41,7 +42,7 @@ public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig { public abstract String consumerGroup(); @Value.Parameter - public abstract Integer timeoutMS(); + public abstract Integer timeoutMs(); @Value.Parameter public abstract Integer messageLimit(); @@ -54,7 +55,7 @@ public abstract class DmaapConsumerConfiguration implements DmaapCustomConfig { Builder consumerGroup(String consumerGroup); - Builder timeoutMS(Integer timeoutMS); + Builder timeoutMs(Integer timeoutMs); Builder messageLimit(Integer messageLimit); } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java index ecc9d211..6e7f538a 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapCustomConfig.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.config; import java.io.Serializable; diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java index 2e95463c..e353056f 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/config/DmaapPublisherConfiguration.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.config; import org.immutables.gson.Gson; diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPConsumerResponseImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPConsumerResponseImpl.java deleted file mode 100644 index ddac9cbf..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPConsumerResponseImpl.java +++ /dev/null @@ -1,72 +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.response; - -import static java.util.Collections.unmodifiableList; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.StringJoiner; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18 - */ -public class DMaaPConsumerResponseImpl implements DMaaPConsumerResponse { - - - private final Integer responseCode; - private final String responseMessage; - private final List<String> fetchedMessage; - - public DMaaPConsumerResponseImpl(@NonNull Integer responseCode, @NonNull String responseMessage, - @Nullable List<String> fetchedMessage) { - this.responseCode = responseCode; - this.responseMessage = responseMessage; - this.fetchedMessage = Optional.ofNullable(fetchedMessage).orElse(Collections.emptyList()); - } - - - @Override - public String getResponseMessage() { - return responseMessage; - } - - @Override - public Integer getResponseCode() { - return responseCode; - } - - @Override - public List<String> getFetchedMessages() { - return unmodifiableList(fetchedMessage); - } - - @Override - public String toString() { - return new StringJoiner(", ", this.getClass().getSimpleName() + "[", "]") - .add("responseCode=" + responseCode) - .add("responseMessage=" + responseMessage) - .add("fetchedMessage=" + fetchedMessage) - .toString(); - } -} diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPResponse.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPResponse.java deleted file mode 100644 index 5bf199c0..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/response/DMaaPResponse.java +++ /dev/null @@ -1,32 +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.response; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18 - */ -public interface DMaaPResponse { - - Integer getResponseCode(); - - - String getResponseMessage(); -} diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java index ab81bede..b0cca3f3 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service; import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; @@ -36,21 +37,21 @@ public class DMaaPReactiveWebClient { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private String dMaaPContentType; - private String dMaaPUserName; - private String dMaaPUserPassword; + private String dmaaPContentType; + private String dmaaPUserName; + private String dmaaPUserPassword; public DMaaPReactiveWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) { - this.dMaaPUserName = dmaapCustomConfig.dmaapUserName(); - this.dMaaPUserPassword = dmaapCustomConfig.dmaapUserPassword(); - this.dMaaPContentType = dmaapCustomConfig.dmaapContentType(); + this.dmaaPUserName = dmaapCustomConfig.dmaapUserName(); + this.dmaaPUserPassword = dmaapCustomConfig.dmaapUserPassword(); + this.dmaaPContentType = dmaapCustomConfig.dmaapContentType(); return this; } public WebClient build() { return WebClient.builder() - .defaultHeader(HttpHeaders.CONTENT_TYPE, dMaaPContentType) - .filter(basicAuthentication(dMaaPUserName, dMaaPUserPassword)) + .defaultHeader(HttpHeaders.CONTENT_TYPE, dmaaPContentType) + .filter(basicAuthentication(dmaaPUserName, dmaaPUserPassword)) .filter(logRequest()) .filter(logResponse()) .build(); diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java index 23cdc98d..af54bf3b 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClient.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service.consumer; import java.net.URI; diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java index e29ecc64..0bc78d43 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClient.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service.producer; import java.net.URI; diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java index 2e323c5e..ee88f1f8 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service; import static org.mockito.Mockito.mock; @@ -30,28 +31,27 @@ import org.springframework.web.reactive.function.client.WebClient; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/5/18 */ -public class DMaaPReactiveWebClientTest { +class DMaaPReactiveWebClientTest { @Test - public void builder_shouldBuildDMaaPReactiveWebClient() { + void builder_shouldBuildDMaaPReactiveWebClient() { //given DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class); - WebClient dMaaPReactiveWebClient; - String dMaaPContentType = "*/*"; - String dMaaPUserName = "DMaaP"; - String dMaaPUserPassword = "DMaaP"; + String dmaaPContentType = "*/*"; + String dmaaPUserName = "DMaaP"; + String dmaaPUserPassword = "DMaaP"; //when - when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn(dMaaPContentType); - when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dMaaPUserName); - when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dMaaPUserPassword); - dMaaPReactiveWebClient = new DMaaPReactiveWebClient() + when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn(dmaaPContentType); + when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dmaaPUserName); + when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dmaaPUserPassword); + WebClient dmaapreactiveWebClient = new DMaaPReactiveWebClient() .fromConfiguration(dmaapConsumerConfiguration) .build(); //then - Assertions.assertNotNull(dMaaPReactiveWebClient); + Assertions.assertNotNull(dmaapreactiveWebClient); } }
\ No newline at end of file diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java index 96939771..2239d110 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java @@ -25,10 +25,10 @@ import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration; -public class DmaapConsumerConfigurationTest { +class DmaapConsumerConfigurationTest { @Test - public void builder_shouldBuildConfigurationObject() { + void builder_shouldBuildConfigurationObject() { // Given DmaapConsumerConfiguration configuration; @@ -55,7 +55,7 @@ public class DmaapConsumerConfigurationTest { .dmaapUserPassword(dmaapUserPassword) .dmaapContentType(dmaapContentType) .consumerGroup(consumerGroup) - .timeoutMS(timeoutMs) + .timeoutMs(timeoutMs) .messageLimit(messageLimit) .build(); @@ -69,7 +69,7 @@ public class DmaapConsumerConfigurationTest { Assertions.assertEquals(dmaapUserName, configuration.dmaapUserName()); Assertions.assertEquals(dmaapUserPassword, configuration.dmaapUserPassword()); Assertions.assertEquals(consumerGroup, configuration.consumerGroup()); - Assertions.assertEquals(timeoutMs, configuration.timeoutMS()); + Assertions.assertEquals(timeoutMs, configuration.timeoutMs()); Assertions.assertEquals(messageLimit, configuration.messageLimit()); } } diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java index 47dd30f4..f4a8f107 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -25,11 +25,11 @@ import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration; -public class DmaapPublisherConfigurationTest { +class DmaapPublisherConfigurationTest { @Test - public void builder_shouldBuildConfigurationObject() { + void builder_shouldBuildConfigurationObject() { // Given DmaapPublisherConfiguration configuration; diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java index 1f04da15..9a46b2a9 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service.consumer; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -30,11 +30,10 @@ import static org.springframework.web.reactive.function.client.ExchangeFilterFun import java.net.URI; import java.net.URISyntaxException; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; @@ -44,20 +43,20 @@ import reactor.test.StepVerifier; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/27/18 */ -public class DMaaPConsumerReactiveHttpClientTest { +class DMaaPConsumerReactiveHttpClientTest { - private static DMaaPConsumerReactiveHttpClient DMaaPConsumerReactiveHttpClient; + private DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient; - private static DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class); + private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class); private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}"; - private static Mono<String> expectedResult = Mono.empty(); - private static WebClient webClient = mock(WebClient.class); - private static RequestHeadersUriSpec requestHeadersSpec; - private static ResponseSpec responseSpec; + private Mono<String> expectedResult = Mono.empty(); + private WebClient webClient = mock(WebClient.class); + private RequestHeadersUriSpec requestHeadersSpec; + private ResponseSpec responseSpec; - @BeforeAll - public static void setUp() { + @BeforeEach + void setUp() { when(consumerConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2"); when(consumerConfigurationMock.dmaapProtocol()).thenReturn("https"); when(consumerConfigurationMock.dmaapPortNumber()).thenReturn(1234); @@ -68,7 +67,7 @@ public class DMaaPConsumerReactiveHttpClientTest { when(consumerConfigurationMock.consumerGroup()).thenReturn("OpenDCAE-c12"); when(consumerConfigurationMock.consumerId()).thenReturn("c12"); - DMaaPConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock); + dmaapConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock); webClient = spy(WebClient.builder() .defaultHeader(HttpHeaders.CONTENT_TYPE, consumerConfigurationMock.dmaapContentType()) .filter(basicAuthentication(consumerConfigurationMock.dmaapUserName(), @@ -80,15 +79,15 @@ public class DMaaPConsumerReactiveHttpClientTest { @Test - public void getHttpResponse_Success() { + void getHttpResponse_Success() { //given expectedResult = Mono.just(JSON_MESSAGE); //when mockDependantObjects(); doReturn(expectedResult).when(responseSpec).bodyToMono(String.class); - DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient); - Mono<String> response = DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse(); + dmaapConsumerReactiveHttpClient.createDMaaPWebClient(webClient); + Mono<String> response = dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse(); //then StepVerifier.create(response).expectSubscription() @@ -99,16 +98,16 @@ public class DMaaPConsumerReactiveHttpClientTest { } @Test - public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException { + void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException { //given - DMaaPConsumerReactiveHttpClient = spy(DMaaPConsumerReactiveHttpClient); + dmaapConsumerReactiveHttpClient = spy(dmaapConsumerReactiveHttpClient); //when when(webClient.get()).thenReturn(requestHeadersSpec); - DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient); - when(DMaaPConsumerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class); + dmaapConsumerReactiveHttpClient.createDMaaPWebClient(webClient); + when(dmaapConsumerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class); //then - StepVerifier.create(DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription() + StepVerifier.create(dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription() .expectError(Exception.class).verify(); } diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java index 20ab64e5..b5e730a0 100644 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.prh.service.producer; import static org.mockito.ArgumentMatchers.any; @@ -29,7 +30,7 @@ import static org.springframework.web.reactive.function.client.ExchangeFilterFun import java.net.URI; import java.net.URISyntaxException; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; @@ -45,21 +46,20 @@ import reactor.test.StepVerifier; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 */ -public class DMaaPProducerReactiveHttpClientTest { +class DMaaPProducerReactiveHttpClientTest { - private static DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient; + private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient; - private static DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock( + private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock( DmaapPublisherConfiguration.class); - private static final Integer RESPONSE_SUCCESS = 200; - private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest(); - private static WebClient webClient = mock(WebClient.class); - private static RequestBodyUriSpec requestBodyUriSpec; - private static ResponseSpec responseSpec; + private ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest(); + private WebClient webClient = mock(WebClient.class); + private RequestBodyUriSpec requestBodyUriSpec; + private ResponseSpec responseSpec; - @BeforeAll - public static void setUp() { + @BeforeEach + void setUp() { when(dmaapPublisherConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2"); when(dmaapPublisherConfigurationMock.dmaapProtocol()).thenReturn("https"); when(dmaapPublisherConfigurationMock.dmaapPortNumber()).thenReturn(1234); @@ -68,7 +68,7 @@ public class DMaaPProducerReactiveHttpClientTest { when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json"); when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("pnfReady"); - dMaaPProducerReactiveHttpClient = new DMaaPProducerReactiveHttpClient(dmaapPublisherConfigurationMock); + dmaapProducerReactiveHttpClient = new DMaaPProducerReactiveHttpClient(dmaapPublisherConfigurationMock); webClient = spy(WebClient.builder() .defaultHeader(HttpHeaders.CONTENT_TYPE, dmaapPublisherConfigurationMock.dmaapContentType()) @@ -80,31 +80,32 @@ public class DMaaPProducerReactiveHttpClientTest { } @Test - public void getHttpResponse_Success() { + void getHttpResponse_Success() { //given - Mono<Integer> expectedResult = Mono.just(RESPONSE_SUCCESS); + Integer responseSuccess = 200; + Mono<Integer> expectedResult = Mono.just(responseSuccess); //when mockWebClientDependantObject(); doReturn(expectedResult).when(responseSpec).bodyToMono(String.class); - dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient); - Mono<String> response = dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel)); + dmaapProducerReactiveHttpClient.createDMaaPWebClient(webClient); + Mono<String> response = dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel)); //then Assertions.assertEquals(response.block(), expectedResult.block()); } @Test - public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException { + void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException { //given - dMaaPProducerReactiveHttpClient = spy(dMaaPProducerReactiveHttpClient); + dmaapProducerReactiveHttpClient = spy(dmaapProducerReactiveHttpClient); //when when(webClient.post()).thenReturn(requestBodyUriSpec); - dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient); - when(dMaaPProducerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class); + dmaapProducerReactiveHttpClient.createDMaaPWebClient(webClient); + when(dmaapProducerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class); //then - StepVerifier.create(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription() + StepVerifier.create(dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription() .expectError(Exception.class).verify(); } |