AAI tasks added 31/44931/2
authorpwielebs <piotr.wielebski@nokia.com>
Thu, 26 Apr 2018 15:04:09 +0000 (17:04 +0200)
committerpwielebs <piotr.wielebski@nokia.com>
Fri, 27 Apr 2018 13:38:11 +0000 (15:38 +0200)
- aaiClients spllitted for consuming and producing
- http removed from names of all clients and interfaces
- HttpRequestDetails added as a second parameter for tasks
- parameters required from dmaap consumer
 - pnf-name for URI (get request -> aaiConsumer)
 - pnf-name and ipv4-oam (and or ipv6-oam)
   (patch request -> aaiProducer)

Change-Id: I87a1b46ab419cd00e9573e08c4d89cb384dd75b5
Issue-ID: DCAEGEN2-451
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
29 files changed:
prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIClientConfiguration.java [moved from prh-aai-client/src/main/java/org/onap/dcaegen2/services/config/AAIHttpClientConfiguration.java with 95% similarity]
prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClient.java [moved from prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIHttpClient.java with 97% similarity]
prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIClientImpl.java [moved from prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIHttpClientImpl.java with 91% similarity]
prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java [new file with mode: 0644]
prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIProducerClient.java [moved from prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java with 64% similarity]
prh-aai-client/src/main/java/org/onap/dcaegen2/services/utils/HttpRequestDetails.java
prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java [new file with mode: 0644]
prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java
prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java [moved from prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImplTest.java with 53% similarity]
prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java
prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
prh-app-server/pom.xml
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java [new file with mode: 0644]
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java [new file with mode: 0644]
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTask.java [moved from prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTask.java with 95% similarity]
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java [moved from prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java with 65% similarity]
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java
prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskSpy.java [new file with mode: 0644]
prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskSpy.java
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.config;
 
 
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
 @Value.Immutable(prehash = true)
 @Value.Style(builder = "new")
 @Gson.TypeAdapters
