summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/test/java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java87
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java90
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java123
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java22
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java18
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java7
6 files changed, 157 insertions, 190 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java
new file mode 100644
index 00000000..88aa434c
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/TestAppConfiguration.java
@@ -0,0 +1,87 @@
+/*
+ * ============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;
+
+import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
+
+
+public class TestAppConfiguration {
+ public static ImmutableDmaapConsumerConfiguration createDefaultDmaapConsumerConfiguration() {
+ return new ImmutableDmaapConsumerConfiguration.Builder()
+ .consumerGroup("OpenDCAE-c12")
+ .consumerId("c12")
+ .dmaapContentType("application/json")
+ .dmaapHostName("message-router.onap.svc.cluster.local")
+ .dmaapPortNumber(3904)
+ .dmaapProtocol("http")
+ .dmaapUserName("admin")
+ .dmaapUserPassword("admin")
+ .keyFile("/opt/app/prh/local/org.onap.prh.keyfile")
+ .trustStore("/opt/app/prh/local/org.onap.prh.trust.jks")
+ .trustStorePassword("change_it")
+ .keyStore("/opt/app/prh/local/org.onap.prh.p12")
+ .keyStorePassword("change_it")
+ .enableDmaapCertAuth(false)
+ .dmaapTopicName("/events/unauthenticated.SEC_OTHER_OUTPUT")
+ .timeoutMs(-1)
+ .messageLimit(-1)
+ .build();
+ }
+
+ public static ImmutableDmaapPublisherConfiguration createDefaultDmaapPublisherConfiguration() {
+ return new ImmutableDmaapPublisherConfiguration.Builder()
+ .dmaapContentType("application/json")
+ .dmaapHostName("message-router.onap.svc.cluster.local")
+ .dmaapPortNumber(3904)
+ .dmaapProtocol("http")
+ .dmaapUserName("admin")
+ .dmaapUserPassword("admin")
+ .keyFile("/opt/app/prh/local/org.onap.prh.keyfile")
+ .trustStore("/opt/app/prh/local/org.onap.prh.trust.jks")
+ .trustStorePassword("change_it")
+ .keyStore("/opt/app/prh/local/org.onap.prh.p12")
+ .keyStorePassword("change_it")
+ .enableDmaapCertAuth(false)
+ .dmaapTopicName("/events/unauthenticated.PNF_READY")
+ .build();
+ }
+
+ public static ImmutableAaiClientConfiguration createDefaultAaiClientConfiguration() {
+ return new ImmutableAaiClientConfiguration.Builder()
+ .aaiHost("aai.onap.svc.cluster.local")
+ .aaiPort(8443)
+ .aaiProtocol("https")
+ .aaiUserName("AAI")
+ .aaiUserPassword("AAI")
+ .aaiIgnoreSslCertificateErrors(true)
+ .aaiBasePath("/aai/v12")
+ .aaiPnfPath("/network/pnfs/pnf")
+ .keyFile("/opt/app/prh/local/org.onap.prh.keyfile")
+ .trustStore("/opt/app/prh/local/org.onap.prh.trust.jks")
+ .trustStorePassword("change_it")
+ .keyStore("/opt/app/prh/local/org.onap.prh.p12")
+ .keyStorePassword("change_it")
+ .enableAaiCertAuth(false)
+ .build();
+ }
+} \ No newline at end of file
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java
index dd0a3dbd..f05dfa7f 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParserTest.java
@@ -20,11 +20,15 @@
package org.onap.dcaegen2.services.prh.configuration;
+import static java.lang.ClassLoader.getSystemResource;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.TestAppConfiguration;
import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
@@ -32,79 +36,25 @@ import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
-public class CloudConfigParserTest {
- private static final String correctJson =
- "{\"aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors\": true, "
- + "\"dmaap.dmaapProducerConfiguration.dmaapTopicName\": \"/events/unauthenticated.PNF_READY\", "
- + "\"dmaap.dmaapConsumerCon"
- + "figuration.timeoutMs\": -1, \"dmaap.dmaapConsumerConfiguration.dmaapHostName\": "
- + "\"message-router.onap.svc.cluster.local\", \"aai.aaiClientConfiguration.aaiPnfPath\": "
- + "\"/network/pnfs/pnf\", \"aai.aaiClientConfiguration.aai"
- + "UserPassword\": \"AAI\", \"dmaap.dmaapConsumerConfiguration.dmaapUserName\": \"admin\", "
- + "\"aai.aaiClientConfiguration.aaiBasePath\": \"/aai/v12\", "
- + "\"dmaap.dmaapProducerConfiguration.dmaapPortNumber\": 3904, \"aai.aaiClientConf"
- + "iguration.aaiHost\": \"aai.onap.svc.cluster.local\", "
- + "\"dmaap.dmaapConsumerConfiguration.dmaapUserPassword\": \"admin\", "
- + "\"dmaap.dmaapProducerConfiguration.dmaapProtocol\": \"http\", \"dmaap.dmaapProducerConfiguration.dmaapC"
- + "ontentType\": \"application/json\", "
- + "\"dmaap.dmaapConsumerConfiguration.dmaapTopicName\": \"/events/unauthenticated.SEC_OTHER_OUTPUT\", "
- + "\"dmaap.dmaapConsumerConfiguration.dmaapPortNumber\": 3904, \"dmaap.dmaapConsumerConfi"
- + "guration.dmaapContentType\": \"application/json\", \"dmaap.dmaapConsumerConfiguration.messageLimit\": "
- + "-1, \"dmaap.dmaapConsumerConfiguration.dmaapProtocol\": \"http\", "
- + "\"aai.aaiClientConfiguration.aaiUserName\": \"AAI\", \"dm"
- + "aap.dmaapConsumerConfiguration.consumerId\": \"c12\", \"dmaap.dmaapProducerConfiguration.dmaapHostName\""
- + ": \"message-router.onap.svc.cluster.local\", \"aai.aaiClientConfiguration.aaiHostPortNumber\": "
- + "8443, \"dmaap.dmaapConsumerConfiguration.consumerGroup\": \"OpenDCAE-c12\", "
- + "\"aai.aaiClientConfiguration.aaiProtocol\": \"https\", "
- + "\"dmaap.dmaapProducerConfiguration.dmaapUserName\": \"admin\", "
- + "\"dmaap.dmaapProducerConfiguration.dmaapUserPasswor"
- + "d\": \"admin\"}";
+class CloudConfigParserTest {
- private static final ImmutableAaiClientConfiguration correctAaiClientConfig =
- new ImmutableAaiClientConfiguration.Builder()
- .aaiHost("aai.onap.svc.cluster.local")
- .aaiPort(8443)
- .aaiUserName("AAI")
- .aaiPnfPath("/network/pnfs/pnf")
- .aaiIgnoreSslCertificateErrors(true)
- .aaiUserPassword("AAI")
- .aaiProtocol("https")
- .aaiBasePath("/aai/v12")
- .build();
-
- private static final ImmutableDmaapConsumerConfiguration correctDmaapConsumerConfig =
- new ImmutableDmaapConsumerConfiguration.Builder()
- .timeoutMs(-1)
- .dmaapHostName("message-router.onap.svc.cluster.local")
- .dmaapUserName("admin")
- .dmaapUserPassword("admin")
- .dmaapTopicName("/events/unauthenticated.SEC_OTHER_OUTPUT")
- .dmaapPortNumber(3904)
- .dmaapContentType("application/json")
- .messageLimit(-1)
- .dmaapProtocol("http")
- .consumerId("c12")
- .consumerGroup("OpenDCAE-c12")
- .build();
-
- private static final ImmutableDmaapPublisherConfiguration correctDmaapPublisherConfig =
- new ImmutableDmaapPublisherConfiguration.Builder()
- .dmaapTopicName("/events/unauthenticated.PNF_READY")
- .dmaapUserPassword("admin")
- .dmaapPortNumber(3904)
- .dmaapProtocol("http")
- .dmaapContentType("application/json")
- .dmaapHostName("message-router.onap.svc.cluster.local")
- .dmaapUserName("admin")
- .build();
-
- private CloudConfigParser cloudConfigParser = new CloudConfigParser(
- new Gson().fromJson(correctJson, JsonObject.class));
+ private final String correctJson =
+ new String(Files.readAllBytes(Paths.get(getSystemResource("flattened_configuration.json").toURI())));
+ private final ImmutableAaiClientConfiguration correctAaiClientConfig =
+ TestAppConfiguration.createDefaultAaiClientConfiguration();
+ private final ImmutableDmaapConsumerConfiguration correctDmaapConsumerConfig =
+ TestAppConfiguration.createDefaultDmaapConsumerConfiguration();
+ private final ImmutableDmaapPublisherConfiguration correctDmaapPublisherConfig =
+ TestAppConfiguration.createDefaultDmaapPublisherConfiguration();
+ private final CloudConfigParser cloudConfigParser = new CloudConfigParser(
+ new Gson().fromJson(correctJson, JsonObject.class));
+ CloudConfigParserTest() throws Exception {
+ }
@Test
- public void shouldCreateAaiConfigurationCorrectly() {
+ void shouldCreateAaiConfigurationCorrectly() {
// when
AaiClientConfiguration aaiClientConfig = cloudConfigParser.getAaiClientConfig();
@@ -115,7 +65,7 @@ public class CloudConfigParserTest {
@Test
- public void shouldCreateDmaapConsumerConfigurationCorrectly() {
+ void shouldCreateDmaapConsumerConfigurationCorrectly() {
// when
DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
@@ -126,7 +76,7 @@ public class CloudConfigParserTest {
@Test
- public void shouldCreateDmaapPublisherConfigurationCorrectly() {
+ void shouldCreateDmaapPublisherConfigurationCorrectly() {
// when
DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
index c4c86db9..61e17d37 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
@@ -20,12 +20,15 @@
package org.onap.dcaegen2.services.prh.configuration;
+import static java.lang.ClassLoader.getSystemResource;
+import static java.nio.file.Files.readAllBytes;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
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.when;
@@ -35,8 +38,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import java.util.Objects;
-import org.junit.jupiter.api.Assertions;
+import java.nio.file.Paths;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -44,51 +46,22 @@ import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtensio
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
*/
@ExtendWith({MockitoExtension.class})
class PrhAppConfigTest {
- private static final String PRH_ENDPOINTS = "prh_endpoints.json";
- private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
- + "\"localhost\",\"aaiPort\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":"
- + "\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\","
- + "\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\","
- + "\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Content-Type\":\"application/merge-patch+json\","
- + "\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},"
- + "\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\","
- + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,"
- + "\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\""
- + ":\"admin\",\"messageLimit\":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":"
- + "\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\","
- + "\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
-
- private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
- + "\"localhost\",\"aaiPort\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":\"https\","
- + "\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":"
- + "\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":"
- + "\"application/json\",\"Real-Time\":\"true\",\"Content-Type\":\"application/merge-patch+json\","
- + "\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\""
- + ":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\""
- + ":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\""
- + ",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\""
- + ":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\","
- + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\""
- + ":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
-
+ private final String jsonString =
+ new String(readAllBytes(Paths.get(getSystemResource("correct_config.json").toURI())));
+ private final String incorrectJsonString =
+ new String(readAllBytes(Paths.get(getSystemResource("incorrect_config.json").toURI())));
private PrhAppConfig prhAppConfig;
private AppConfig appConfig;
- private static InputStream inputStream;
- static {
- try {
- inputStream = Objects
- .requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).openStream();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ PrhAppConfigTest() throws Exception {
}
@BeforeEach
@@ -98,30 +71,16 @@ class PrhAppConfigTest {
}
@Test
- void whenApplicationWasStarted_FilePathIsSet() throws IOException {
- //
- // When
- //
- doReturn(inputStream).when(prhAppConfig).getInputStream(anyString());
- //
- // Then
- //
- verify(prhAppConfig, times(0)).initFileStreamReader();
- }
-
- @Test
- void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration()
- throws IOException {
+ void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration() {
//
// Given
//
InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
- StandardCharsets.UTF_8)));
+ StandardCharsets.UTF_8)));
//
// When
//
prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
- doReturn(inputStream).when(prhAppConfig).getInputStream(any());
prhAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration();
appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration();
@@ -129,16 +88,13 @@ class PrhAppConfigTest {
//
// Then
//
- verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
- Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration());
- Assertions
- .assertEquals(appConfig.getDmaapPublisherConfiguration(), prhAppConfig.getDmaapPublisherConfiguration());
- Assertions
- .assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration());
- Assertions
- .assertEquals(appConfig.getAaiClientConfiguration(), prhAppConfig.getAaiClientConfiguration());
+ verify(prhAppConfig).initFileStreamReader();
+ assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
+ assertNotNull(prhAppConfig.getDmaapPublisherConfiguration());
+ assertNotNull(prhAppConfig.getAaiClientConfiguration());
+ assertEquals(appConfig.getDmaapPublisherConfiguration(), prhAppConfig.getDmaapPublisherConfiguration());
+ assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration());
+ assertEquals(appConfig.getAaiClientConfiguration(), prhAppConfig.getAaiClientConfiguration());
}
@@ -147,7 +103,7 @@ class PrhAppConfigTest {
//
// Given
InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
- StandardCharsets.UTF_8)));
+ StandardCharsets.UTF_8)));
Resource resource = spy(new InputStreamResource(inputStream));
//
when(resource.getInputStream()).thenThrow(new IOException());
@@ -159,47 +115,44 @@ class PrhAppConfigTest {
//
// Then
//
- verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
- Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
+ verify(prhAppConfig).initFileStreamReader();
+ assertNull(prhAppConfig.getAaiClientConfiguration());
+ assertNull(prhAppConfig.getDmaapConsumerConfiguration());
+ assertNull(prhAppConfig.getDmaapPublisherConfiguration());
}
@Test
- void whenFileIsExistsButJsonIsIncorrect() throws IOException {
+ void whenFileIsExistsButJsonIsIncorrect() {
//
// Given
//
InputStream inputStream = new ByteArrayInputStream((incorrectJsonString.getBytes(
- StandardCharsets.UTF_8)));
+ StandardCharsets.UTF_8)));
//
// When
//
prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
- doReturn(inputStream).when(prhAppConfig).getInputStream(any());
prhAppConfig.initFileStreamReader();
//
// Then
//
- verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
- Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
+ verify(prhAppConfig).initFileStreamReader();
+ assertNotNull(prhAppConfig.getAaiClientConfiguration());
+ assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
+ assertNull(prhAppConfig.getDmaapPublisherConfiguration());
}
@Test
- void whenTheConfigurationFits_ButRootElementIsNotAJsonObject()
- throws IOException {
+ void whenTheConfigurationFits_ButRootElementIsNotAJsonObject() {
// Given
InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
- StandardCharsets.UTF_8)));
+ StandardCharsets.UTF_8)));
// When
prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
- doReturn(inputStream).when(prhAppConfig).getInputStream(any());
JsonElement jsonElement = mock(JsonElement.class);
when(jsonElement.isJsonObject()).thenReturn(false);
doReturn(jsonElement).when(prhAppConfig).getJsonElement(any(JsonParser.class), any(InputStream.class));
@@ -209,9 +162,9 @@ class PrhAppConfigTest {
appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration();
// Then
- verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
- Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
+ verify(prhAppConfig).initFileStreamReader();
+ assertNull(prhAppConfig.getAaiClientConfiguration());
+ assertNull(prhAppConfig.getDmaapConsumerConfiguration());
+ assertNull(prhAppConfig.getDmaapPublisherConfiguration());
}
} \ No newline at end of file
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
index 6a9326e1..56d7b818 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
@@ -29,13 +29,14 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+
import javax.net.ssl.SSLException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
+import org.onap.dcaegen2.services.prh.TestAppConfiguration;
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.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
@@ -51,14 +52,6 @@ import reactor.test.StepVerifier;
*/
class AaiProducerTaskImplTest {
-
- private static final String AAI_HOST = "/aai/v11/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/v11";
- private static final String PNF_PATH = "/network/pnfs/pnf";
-
private ConsumerDmaapModel consumerDmaapModel;
private AaiProducerTaskImpl aaiProducerTask;
private AaiClientConfiguration aaiClientConfiguration;
@@ -69,16 +62,7 @@ class AaiProducerTaskImplTest {
@BeforeEach
void setUp() {
clientResponse = mock(ClientResponse.class);
- aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
- .aaiHost(AAI_HOST)
- .aaiPort(PORT)
- .aaiProtocol(PROTOCOL)
- .aaiUserName(USER_NAME_PASSWORD)
- .aaiUserPassword(USER_NAME_PASSWORD)
- .aaiIgnoreSslCertificateErrors(true)
- .aaiBasePath(BASE_PATH)
- .aaiPnfPath(PNF_PATH)
- .build();
+ aaiClientConfiguration = TestAppConfiguration.createDefaultAaiClientConfiguration();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E").build();
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
index c17e2543..8d6218ee 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
@@ -21,12 +21,13 @@
package org.onap.dcaegen2.services.prh.tasks;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
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.when;
+import static org.onap.dcaegen2.services.prh.TestAppConfiguration.createDefaultDmaapConsumerConfiguration;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
@@ -35,16 +36,14 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
@@ -61,10 +60,7 @@ class DmaapConsumerTaskImplTest {
@BeforeAll
static void setUp() {
- dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder().consumerGroup("OpenDCAE-c12")
- .consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
- .dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH")
- .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMs(-1).messageLimit(-1).build();
+ dmaapConsumerConfiguration = createDefaultDmaapConsumerConfiguration();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
@@ -113,8 +109,8 @@ class DmaapConsumerTaskImplTest {
Flux<ConsumerDmaapModel> response = dmaapConsumerTask.execute("Sample input");
//then
- verify(dMaaPConsumerReactiveHttpClient, times(1)).getDMaaPConsumerResponse();
- assertEquals(null, response.blockFirst());
+ verify(dMaaPConsumerReactiveHttpClient).getDMaaPConsumerResponse();
+ assertNull(response.blockFirst());
}
@Test
@@ -126,7 +122,7 @@ class DmaapConsumerTaskImplTest {
Flux<ConsumerDmaapModel> response = dmaapConsumerTask.execute("Sample input");
//then
- verify(dMaaPConsumerReactiveHttpClient, times(1)).getDMaaPConsumerResponse();
+ verify(dMaaPConsumerReactiveHttpClient).getDMaaPConsumerResponse();
assertEquals(consumerDmaapModel, response.blockFirst());
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
index fad7a067..00d6fc46 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
@@ -29,12 +29,12 @@ 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 static org.onap.dcaegen2.services.prh.TestAppConfiguration.createDefaultDmaapPublisherConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
@@ -59,10 +59,7 @@ class DmaapPublisherTaskImplTest {
@BeforeAll
static void setUp() {
- dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
- .dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
- .dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH")
- .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").build();
+ dmaapPublisherConfiguration = createDefaultDmaapPublisherConfiguration();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E").build();