summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTask.java6
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImpl.java39
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIProducerTaskImpl.java4
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImplTest.java174
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java (renamed from prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapConsumerConfigurationTest.java)59
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java (renamed from prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapPublisherConfigurationTest.java)43
6 files changed, 261 insertions, 64 deletions
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 5a3afd86..b4b66036 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
@@ -22,9 +22,9 @@ package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
-public abstract class AAIConsumerTask<T> extends Task {
+public abstract class AAIConsumerTask<T, U, V> extends Task {
- protected abstract void consume() throws AAINotFoundException;
+ protected abstract V consume(U message) throws AAINotFoundException;
- protected abstract T resolveConfiguration();
+ protected abstract T resolveClient();
}
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 cbe3d9aa..31af9c80 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
@@ -20,24 +20,25 @@
package org.onap.dcaegen2.services.prh.tasks;
+import java.io.IOException;
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.model.ConsumerDmaapModel;
+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;
-import java.util.Optional;
-
@Component
-public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration> {
+public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIConsumerClient, ConsumerDmaapModel, Object> {
private static final Logger logger = LoggerFactory.getLogger(AAIConsumerTaskImpl.class);
private final Config prhAppConfig;
- private Optional<String> response;
+ private AAIConsumerClient aaiConsumerClient;
@Autowired
public AAIConsumerTaskImpl(AppConfig prhAppConfig) {
@@ -45,13 +46,24 @@ public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration>
}
@Override
- protected void consume() throws AAINotFoundException {
+ protected Object 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");
+ }
}
@Override
public Object execute(Object object) throws AAINotFoundException {
- consume();
- return null;
+ setAAIClientConfig();
+ logger.trace("Method called with arg {}", object);
+ if (object instanceof ConsumerDmaapModel) {
+ return consume((ConsumerDmaapModel) object);
+ }
+ throw new AAINotFoundException("Incorrect object type");
}
@Override
@@ -59,8 +71,17 @@ public class AAIConsumerTaskImpl extends AAIConsumerTask<AAIClientConfiguration>
logger.trace("initConfigs for AAIConsumerTaskImpl not needed/supported");
}
- @Override
- protected AAIClientConfiguration resolveConfiguration() {
+
+ protected void setAAIClientConfig() {
+ aaiConsumerClient = resolveClient();
+ }
+
+ AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
+
+ @Override
+ protected AAIConsumerClient resolveClient() {
+ return new AAIConsumerClient(resolveConfiguration());
+ }
}
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 24de3124..5d022f85 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
@@ -79,11 +79,11 @@ public class AAIProducerTaskImpl extends AAIProducerTask<AAIProducerClient, Cons
logger.trace("initConfigs for AAIProducerTaskImpl not needed/supported");
}
- protected void setAAIClientConfig() {
+ void setAAIClientConfig() {
aaiProducerClient = resolveClient();
}
- protected AAIClientConfiguration resolveConfiguration() {
+ AAIClientConfiguration resolveConfiguration() {
return prhAppConfig.getAAIClientConfiguration();
}
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
new file mode 100644
index 00000000..548a285d
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AAIConsumerTaskImplTest.java
@@ -0,0 +1,174 @@
+/*
+ * ============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 static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Optional;
+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.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.service.AAIConsumerClient;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
+ */
+class AAIConsumerTaskImplTest {
+
+ private static ConsumerDmaapModel consumerDmaapModel;
+ private static AAIConsumerTaskImpl aaiConsumerTask;
+
+ private static final String AAI_HOST = "/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E";
+ private static final Integer PORT = 1234;
+ private static final String PROTOCOL = "https";
+ private static final String USER_NAME_PASSWORD = "PRH";
+ private static final String BASE_PATH = "/aai/v12";
+ private static final String PNF_PATH = "/network/pnfs/pnf";
+
+ private static AAIClientConfiguration aaiClientConfiguration;
+ private static AAIConsumerClient aaiConsumerClient;
+ private static AppConfig appConfig;
+
+ @BeforeAll
+ public static void setUp() {
+ aaiClientConfiguration = new ImmutableAAIClientConfiguration.Builder()
+ .aaiHost(AAI_HOST)
+ .aaiHostPortNumber(PORT)
+ .aaiProtocol(PROTOCOL)
+ .aaiUserName(USER_NAME_PASSWORD)
+ .aaiUserPassword(USER_NAME_PASSWORD)
+ .aaiIgnoreSSLCertificateErrors(true)
+ .aaiBasePath(BASE_PATH)
+ .aaiPnfPath(PNF_PATH)
+ .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);
+
+ }
+
+ @Test
+ public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() throws IOException {
+ //given
+ Object response = null;
+
+ //when
+ when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
+ try {
+ aaiConsumerTask = new AAIConsumerTaskImpl(appConfig);
+ response = aaiConsumerTask.execute("Some string");
+ } catch (PrhTaskException e) {
+ e.printStackTrace();
+ }
+ //then
+ Assertions.assertNull(response);
+ }
+
+ @Test
+ public void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, IOException {
+ //given
+ Object response;
+ aaiConsumerClient = mock(AAIConsumerClient.class);
+
+ //when
+ when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of("200"));
+ when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiConsumerTask = spy(new AAIConsumerTaskImpl(appConfig));
+ when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
+ doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient();
+ aaiConsumerTask.setAAIClientConfig();
+ aaiConsumerTask.initConfigs();
+ response = aaiConsumerTask.execute(consumerDmaapModel);
+
+ //then
+ verify(aaiConsumerClient, times(1)).getHttpResponse(any(ConsumerDmaapModel.class));
+ verifyNoMoreInteractions(aaiConsumerClient);
+ Assertions.assertNotNull(response);
+ Assertions.assertEquals(Optional.of("200"), response);
+
+ }
+
+ @Test
+ public void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException {
+ //given
+ Object response = null;
+ aaiConsumerClient = mock(AAIConsumerClient.class);
+ //when
+ when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of("400"));
+ when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiConsumerTask = spy(new AAIConsumerTaskImpl(appConfig));
+ when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
+ doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient();
+ aaiConsumerTask.setAAIClientConfig();
+ aaiConsumerTask.initConfigs();
+ try {
+ response = aaiConsumerTask.execute(consumerDmaapModel);
+ } catch (PrhTaskException e) {
+ e.printStackTrace();
+ }
+
+ //then
+ verify(aaiConsumerClient, times(1)).getHttpResponse(any(ConsumerDmaapModel.class));
+ verifyNoMoreInteractions(aaiConsumerClient);
+ Assertions.assertEquals(Optional.of("400"), response);
+ }
+
+ @Test
+ public void whenPassedObjectFits_ThrowsIOException() throws IOException {
+ //given
+ Object response = null;
+ aaiConsumerClient = mock(AAIConsumerClient.class);
+ //when
+ when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
+ when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenThrow(IOException.class);
+ aaiConsumerTask = spy(new AAIConsumerTaskImpl(appConfig));
+ when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
+ doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient();
+ aaiConsumerTask.setAAIClientConfig();
+ aaiConsumerTask.initConfigs();
+ try {
+ response = aaiConsumerTask.execute(consumerDmaapModel);
+ } catch (AAINotFoundException e) {
+ e.printStackTrace();
+ }
+
+ //then
+ verify(aaiConsumerClient, times(1)).getHttpResponse(any(ConsumerDmaapModel.class));
+ verifyNoMoreInteractions(aaiConsumerClient);
+ Assertions.assertNull(response);
+ }
+
+} \ No newline at end of file
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapConsumerConfigurationTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java
index 2c076cef..dc8f7b6e 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapConsumerConfigurationTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java
@@ -18,45 +18,46 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.service.config;
+package org.onap.dcaegen2.services.prh.service.config;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
public class DmaapConsumerConfigurationTest {
- // Given
- private DmaapConsumerConfiguration configuration;
- private String consumerId = "1";
- private String dmaapHostName = "localhost";
- private Integer dmaapPortNumber = 2222;
- private String dmaapTopicName = "temp";
- private String dmaapProtocol = "http";
- private String dmaapUserName = "admin";
- private String dmaapUserPassword = "admin";
- private String dmaapContentType = "application/json";
- private String consumerGroup = "other";
- private Integer timeoutMs = 1000;
- private Integer messageLimit = 1000;
-
@Test
public void builder_shouldBuildConfigurationObject() {
+
+ // Given
+ DmaapConsumerConfiguration configuration;
+ String consumerId = "1";
+ String dmaapHostName = "localhost";
+ Integer dmaapPortNumber = 2222;
+ String dmaapTopicName = "temp";
+ String dmaapProtocol = "http";
+ String dmaapUserName = "admin";
+ String dmaapUserPassword = "admin";
+ String dmaapContentType = "application/json";
+ String consumerGroup = "other";
+ Integer timeoutMs = 1000;
+ Integer messageLimit = 1000;
+
// When
configuration = new ImmutableDmaapConsumerConfiguration.Builder()
- .consumerId(consumerId)
- .dmaapHostName(dmaapHostName)
- .dmaapPortNumber(dmaapPortNumber)
- .dmaapTopicName(dmaapTopicName)
- .dmaapProtocol(dmaapProtocol)
- .dmaapUserName(dmaapUserName)
- .dmaapUserPassword(dmaapUserPassword)
- .dmaapContentType(dmaapContentType)
- .consumerGroup(consumerGroup)
- .timeoutMS(timeoutMs)
- .messageLimit(messageLimit)
- .build();
+ .consumerId(consumerId)
+ .dmaapHostName(dmaapHostName)
+ .dmaapPortNumber(dmaapPortNumber)
+ .dmaapTopicName(dmaapTopicName)
+ .dmaapProtocol(dmaapProtocol)
+ .dmaapUserName(dmaapUserName)
+ .dmaapUserPassword(dmaapUserPassword)
+ .dmaapContentType(dmaapContentType)
+ .consumerGroup(consumerGroup)
+ .timeoutMS(timeoutMs)
+ .messageLimit(messageLimit)
+ .build();
// Then
Assertions.assertNotNull(configuration);
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapPublisherConfigurationTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java
index 7796da5c..47dd30f4 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/config/DmaapPublisherConfigurationTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapPublisherConfigurationTest.java
@@ -18,38 +18,39 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.service.config;
+package org.onap.dcaegen2.services.prh.service.config;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
public class DmaapPublisherConfigurationTest {
- // Given
- private DmaapPublisherConfiguration configuration;
- private String dmaapHostName = "localhost";
- private Integer dmaapPortNumber = 2222;
- private String dmaapTopicName = "temp";
- private String dmaapProtocol = "http";
- private String dmaapUserName = "admin";
- private String dmaapUserPassword = "admin";
- private String dmaapContentType = "application/json";
-
@Test
public void builder_shouldBuildConfigurationObject() {
+
+ // Given
+ DmaapPublisherConfiguration configuration;
+ String dmaapHostName = "localhost";
+ Integer dmaapPortNumber = 2222;
+ String dmaapTopicName = "temp";
+ String dmaapProtocol = "http";
+ String dmaapUserName = "admin";
+ String dmaapUserPassword = "admin";
+ String dmaapContentType = "application/json";
+
// When
configuration = new ImmutableDmaapPublisherConfiguration.Builder()
- .dmaapHostName(dmaapHostName)
- .dmaapPortNumber(dmaapPortNumber)
- .dmaapTopicName(dmaapTopicName)
- .dmaapProtocol(dmaapProtocol)
- .dmaapUserName(dmaapUserName)
- .dmaapUserPassword(dmaapUserPassword)
- .dmaapContentType(dmaapContentType)
- .build();
+ .dmaapHostName(dmaapHostName)
+ .dmaapPortNumber(dmaapPortNumber)
+ .dmaapTopicName(dmaapTopicName)
+ .dmaapProtocol(dmaapProtocol)
+ .dmaapUserName(dmaapUserName)
+ .dmaapUserPassword(dmaapUserPassword)
+ .dmaapContentType(dmaapContentType)
+ .build();
// Then
Assertions.assertNotNull(configuration);