-public abstract class AAIHttpClientConfiguration implements Serializable {
+public abstract class AAIClientConfiguration implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
@@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.service;
 import org.apache.http.impl.client.CloseableHttpClient;
 
 @FunctionalInterface
-public interface AAIHttpClient {
+public interface AAIClient {
     CloseableHttpClient getAAIHttpClient();
 }
 
@@ -31,7 +31,7 @@ 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.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,14 +40,14 @@ import java.security.KeyManagementException;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 
-public class AAIHttpClientImpl implements AAIHttpClient {
+public class AAIClientImpl implements AAIClient {
 
-    Logger logger = LoggerFactory.getLogger(AAIHttpClientImpl.class);
+    Logger logger = LoggerFactory.getLogger(AAIClientImpl.class);
 
-    private AAIHttpClientConfiguration aaiHttpClientConfig;
+    private AAIClientConfiguration aaiHttpClientConfig;
 
     @Autowired
-    public AAIHttpClientImpl(AAIHttpClientConfiguration aaiHttpClientConfiguration) {
+    public AAIClientImpl(AAIClientConfiguration aaiHttpClientConfiguration) {
         this.aaiHttpClientConfig = aaiHttpClientConfiguration;
     }
 
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIConsumerClient.java
new file mode 100644 (file)
index 0000000..24790be
--- /dev/null
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.service;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+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.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.onap.dcaegen2.services.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.Optional;
+
+public class AAIConsumerClient implements AAIExtendedHttpClient {
+
+    Logger logger = LoggerFactory.getLogger(AAIConsumerClient.class);
+
+    private final CloseableHttpClient closeableHttpClient;
+    private final String aaiHost;
+    private final String aaiProtocol;
+    private final Integer aaiHostPortNumber;
+
+
+    public AAIConsumerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
+        final AAIClient aaiClient = new AAIClientImpl(aaiHttpClientConfiguration);
+        closeableHttpClient = aaiClient.getAAIHttpClient();
+        aaiHost = aaiHttpClientConfiguration.aaiHost();
+        aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
+        aaiHostPortNumber = aaiHttpClientConfiguration.aaiHostPortNumber();
+    }
+
+    @Override
+    public Optional<String> getHttpResponse(HttpRequestDetails requestDetails) {
+
+        Optional<String> extendedDetails = Optional.empty();
+        Optional<HttpRequestBase> request = createRequest(requestDetails);
+
+        try {
+            extendedDetails = closeableHttpClient.execute(request.get(), aaiResponseHandler());
+        } catch (IOException e) {
+            logger.error("Exception while executing HTTP request: {}", e);
+        }
+
+        return extendedDetails;
+    }
+
+
+    private URI createAAIExtendedURI(final String path, String pnfName) {
+
+        URI extendedURI = null;
+
+        final URIBuilder uriBuilder = new URIBuilder()
+                .setScheme(aaiProtocol)
+                .setHost(aaiHost)
+                .setPort(aaiHostPortNumber)
+                .setPath(path + "/" + pnfName);
+
+        try {
+            extendedURI = uriBuilder.build();
+            logger.info("Building extended URI: {}", extendedURI);
+        } catch (URISyntaxException e) {
+            logger.error("Exception while building extended URI: {}", e);
+        }
+
+        return extendedURI;
+    }
+
+    private ResponseHandler<Optional<String>> aaiResponseHandler() {
+        return httpResponse ->  {
+            final int responseCode = httpResponse.getStatusLine().getStatusCode();
+            logger.info("Status code of operation: {}", responseCode);
+            final HttpEntity responseEntity = httpResponse.getEntity();
+
+            if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
+                logger.info("HTTP response successful.");
+                final String aaiResponse = EntityUtils.toString(responseEntity);
+                return Optional.of(aaiResponse);
+            } else {
+                String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
+                logger.error("HTTP response not successful : {}", aaiResponse);
+                return Optional.of("" + responseCode);
+            }
+        };
+    }
+
+    private HttpRequestBase createHttpRequest(URI extendedURI) {
+
+        if (isExtendedURINotNull(extendedURI)) {
+            return new HttpGet(extendedURI);
+        } else {
+            return null;
+        }
+    }
+
+    private Boolean isExtendedURINotNull(URI extendedURI) {
+        return extendedURI != null;
+    }
+
+    private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
+
+        final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
+        HttpRequestBase request = createHttpRequest(extendedURI);
+        requestDetails.headers().forEach(request::addHeader);
+        return Optional.of(request);
+    }
+}
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.dcaegen2.services.service;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
 import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPatch;
-import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpRequestBase;
 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.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 import org.onap.dcaegen2.services.utils.HttpRequestDetails;
 import org.onap.dcaegen2.services.utils.HttpUtils;
-import org.onap.dcaegen2.services.utils.RequestVerbs;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.lang.NonNull;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Iterator;
-import java.util.Map;
 import java.util.Optional;
 
-public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient {
-
-    Logger logger = LoggerFactory.getLogger(AAIExtendedHttpClientImpl.class);
+public class AAIProducerClient implements AAIExtendedHttpClient {
+    Logger logger = LoggerFactory.getLogger(AAIProducerClient.class);
 
     private final CloseableHttpClient closeableHttpClient;
     private final String aaiHost;
@@ -56,8 +50,8 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient {
     private final Integer aaiHostPortNumber;
 
 
-    public AAIExtendedHttpClientImpl (AAIHttpClientConfiguration aaiHttpClientConfiguration) {
-        final AAIHttpClient aaiHttpClient = new AAIHttpClientImpl(aaiHttpClientConfiguration);
+    public AAIProducerClient(AAIClientConfiguration aaiHttpClientConfiguration) {
+        final AAIClient aaiHttpClient = new AAIClientImpl(aaiHttpClientConfiguration);
         closeableHttpClient = aaiHttpClient.getAAIHttpClient();
         aaiHost = aaiHttpClientConfiguration.aaiHost();
         aaiProtocol = aaiHttpClientConfiguration.aaiProtocol();
@@ -79,18 +73,15 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient {
         return extendedDetails;
     }
 
-    private URI createAAIExtendedURI(final String path, Map<String, String> queryParams) {
+    private URI createAAIExtendedURI(final String path, final String pnfName) {
 
         URI extendedURI = null;
 
-        final URIBuilder uriBuilder = new URIBuilder().setScheme(this.aaiProtocol).setHost(this.aaiHost)
-                .setPort(this.aaiHostPortNumber)
-                .setPath(path);
-        final String customQuery = createCustomQuery(queryParams);
-
-        if (StringUtils.isNoneBlank(customQuery)) {
-            uriBuilder.setCustomQuery(customQuery);
-        }
+        final URIBuilder uriBuilder = new URIBuilder()
+                .setScheme(aaiProtocol)
+                .setHost(aaiHost)
+                .setPort(aaiHostPortNumber)
+                .setPath(path + "/" + pnfName);
 
         try {
             extendedURI = uriBuilder.build();
@@ -102,45 +93,25 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient {
         return extendedURI;
     }
 
-    private String createCustomQuery(@NonNull final Map<String, String> queryParams) {
-        final StringBuilder queryStringBuilder = new StringBuilder("");
-        final Iterator<Map.Entry<String, String>> queryParamIterator = queryParams.entrySet().iterator();
-
-        while (queryParamIterator.hasNext()) {
-            final Map.Entry<String, String> queryParamsEntry = queryParamIterator.next();
-            queryStringBuilder.append(queryParamsEntry.getKey()).append("=").append(queryParamsEntry.getValue());
-            if (queryParamIterator.hasNext()) {
-                queryStringBuilder.append("&");
-            }
-        }
-
-        return queryStringBuilder.toString();
-    }
-
     private ResponseHandler<Optional<String>> aaiResponseHandler() {
-        return httpResponse ->  {
+        return (HttpResponse httpResponse) ->  {
             final int responseCode = httpResponse.getStatusLine().getStatusCode();
+            logger.info("Status code of operation: {}", responseCode);
             final HttpEntity responseEntity = httpResponse.getEntity();
 
-            if (HttpUtils.isSuccessfulResponseCode(responseCode) && responseEntity != null) {
+            if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
                 logger.info("HTTP response successful.");
-                final String aaiResponse = EntityUtils.toString(responseEntity);
-                return Optional.of(aaiResponse);
+                return Optional.of("" + responseCode);
             } else {
                 String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
                 logger.error("HTTP response not successful : {}", aaiResponse);
-                return Optional.empty();
+                return Optional.of("" + responseCode);
             }
         };
     }
 
     private HttpRequestBase createHttpRequest(URI extendedURI, HttpRequestDetails httpRequestDetails) {
-        if (isExtendedURINotNull(extendedURI) && (httpRequestDetails.requestVerb().equals(RequestVerbs.GET))) {
-            return new HttpGet(extendedURI);
-        } else if (isExtendedURINotNull(extendedURI) && (httpRequestDetails.requestVerb().equals(RequestVerbs.PUT))) {
-            return new HttpPut(extendedURI);
-        } else if (isExtendedURINotNull(extendedURI) &&
-                isPatchRequestValid(httpRequestDetails.requestVerb(),httpRequestDetails.jsonBody())) {
+        if (isExtendedURINotNull(extendedURI) && httpRequestDetails.jsonBody().isPresent()) {
             return createHttpPatch(extendedURI, httpRequestDetails.jsonBody());
         } else {
             return null;
@@ -174,13 +145,9 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient {
         return stringEntity;
     }
 
-    private Boolean isPatchRequestValid(RequestVerbs requestVerb, Optional<String> jsonBody) {
-        return requestVerb == RequestVerbs.PATCH && jsonBody.isPresent();
-    }
-
     private Optional<HttpRequestBase> createRequest(HttpRequestDetails requestDetails) {
 
-        final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.queryParameters());
+        final URI extendedURI = createAAIExtendedURI(requestDetails.aaiAPIPath(), requestDetails.pnfName());
         HttpRequestBase request = createHttpRequest(extendedURI, requestDetails);
         requestDetails.headers().forEach(request::addHeader);
         return Optional.of(request);
index 574cb22..37e6b86 100644 (file)
@@ -39,11 +39,8 @@ public abstract class HttpRequestDetails implements Serializable {
     public abstract Optional<String> jsonBody();
 
     @Value.Parameter
-    public abstract Map<String,String> queryParameters();
+    public abstract String pnfName();
 
     @Value.Parameter
     public abstract Map<String,String> headers();
-
-    @Value.Parameter
-    public abstract RequestVerbs requestVerb();
 }
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java
new file mode 100644 (file)
index 0000000..b95cc8d
--- /dev/null
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.service;
+
+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.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+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;
+
+public class AAIConsumerClientTest {
+
+    private static AAIConsumerClient testedObject;
+    private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+    private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
+    private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
+    private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }";
+
+    @BeforeAll
+    public static void setup() throws NoSuchFieldException, IllegalAccessException {
+
+        Map<String, String> aaiHeaders = new HashMap<>();
+        aaiHeaders.put("X-FromAppId", "prh");
+        aaiHeaders.put("X-TransactionId", "9999");
+        aaiHeaders.put("Accept", "application/json");
+        aaiHeaders.put("authentication", "Basic QUFJOkFBSQ==");
+        aaiHeaders.put("Real-Time", "true");
+        aaiHeaders.put("Content-Type", "application/json");
+
+        when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
+        when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
+        when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
+        when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
+        when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
+
+        when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
+        when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
+        when(httpRequestDetailsMock.pnfName()).thenReturn("pnf-nokia-45fsfcx");
+        when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE));
+
+        testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
+        setField();
+    }
+
+
+    @Test
+    public void getExtendedDetails_returnsSuccess() throws IOException {
+
+        when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
+                thenReturn(Optional.of(JSON_MESSAGE));
+        Optional<String>  actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+        Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
+    }
+
+
+    private static void setField() throws NoSuchFieldException, IllegalAccessException {
+        Field field = testedObject.getClass().getDeclaredField("closeableHttpClient");
+        field.setAccessible(true);
+        field.set(testedObject, closeableHttpClientMock);
+    }
+}
index fd13f1e..cfe1a7f 100644 (file)
@@ -21,7 +21,7 @@ package org.onap.dcaegen2.services.service;
 
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
@@ -30,13 +30,13 @@ import static org.mockito.Mockito.when;
 
 public class AAIHttpClientImplTest {
 
-    private static AAIHttpClientImpl testedObject;
-    private static AAIHttpClientConfiguration aaiHttpClientConfigurationMock;
+    private static AAIClientImpl testedObject;
+    private static AAIClientConfiguration aaiHttpClientConfigurationMock;
 
 
     @BeforeAll
     public static void setup() {
-        aaiHttpClientConfigurationMock = mock(AAIHttpClientConfiguration.class);
+        aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
         when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
         when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
         when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
@@ -44,7 +44,7 @@ public class AAIHttpClientImplTest {
         when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PNF");
         when(aaiHttpClientConfigurationMock.aaiIgnoreSSLCertificateErrors()).thenReturn(true);
 
-        testedObject  = new AAIHttpClientImpl(aaiHttpClientConfigurationMock);
+        testedObject  = new AAIClientImpl(aaiHttpClientConfigurationMock);
     }
 
     @Test
@@ -1,4 +1,4 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  * PNF-REGISTRATION-HANDLER
  * ================================================================================
 
 package org.onap.dcaegen2.services.service;
 
-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.HttpPatch;
+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.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPatch;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.immutables.value.internal.$processor$.meta.$GsonMirrors;
-import org.junit.Ignore;
-import org.junit.jupiter.api.*;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
-import org.onap.dcaegen2.services.utils.RequestVerbs;
 
-public class AAIExtendedHttpClientImplTest {
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AAIProducerClientTest {
 
-    private static AAIExtendedHttpClientImpl testedObject;
-    private static AAIHttpClientConfiguration aaiHttpClientConfigurationMock = mock(AAIHttpClientConfiguration.class);
+    private static AAIProducerClient testedObject;
+    private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
     private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
     private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class);
-    private static Optional<String> expectedResult = Optional.empty();
-    private static final String JSON_MESSAGE = "{ \"ipaddress-v4-oam\": \"11.22.33.44\" }";
-    private static final String PNF_ID = "NOKQTFCOC540002E";
+    private static final String JsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}";
+    private static final String SUCCESS = "200";
+    private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
 
     @BeforeAll
     public static void init() throws NoSuchFieldException, IllegalAccessException {
 
-        Map<String, String> queryParams = new HashMap<>();
-        queryParams.put("pnf-id", PNF_ID);
-
         Map<String, String> aaiHeaders = new HashMap<>();
         aaiHeaders.put("X-FromAppId", "prh");
         aaiHeaders.put("X-TransactionId", "vv-temp");
         aaiHeaders.put("Accept", "application/json");
         aaiHeaders.put("Real-Time", "true");
-        aaiHeaders.put("Content-Type", "application/json");
+        aaiHeaders.put("Content-Type", "application/merge-patch+json");
 
-        when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
+        when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net");
         when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
         when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
         when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
         when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
 
         when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf");
+
         when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders);
-        when(httpRequestDetailsMock.queryParameters()).thenReturn(queryParams);
-        when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE));
+        when(httpRequestDetailsMock.pnfName()).thenReturn(PNF_NAME);
+        when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JsonBody));
 
-        testedObject = new AAIExtendedHttpClientImpl(aaiHttpClientConfigurationMock);
+        testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
         setField();
     }
 
-    @AfterAll
-    public static void teardown() {
-        testedObject = null;
-        aaiHttpClientConfigurationMock = null;
-        closeableHttpClientMock = null;
-        httpRequestDetailsMock = null;
-        expectedResult = null;
-    }
-
     @Test
     public void getHttpResponsePatch_success() throws IOException {
-        when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PATCH);
-
-        expectedResult = Optional.of(JSON_MESSAGE);
 
         when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
-                .thenReturn(expectedResult);
+                .thenReturn(Optional.of(SUCCESS));
         Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
 
-        Assertions.assertEquals(expectedResult.get(), actualResult.get());
-    }
-
-    @Test
-    public void getHttpResponsePut_success() throws IOException {
-        when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PUT);
-
-        expectedResult = Optional.of("getExtendedDetailsOK");
-
-        when(closeableHttpClientMock.execute(any(HttpPut.class), any(ResponseHandler.class))).
-                thenReturn(expectedResult);
-        Optional<String>  actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
-
-        Assertions.assertEquals(expectedResult.get(), actualResult.get());
-    }
-
-    @Test
-    public void getExtendedDetails_returnsNull() throws IOException {
-        when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.GET);
-        when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
-                thenReturn(Optional.empty());
-        Optional<String>  actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
-        Assertions.assertEquals(Optional.empty(),actualResult);
-    }
-
-    @Test
-    public void getHttpResponsePut_failure() {
-        when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PUT);
-
+        Assertions.assertEquals(SUCCESS, actualResult.get());
     }
 
     private static void setField() throws NoSuchFieldException, IllegalAccessException {
index 76c2969..29a0092 100644 (file)
@@ -23,12 +23,12 @@ package org.onap.dcaegen2.services.service.config;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.config.ImmutableAAIClientConfiguration;
 
 public class AAIHttpClientConfigurationTest {
 
-    private static AAIHttpClientConfiguration client;
+    private static AAIClientConfiguration client;
     private static final String AAI_HOST = "/aai/v11/network/pnfs/pnf/NOKQTFCOC540002E";
     private static final Integer PORT = 1234;
     private static final String PROTOCOL = "https";
@@ -36,7 +36,7 @@ public class AAIHttpClientConfigurationTest {
 
     @BeforeAll
     public static void init() {
-        client = new ImmutableAAIHttpClientConfiguration.Builder()
+        client = new ImmutableAAIClientConfiguration.Builder()
             .aaiHost(AAI_HOST)
             .aaiHostPortNumber(PORT)
             .aaiProtocol(PROTOCOL)
index 563e692..0deb8ad 100644 (file)
@@ -36,19 +36,16 @@ public class HttpRequestDetailsTest {
     private static HttpRequestDetails testObject;
 
     private static final String AAI_PATH = "aaiPathTest";
-    private static final RequestVerbs HTTP_VERB = RequestVerbs.PATCH;
-    private static final String QUERY_KEY1 = "queryKey1";
-    private static final String QUERY_VALUE1 = "queryValue1";
     private static final String HEADERS_KEY1 = "headersKey1";
     private static final String HEADERS_VALUE1 = "headersValue1";
     private static final String JSON_MESSAGE = "{\"dare_to\": \"dream_big\"}";
+    private static final String PNF_NAME = "pnf-nokia-5454885485";
 
     @BeforeAll
     public static void init() {
         testObject = ImmutableHttpRequestDetails.builder()
                 .aaiAPIPath(AAI_PATH)
-                .requestVerb(HTTP_VERB)
-                .putQueryParameters(QUERY_KEY1,QUERY_VALUE1)
+                .pnfName(PNF_NAME)
                 .putHeaders(HEADERS_KEY1,HEADERS_VALUE1)
                 .jsonBody(JSON_MESSAGE)
                 .build();
@@ -58,8 +55,7 @@ public class HttpRequestDetailsTest {
     public void testGetters_success() {
         Assertions.assertEquals(AAI_PATH, testObject.aaiAPIPath());
         Assertions.assertEquals(HEADERS_VALUE1, testObject.headers().get(HEADERS_KEY1));
-        Assertions.assertEquals(QUERY_VALUE1, testObject.queryParameters().get(QUERY_KEY1));
-        Assertions.assertEquals(RequestVerbs.PATCH, testObject.requestVerb());
+        Assertions.assertEquals(PNF_NAME, testObject.pnfName());
         Assertions.assertEquals(Optional.of(JSON_MESSAGE), testObject.jsonBody());
     }
 }
index e804c3e..cb85db1 100644 (file)
       <artifactId>prh-dmaap-client</artifactId>
       <version>${project.parent.version}</version>
     </dependency>
+      <dependency>
+          <groupId>org.onap.dcaegen2.services.prh</groupId>
+          <artifactId>prh-aai-client</artifactId>
+          <version>1.0.0-SNAPSHOT</version>
+      </dependency>
 
   </dependencies>
   <dependencyManagement>
index 76633d2..15db50e 100644 (file)
  */
 package org.onap.dcaegen2.services.prh.configuration;
 
-import java.util.Optional;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
-import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.config.*;
 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
  */
@@ -38,26 +34,26 @@ import org.springframework.stereotype.Component;
 @Configuration
 public class AppConfig extends PrhAppConfig {
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapHostName:}")
-    public String consumerDmmapHostName;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapHostName:}")
+    public String consumerDmaapHostName;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapPortNumber:}")
-    public Integer consumerDmmapPortNumber;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapPortNumber:}")
+    public Integer consumerDmaapPortNumber;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapTopicName:}")
-    public String consumerDmmapTopicName;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapTopicName:}")
+    public String consumerDmaapTopicName;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapProtocol:}")
-    public String consumerDmmapProtocol;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapProtocol:}")
+    public String consumerDmaapProtocol;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserName:}")
-    public String consumerDmmapUserName;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserName:}")
+    public String consumerDmaapUserName;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserPassword:}")
-    public String consumerDmmapUserPassword;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserPassword:}")
+    public String consumerDmaapUserPassword;
 
-    @Value("${dmaap.dmaapConsumerConfiguration.dmmapContentType:}")
-    public String consumerDmmapContentType;
+    @Value("${dmaap.dmaapConsumerConfiguration.dmaapContentType:}")
+    public String consumerDmaapContentType;
 
     @Value("${dmaap.dmaapConsumerConfiguration.consumerId:}")
     public String consumerId;
@@ -71,26 +67,26 @@ public class AppConfig extends PrhAppConfig {
     @Value("${dmaap.dmaapConsumerConfiguration.message-limit:}")
     public Integer consumerMessageLimit;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapHostName:}")
-    public String producerDmmapHostName;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapHostName:}")
+    public String producerDmaapHostName;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapPortNumber:}")
-    public Integer producerDmmapPortNumber;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapPortNumber:}")
+    public Integer producerDmaapPortNumber;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapTopicName:}")
-    public String producerDmmapTopicName;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapTopicName:}")
+    public String producerDmaapTopicName;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapProtocol:}")
-    public String producerDmmapProtocol;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapProtocol:}")
+    public String producerDmaapProtocol;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapUserName:}")
-    public String producerDmmapUserName;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapUserName:}")
+    public String producerDmaapUserName;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapUserPassword:}")
-    public String producerDmmapUserPassword;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapUserPassword:}")
+    public String producerDmaapUserPassword;
 
-    @Value("${dmaap.dmaapProducerConfiguration.dmmapContentType:}")
-    public String producerDmmapContentType;
+    @Value("${dmaap.dmaapProducerConfiguration.dmaapContentType:}")
+    public String producerDmaapContentType;
 
     @Value("${aai.aaiHttpClientConfiguration.aaiHost:}")
     public String aaiHost;
@@ -113,63 +109,63 @@ public class AppConfig extends PrhAppConfig {
     @Override
     public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
         return new ImmutableDmaapConsumerConfiguration.Builder()
-            .dmaapUserPassword(
-                Optional.ofNullable(consumerDmmapUserPassword).orElse(dmaapConsumerConfiguration.dmaapUserPassword()))
-            .dmaapUserName(
-                Optional.ofNullable(consumerDmmapUserName).orElse(dmaapConsumerConfiguration.dmaapUserName()))
-            .dmaapHostName(
-                Optional.ofNullable(consumerDmmapHostName).orElse(dmaapConsumerConfiguration.dmaapHostName()))
-            .dmaapPortNumber(
-                Optional.ofNullable(consumerDmmapPortNumber).orElse(dmaapConsumerConfiguration.dmaapPortNumber()))
-            .dmaapProtocol(
-                Optional.ofNullable(consumerDmmapProtocol).orElse(dmaapConsumerConfiguration.dmaapProtocol()))
-            .dmaapContentType(
-                Optional.ofNullable(consumerDmmapContentType).orElse(dmaapConsumerConfiguration.dmaapContentType()))
-            .dmaapTopicName(
-                Optional.ofNullable(consumerDmmapTopicName).orElse(dmaapConsumerConfiguration.dmaapTopicName()))
-            .messageLimit(
-                Optional.ofNullable(consumerMessageLimit).orElse(dmaapConsumerConfiguration.messageLimit()))
-            .timeoutMS(Optional.ofNullable(consumerTimeoutMS).orElse(dmaapConsumerConfiguration.timeoutMS()))
-            .consumerGroup(Optional.ofNullable(consumerGroup).orElse(dmaapConsumerConfiguration.consumerGroup()))
-            .consumerId(Optional.ofNullable(consumerId).orElse(dmaapConsumerConfiguration.consumerId()))
-            .build();
+                .dmaapUserPassword(
+                        Optional.ofNullable(consumerDmaapUserPassword).orElse(dmaapConsumerConfiguration.dmaapUserPassword()))
+                .dmaapUserName(
+                        Optional.ofNullable(consumerDmaapUserName).orElse(dmaapConsumerConfiguration.dmaapUserName()))
+                .dmaapHostName(
+                        Optional.ofNullable(consumerDmaapHostName).orElse(dmaapConsumerConfiguration.dmaapHostName()))
+                .dmaapPortNumber(
+                        Optional.ofNullable(consumerDmaapPortNumber).orElse(dmaapConsumerConfiguration.dmaapPortNumber()))
+                .dmaapProtocol(
+                        Optional.ofNullable(consumerDmaapProtocol).orElse(dmaapConsumerConfiguration.dmaapProtocol()))
+                .dmaapContentType(
+                        Optional.ofNullable(consumerDmaapContentType).orElse(dmaapConsumerConfiguration.dmaapContentType()))
+                .dmaapTopicName(
+                        Optional.ofNullable(consumerDmaapTopicName).orElse(dmaapConsumerConfiguration.dmaapTopicName()))
+                .messageLimit(
+                        Optional.ofNullable(consumerMessageLimit).orElse(dmaapConsumerConfiguration.messageLimit()))
+                .timeoutMS(Optional.ofNullable(consumerTimeoutMS).orElse(dmaapConsumerConfiguration.timeoutMS()))
+                .consumerGroup(Optional.ofNullable(consumerGroup).orElse(dmaapConsumerConfiguration.consumerGroup()))
+                .consumerId(Optional.ofNullable(consumerId).orElse(dmaapConsumerConfiguration.consumerId()))
+                .build();
     }
 
     @Override
-    public AAIHttpClientConfiguration getAAIHttpClientConfiguration() {
-        return new ImmutableAAIHttpClientConfiguration.Builder()
-            .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiHttpClientConfiguration.aaiHost()))
-            .aaiHostPortNumber(
-                Optional.ofNullable(aaiHostPortNumber).orElse(aaiHttpClientConfiguration.aaiHostPortNumber()))
-            .aaiIgnoreSSLCertificateErrors(
-                Optional.ofNullable(aaiIgnoreSSLCertificateErrors)
-                    .orElse(aaiHttpClientConfiguration.aaiIgnoreSSLCertificateErrors()))
-            .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiHttpClientConfiguration.aaiProtocol()))
-            .aaiUserName(
-                Optional.ofNullable(aaiUserName).orElse(aaiHttpClientConfiguration.aaiUserName()))
-            .aaiUserPassword(Optional.ofNullable(
-                aaiUserPassword).orElse(aaiHttpClientConfiguration.aaiUserPassword()))
-            .build();
+    public AAIClientConfiguration getAAIClientConfiguration() {
+        return new ImmutableAAIClientConfiguration.Builder()
+                .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiClientConfiguration.aaiHost()))
+                .aaiHostPortNumber(
+                        Optional.ofNullable(aaiHostPortNumber).orElse(aaiClientConfiguration.aaiHostPortNumber()))
+                .aaiIgnoreSSLCertificateErrors(
+                        Optional.ofNullable(aaiIgnoreSSLCertificateErrors)
+                                .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors()))
+                .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiClientConfiguration.aaiProtocol()))
+                .aaiUserName(
+                        Optional.ofNullable(aaiUserName).orElse(aaiClientConfiguration.aaiUserName()))
+                .aaiUserPassword(Optional.ofNullable(
+                        aaiUserPassword).orElse(aaiClientConfiguration.aaiUserPassword()))
+                .build();
     }
 
     @Override
     public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
         return new ImmutableDmaapPublisherConfiguration.Builder()
-            .dmaapContentType(
-                Optional.ofNullable(producerDmmapContentType).orElse(dmaapPublisherConfiguration.dmaapContentType()))
-            .dmaapHostName(
-                Optional.ofNullable(producerDmmapHostName).orElse(dmaapPublisherConfiguration.dmaapHostName()))
-            .dmaapPortNumber(
-                Optional.ofNullable(producerDmmapPortNumber).orElse(dmaapPublisherConfiguration.dmaapPortNumber()))
-            .dmaapProtocol(
-                Optional.ofNullable(producerDmmapProtocol).orElse(dmaapPublisherConfiguration.dmaapProtocol()))
-            .dmaapTopicName(
-                Optional.ofNullable(producerDmmapTopicName).orElse(dmaapPublisherConfiguration.dmaapTopicName()))
-            .dmaapUserName(
-                Optional.ofNullable(producerDmmapUserName).orElse(dmaapPublisherConfiguration.dmaapUserName()))
-            .dmaapUserPassword(
-                Optional.ofNullable(producerDmmapUserPassword).orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
-            .build();
+                .dmaapContentType(
+                        Optional.ofNullable(producerDmaapContentType).orElse(dmaapPublisherConfiguration.dmaapContentType()))
+                .dmaapHostName(
+                        Optional.ofNullable(producerDmaapHostName).orElse(dmaapPublisherConfiguration.dmaapHostName()))
+                .dmaapPortNumber(
+                        Optional.ofNullable(producerDmaapPortNumber).orElse(dmaapPublisherConfiguration.dmaapPortNumber()))
+                .dmaapProtocol(
+                        Optional.ofNullable(producerDmaapProtocol).orElse(dmaapPublisherConfiguration.dmaapProtocol()))
+                .dmaapTopicName(
+                        Optional.ofNullable(producerDmaapTopicName).orElse(dmaapPublisherConfiguration.dmaapTopicName()))
+                .dmaapUserName(
+                        Optional.ofNullable(producerDmaapUserName).orElse(dmaapPublisherConfiguration.dmaapUserName()))
+                .dmaapUserPassword(
+                        Optional.ofNullable(producerDmaapUserPassword).orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
+                .build();
     }
 
 }
index 8dd2bf3..605a1bd 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.onap.dcaegen2.services.prh.configuration;
 
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
 import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
 
@@ -30,7 +30,7 @@ public interface Config {
 
     DmaapConsumerConfiguration getDmaapConsumerConfiguration();
 
-    AAIHttpClientConfiguration getAAIHttpClientConfiguration();
+    AAIClientConfiguration getAAIClientConfiguration();
 
     DmaapPublisherConfiguration getDmaapPublisherConfiguration();
 
index 8720cf4..0473c1a 100644 (file)
  */
 package org.onap.dcaegen2.services.prh.configuration;
 
-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.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ServiceLoader;
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import com.google.gson.*;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
 import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
 import org.slf4j.Logger;
@@ -45,6 +29,13 @@ 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.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ServiceLoader;
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
  */
@@ -63,7 +54,7 @@ public abstract class PrhAppConfig implements Config {
     private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class);
     private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
 
-    AAIHttpClientConfiguration aaiHttpClientConfiguration;
+    AAIClientConfiguration aaiClientConfiguration;
 
     DmaapConsumerConfiguration dmaapConsumerConfiguration;
 
@@ -79,8 +70,8 @@ public abstract class PrhAppConfig implements Config {
     }
 
     @Override
-    public AAIHttpClientConfiguration getAAIHttpClientConfiguration() {
-        return aaiHttpClientConfiguration;
+    public AAIClientConfiguration getAAIClientConfiguration() {
+        return aaiClientConfiguration;
     }
 
     @Override
@@ -99,41 +90,41 @@ public abstract class PrhAppConfig implements Config {
             JsonElement rootElement = parser.parse(new InputStreamReader(inputStream));
             if (rootElement.isJsonObject()) {
                 jsonObject = rootElement.getAsJsonObject();
-                aaiHttpClientConfiguration = deserializeType(gsonBuilder,
-                    jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
-                    AAIHttpClientConfiguration.class);
+                aaiClientConfiguration = deserializeType(gsonBuilder,
+                        jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
+                        AAIClientConfiguration.class);
 
                 dmaapConsumerConfiguration = deserializeType(gsonBuilder,
-                    jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
-                    DmaapConsumerConfiguration.class);
+                        jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+                        DmaapConsumerConfiguration.class);
 
                 dmaapPublisherConfiguration = deserializeType(gsonBuilder,
-                    jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
-                    DmaapPublisherConfiguration.class);
+                        jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+                        DmaapPublisherConfiguration.class);
             }
         } catch (FileNotFoundException e) {
             logger
-                .error(
-                    "Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}",
-                    dateTimeFormatter.format(
-                        LocalDateTime.now()), e);
+                    .error(
+                            "Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}",
+                            dateTimeFormatter.format(
+                                    LocalDateTime.now()), e);
         } catch (IOException e) {
             logger
-                .error(
-                    "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}",
-                    dateTimeFormatter.format(
-                        LocalDateTime.now()), e);
+                    .error(
+                            "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}",
+                            dateTimeFormatter.format(
+                                    LocalDateTime.now()), e);
         } catch (JsonSyntaxException e) {
             logger
-                .error(
-                    "Configuration PrhAppConfig initFileStreamReader()::JsonSyntaxException :: Execution Time - {}:{}",
-                    dateTimeFormatter.format(
-                        LocalDateTime.now()), e);
+                    .error(
+                            "Configuration PrhAppConfig initFileStreamReader()::JsonSyntaxException :: Execution Time - {}:{}",
+                            dateTimeFormatter.format(
+                                    LocalDateTime.now()), e);
         }
     }
 
     private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
-        @NotNull Class<T> type) {
+                                  @NotNull Class<T> type) {
         return gsonBuilder.create().fromJson(jsonObject, type);
     }
 
index 95b360e..b91b56c 100644 (file)
@@ -21,6 +21,7 @@ package org.onap.dcaegen2.services.prh.controllers;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+
 import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 6f08dd8..733b7df 100644 (file)
@@ -24,6 +24,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ScheduledFuture;
+
 import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
 import org.slf4j.Logger;
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
new file mode 100644 (file)
index 0000000..5a3afd8
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============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.tasks;
+
+import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+
+public abstract class AAIConsumerTask<T> extends Task {
+
+    protected abstract void consume() throws AAINotFoundException;
+
+    protected abstract T resolveConfiguration();
+}
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
new file mode 100644 (file)
index 0000000..64ccad5
--- /dev/null
@@ -0,0 +1,89 @@
+/*-
+ * ============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.tasks;
+
+import org.onap.dcaegen2.services.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.service.AAIProducerClient;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Optional;
+
+@Component
+public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration> {
+
+    private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
+    private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+
+    private final Config prhAppConfig;
+    private final HttpRequestDetails requestDetails;
+    private AAIProducerClient producerClient;
+    public Optional<String> response;
+
+    @Autowired
+    public AAIConsumerTaskImpl(AppConfig prhAppConfig, HttpRequestDetails requestDetails) {
+        this.prhAppConfig = prhAppConfig;
+        this.requestDetails = requestDetails;
+    }
+
+    @Override
+    protected void consume() throws AAINotFoundException {
+        logger.debug("Start task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
+                LocalDateTime.now()));
+
+
+        producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration());
+
+        response = producerClient.getHttpResponse(requestDetails);
+
+        logger.debug("End task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
+                LocalDateTime.now()));
+
+    }
+
+    @Override
+    public ResponseEntity execute(Object object) throws AAINotFoundException {
+        logger.debug("Start task AAIProducerTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format(
+                LocalDateTime.now()));
+        consume();
+        logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format(
+                LocalDateTime.now()));
+        return null;
+    }
+
+    @Override
+    void initConfigs() {
+    }
+
+    @Override
+    protected AAIClientConfiguration resolveConfiguration() {
+        return prhAppConfig.getAAIClientConfiguration();
+    }
+}
@@ -24,7 +24,7 @@ import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
  */
-public abstract class AAIPublisherTask<T> extends Task {
+public abstract class AAIProducerTask<T> extends Task {
 
     protected abstract void publish() throws AAINotFoundException;
 
  */
 package org.onap.dcaegen2.services.prh.tasks;
 
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.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.service.AAIProducerClient;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Optional;
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
  */
 @Component
-public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfiguration> {
+public class AAIProducerTaskImpl extends AAIProducerTask<AAIClientConfiguration> {
 
     private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
     private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
 
     private final Config prhAppConfig;
+    private AAIProducerClient producerClient;
+    private HttpRequestDetails requestDetails;
+    private String jsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}";
+    private String pnfName = "example-pnf-name-val-40510"; // pnf name received from dmaap required for URI
+    public Optional<String> response;
 
     @Autowired
-    public AAIPublisherTaskImpl(AppConfig prhAppConfig) {
+    public AAIProducerTaskImpl(AppConfig prhAppConfig, HttpRequestDetails requestDetails) {
         this.prhAppConfig = prhAppConfig;
-
+        this.requestDetails = requestDetails;
     }
 
     @Override
     protected void publish() throws AAINotFoundException {
-        logger.debug("Start task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
+        logger.debug("Start task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
             LocalDateTime.now()));
-        prhAppConfig.getAAIHttpClientConfiguration();
-        logger.debug("End task DmaapConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
+
+        producerClient = new AAIProducerClient(prhAppConfig.getAAIClientConfiguration());
+
+        response = producerClient.getHttpResponse(requestDetails);
+
+        logger.debug("End task AAIConsumerTask::publish() :: Execution Time - {}", dateTimeFormatter.format(
             LocalDateTime.now()));
 
     }
 
     @Override
     public ResponseEntity execute(Object object) throws AAINotFoundException {
-        logger.debug("Start task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format(
+        logger.debug("Start task AAIProducerTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format(
             LocalDateTime.now()));
         publish();
         logger.debug("End task AAIPublisherTaskImpl::execute() :: Execution Time - {}", dateTimeFormatter.format(
@@ -73,8 +86,8 @@ public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfigur
     }
 
     @Override
-    protected AAIHttpClientConfiguration resolveConfiguration() {
-        return prhAppConfig.getAAIHttpClientConfiguration();
+    protected AAIClientConfiguration resolveConfiguration() {
+        return prhAppConfig.getAAIClientConfiguration();
     }
 
 }
index 0db49f7..eb66361 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.onap.dcaegen2.services.prh.tasks;
 
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
 import org.onap.dcaegen2.services.prh.configuration.AppConfig;
 import org.onap.dcaegen2.services.prh.configuration.Config;
@@ -30,6 +28,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
  */
index 072f9c7..ff5f589 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.onap.dcaegen2.services.prh.tasks;
 
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
 import org.onap.dcaegen2.services.prh.configuration.AppConfig;
 import org.onap.dcaegen2.services.prh.configuration.Config;
@@ -30,6 +28,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
  */
index c051afb..2922da1 100644 (file)
@@ -39,14 +39,16 @@ public class ScheduledTasks {
 
     private final Task dmaapConsumerTask;
     private final Task dmaapProducerTask;
-    private final Task aaiPublisherTask;
+    private final Task aaiProducerTask;
+    private final Task aaiConsumerTask;
 
     @Autowired
     public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask,
-        AAIPublisherTask aaiPublisherTask) {
+        AAIProducerTask aaiPublisherTask, AAIConsumerTask aaiConsumerTask) {
         this.dmaapConsumerTask = dmaapConsumerTask;
         this.dmaapProducerTask = dmaapPublisherTask;
-        this.aaiPublisherTask = aaiPublisherTask;
+        this.aaiProducerTask = aaiPublisherTask;
+        this.aaiConsumerTask = aaiConsumerTask;
     }
 
     public void scheduleMainPrhEventTask() {
@@ -65,8 +67,10 @@ public class ScheduledTasks {
     }
 
     private void setTaskExecutionFlow() {
-        dmaapConsumerTask.setNext(aaiPublisherTask);
-        aaiPublisherTask.setNext(dmaapProducerTask);
+        dmaapConsumerTask.setNext(aaiProducerTask);
+        aaiProducerTask.setNext(dmaapProducerTask);
+        aaiConsumerTask.setNext(aaiConsumerTask);
+        dmaapProducerTask.setNext(dmaapConsumerTask);
     }
 
 }
index faecec4..8094c99 100644 (file)
@@ -23,19 +23,15 @@ import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
 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.IT.junit5.mockito.MockitoExtension;
 import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
-import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
@@ -77,6 +73,11 @@ class ServiceMockProvider {
     public PrhAppConfig getPrhAppConfig() {
         return mock(PrhAppConfig.class);
     }
+
+    @Bean
+    public HttpRequestDetails getRequestDetails() {
+        return mock(HttpRequestDetails.class);
+    }
 }
 
 
index 764bafe..e7d5541 100644 (file)
@@ -88,13 +88,13 @@ class PrhAppConfigTest {
         prhAppConfig.initFileStreamReader();
         appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration();
         appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration();
-        appConfig.aaiHttpClientConfiguration = prhAppConfig.getAAIHttpClientConfiguration();
+        appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration();
         //
         // Then
         //
         verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
-        Assertions.assertNotNull(prhAppConfig.getAAIHttpClientConfiguration());
+        Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration());
         Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
         Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration());
         Assertions
@@ -102,7 +102,7 @@ class PrhAppConfigTest {
         Assertions
             .assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration());
         Assertions
-            .assertEquals(appConfig.getAAIHttpClientConfiguration(), prhAppConfig.getAAIHttpClientConfiguration());
+            .assertEquals(appConfig.getAAIClientConfiguration(), prhAppConfig.getAAIClientConfiguration());
 
     }
 
@@ -122,7 +122,7 @@ class PrhAppConfigTest {
         //
         verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
-        Assertions.assertNull(prhAppConfig.getAAIHttpClientConfiguration());
+        Assertions.assertNull(prhAppConfig.getAAIClientConfiguration());
         Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
         Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
 
@@ -147,7 +147,7 @@ class PrhAppConfigTest {
         //
         verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
-        Assertions.assertNotNull(prhAppConfig.getAAIHttpClientConfiguration());
+        Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration());
         Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
         Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
 
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
new file mode 100644 (file)
index 0000000..57c3ce2
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PROJECT
+ * ================================================================================
+ * 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.tasks;
+
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
+
+import org.onap.dcaegen2.services.prh.configuration.AppConfig;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
+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 {
+
+    @Bean
+    @Primary
+    public AAIConsumerTask registerSimpleAAIPublisherTask() {
+        AppConfig appConfig = mock(AppConfig.class);
+        HttpRequestDetails requestDetails = mock(HttpRequestDetails.class);
+        when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class));
+        return spy(new AAIConsumerTaskImpl(appConfig, requestDetails));
+    }
+}
\ No newline at end of file
index c27c881..8da7f85 100644 (file)
  */
 package org.onap.dcaegen2.services.prh.tasks;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
+import org.onap.dcaegen2.services.config.AAIClientConfiguration;
 import org.onap.dcaegen2.services.prh.configuration.AppConfig;
+import org.onap.dcaegen2.services.utils.HttpRequestDetails;
 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
  */
@@ -37,9 +36,10 @@ public class AAIPublisherTaskSpy {
 
     @Bean
     @Primary
-    public AAIPublisherTask registerSimpleAAIPublisherTask() {
+    public AAIProducerTask registerSimpleAAIPublisherTask() {
         AppConfig appConfig = mock(AppConfig.class);
-        when(appConfig.getAAIHttpClientConfiguration()).thenReturn(mock(AAIHttpClientConfiguration.class));
-        return spy(new AAIPublisherTaskImpl(appConfig));
+        HttpRequestDetails requestDetails = mock(HttpRequestDetails.class);
+        when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class));
+        return spy(new AAIProducerTaskImpl(appConfig, requestDetails));
     }
 }
index 2d599b2..606b0cb 100644 (file)
@@ -40,11 +40,14 @@ public class ScheduleControllerSpy {
     private DmaapPublisherTask dmaapPublisherTaskImplSpy;
 
     @Autowired
-    private AAIPublisherTask aaiPublisherTaskImplSpy;
+    private AAIProducerTask aaiPublisherTaskImplSpy;
+
+    @Autowired
+    private AAIConsumerTask aaiConsumerTaskImplSpy;
 
     @Bean
     @Primary
     public ScheduledTasks registerSimpleScheduledTask() {
-        return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy));
+        return spy(new ScheduledTasks(dmaapConsumerTaskImplSpy, dmaapPublisherTaskImplSpy, aaiPublisherTaskImplSpy, aaiConsumerTaskImplSpy));
     }
 }