aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java77
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java23
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java3
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java29
-rw-r--r--prh-app-server/src/main/resources/prh_endpoints.json9
-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
-rw-r--r--prh-app-server/src/test/resources/correct_config.json (renamed from prh-app-server/src/test/resources/prh_endpoints.json)20
-rw-r--r--prh-app-server/src/test/resources/flattened_configuration.json35
-rw-r--r--prh-app-server/src/test/resources/incorrect_config.json57
14 files changed, 389 insertions, 211 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
index c5c77ec2..643462f1 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
@@ -32,7 +32,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
*/
@@ -120,6 +119,27 @@ public class AppConfig extends PrhAppConfig {
@Value("${aai.aaiClientConfiguration.aaiPnfPath:}")
public String aaiPnfPath;
+ @Value("${security.keyFile:}")
+ public String keyFile;
+
+ @Value("${security.trustStore:}")
+ public String trustStore;
+
+ @Value("${security.trustStorePassword:}")
+ public String trustStorePassword;
+
+ @Value("${security.keyStore:}")
+ public String keyStore;
+
+ @Value("${security.keyStorePassword:}")
+ public String keyStorePassword;
+
+ @Value("${security.enableAaiCertAuth:}")
+ public Boolean enableAaiCertAuth;
+
+ @Value("${security.enableDmaapCertAuth:}")
+ public Boolean enableDmaapCertAuth;
+
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return new ImmutableDmaapConsumerConfiguration.Builder()
@@ -153,6 +173,24 @@ public class AppConfig extends PrhAppConfig {
.orElse(dmaapConsumerConfiguration.consumerGroup()))
.consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.consumerId()))
+ .keyFile(
+ Optional.ofNullable(keyFile).filter(p -> !p.isEmpty())
+ .orElse(dmaapConsumerConfiguration.keyFile()))
+ .trustStore(
+ Optional.ofNullable(trustStore).filter(p -> !p.isEmpty())
+ .orElse(dmaapConsumerConfiguration.trustStore()))
+ .trustStorePassword(
+ Optional.ofNullable(trustStorePassword).filter(isEmpty.negate())
+ .orElse(dmaapConsumerConfiguration.trustStorePassword()))
+ .keyStore(
+ Optional.ofNullable(keyStore).filter(p -> !p.isEmpty())
+ .orElse(dmaapConsumerConfiguration.keyStore()))
+ .keyStorePassword(
+ Optional.ofNullable(keyStorePassword).filter(isEmpty.negate())
+ .orElse(dmaapConsumerConfiguration.keyStorePassword()))
+ .enableDmaapCertAuth(
+ Optional.ofNullable(enableDmaapCertAuth).filter(p -> !p.toString().isEmpty())
+ .orElse(dmaapConsumerConfiguration.enableDmaapCertAuth()))
.build();
}
@@ -177,6 +215,24 @@ public class AppConfig extends PrhAppConfig {
.aaiPnfPath(
Optional.ofNullable(aaiPnfPath).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiPnfPath()))
.aaiHeaders(aaiClientConfiguration.aaiHeaders())
+ .keyFile(
+ Optional.ofNullable(keyFile).filter(p -> !p.isEmpty())
+ .orElse(aaiClientConfiguration.keyFile()))
+ .trustStore(
+ Optional.ofNullable(trustStore).filter(p -> !p.isEmpty())
+ .orElse(aaiClientConfiguration.trustStore()))
+ .trustStorePassword(
+ Optional.ofNullable(trustStorePassword).filter(isEmpty.negate())
+ .orElse(aaiClientConfiguration.trustStorePassword()))
+ .keyStore(
+ Optional.ofNullable(keyStore).filter(p -> !p.isEmpty())
+ .orElse(aaiClientConfiguration.keyStore()))
+ .keyStorePassword(
+ Optional.ofNullable(keyStorePassword).filter(isEmpty.negate())
+ .orElse(aaiClientConfiguration.keyStorePassword()))
+ .enableAaiCertAuth(
+ Optional.ofNullable(enableAaiCertAuth).filter(p -> !p.toString().isEmpty())
+ .orElse(aaiClientConfiguration.enableAaiCertAuth()))
.build();
}
@@ -204,7 +260,24 @@ public class AppConfig extends PrhAppConfig {
.dmaapUserPassword(
Optional.ofNullable(producerDmaapUserPassword).filter(isEmpty.negate())
.orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
+ .keyFile(
+ Optional.ofNullable(keyFile).filter(p -> !p.isEmpty())
+ .orElse(dmaapPublisherConfiguration.keyFile()))
+ .trustStore(
+ Optional.ofNullable(trustStore).filter(p -> !p.isEmpty())
+ .orElse(dmaapPublisherConfiguration.trustStore()))
+ .trustStorePassword(
+ Optional.ofNullable(trustStorePassword).filter(isEmpty.negate())
+ .orElse(dmaapPublisherConfiguration.trustStorePassword()))
+ .keyStore(
+ Optional.ofNullable(keyStore).filter(p -> !p.isEmpty())
+ .orElse(dmaapPublisherConfiguration.keyStore()))
+ .keyStorePassword(
+ Optional.ofNullable(keyStorePassword).filter(isEmpty.negate())
+ .orElse(dmaapPublisherConfiguration.keyStorePassword()))
+ .enableDmaapCertAuth(
+ Optional.ofNullable(enableDmaapCertAuth).filter(p -> !p.toString().isEmpty())
+ .orElse(dmaapPublisherConfiguration.enableDmaapCertAuth()))
.build();
}
-
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java
index 32d8a562..2e57256e 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfigParser.java
@@ -33,6 +33,11 @@ import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguratio
*/
class CloudConfigParser {
+ private static final String SECURITY_KEY_FILE = "security.keyFile";
+ private static final String SECURITY_TRUST_STORE = "security.trustStore";
+ private static final String SECURITY_KEY_STORE = "security.keyStore";
+ private static final String KEY_STORE_PASS = "security.keyStorePassword";
+ private static final String TRUST_STORE_PASS = "security.trustStorePassword";
private final JsonObject jsonObject;
CloudConfigParser(JsonObject jsonObject) {
@@ -48,6 +53,12 @@ class CloudConfigParser {
.dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString())
.dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString())
.dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString())
+ .keyFile(jsonObject.get(SECURITY_KEY_FILE).getAsString())
+ .trustStore(jsonObject.get(SECURITY_TRUST_STORE).getAsString())
+ .trustStorePassword(jsonObject.get(TRUST_STORE_PASS).getAsString())
+ .keyStore(jsonObject.get(SECURITY_KEY_STORE).getAsString())
+ .keyStorePassword(jsonObject.get(KEY_STORE_PASS).getAsString())
+ .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean())
.build();
}
@@ -62,6 +73,12 @@ class CloudConfigParser {
.aaiUserPassword(jsonObject.get("aai.aaiClientConfiguration.aaiUserPassword").getAsString())
.aaiProtocol(jsonObject.get("aai.aaiClientConfiguration.aaiProtocol").getAsString())
.aaiBasePath(jsonObject.get("aai.aaiClientConfiguration.aaiBasePath").getAsString())
+ .keyFile(jsonObject.get(SECURITY_KEY_FILE).getAsString())
+ .trustStore(jsonObject.get(SECURITY_TRUST_STORE).getAsString())
+ .trustStorePassword(jsonObject.get(TRUST_STORE_PASS).getAsString())
+ .keyStore(jsonObject.get(SECURITY_KEY_STORE).getAsString())
+ .keyStorePassword(jsonObject.get(KEY_STORE_PASS).getAsString())
+ .enableAaiCertAuth(jsonObject.get("security.enableAaiCertAuth").getAsBoolean())
.build();
}
@@ -78,6 +95,12 @@ class CloudConfigParser {
.dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString())
.consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString())
.consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString())
+ .keyFile(jsonObject.get(SECURITY_KEY_FILE).getAsString())
+ .trustStore(jsonObject.get(SECURITY_TRUST_STORE).getAsString())
+ .trustStorePassword(jsonObject.get(TRUST_STORE_PASS).getAsString())
+ .keyStore(jsonObject.get(SECURITY_KEY_STORE).getAsString())
+ .keyStorePassword(jsonObject.get(KEY_STORE_PASS).getAsString())
+ .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean())
.build();
}
} \ No newline at end of file
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
index e598b4b3..1e1e0491 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
@@ -104,9 +104,8 @@ public class CloudConfiguration extends AppConfig {
return Optional.ofNullable(aaiClientCloudConfiguration).orElse(super.getAaiClientConfiguration());
}
-
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
return Optional.ofNullable(dmaapConsumerCloudConfiguration).orElse(super.getDmaapConsumerConfiguration());
}
-}
+} \ No newline at end of file
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
index 18cd1f8f..54c63532 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
@@ -26,8 +26,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapterFactory;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -59,6 +57,7 @@ public abstract class PrhAppConfig implements Config {
private static final String AAI_CONFIG = "aaiClientConfiguration";
private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
+ private static final String SECURITY = "security";
private static final Logger LOGGER = LoggerFactory.getLogger(PrhAppConfig.class);
@@ -92,22 +91,25 @@ public abstract class PrhAppConfig implements Config {
GsonBuilder gsonBuilder = new GsonBuilder();
ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
JsonParser parser = new JsonParser();
- JsonObject jsonObject;
try (InputStream inputStream = resourceFile.getInputStream()) {
JsonElement rootElement = getJsonElement(parser, inputStream);
if (rootElement.isJsonObject()) {
- jsonObject = rootElement.getAsJsonObject();
+ JsonObject jsonObject = concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY));
aaiClientConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
+ jsonObject,
AaiClientConfiguration.class);
-
dmaapConsumerConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+ concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
DmaapConsumerConfiguration.class);
-
dmaapPublisherConfiguration = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+ concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
DmaapPublisherConfiguration.class);
}
} catch (IOException e) {
@@ -121,6 +123,12 @@ public abstract class PrhAppConfig implements Config {
return parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
}
+ private JsonObject concatenateJsonObjects(JsonObject target, JsonObject source) {
+ source.entrySet()
+ .forEach(entry -> target.add(entry.getKey(), entry.getValue()));
+ return target;
+ }
+
private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
@NotNull Class<T> type) {
return gsonBuilder.create().fromJson(jsonObject, type);
@@ -130,7 +138,4 @@ public abstract class PrhAppConfig implements Config {
this.resourceFile = resourceFile;
}
- InputStream getInputStream(@NotNull String filepath) throws IOException {
- return new BufferedInputStream(new FileInputStream(filepath));
- }
} \ No newline at end of file
diff --git a/prh-app-server/src/main/resources/prh_endpoints.json b/prh-app-server/src/main/resources/prh_endpoints.json
index b3bff7d9..75917f12 100644
--- a/prh-app-server/src/main/resources/prh_endpoints.json
+++ b/prh-app-server/src/main/resources/prh_endpoints.json
@@ -42,6 +42,15 @@
"Content-Type": "application/merge-patch+json"
}
}
+ },
+ "security": {
+ "keyFile" : "/opt/app/prh/local/org.onap.prh.keyfile",
+ "trustStore" : "change it",
+ "trustStorePassword" : "change it",
+ "keyStore" : "change it",
+ "keyStorePassword" : "change it",
+ "enableAaiCertAuth" : "false",
+ "enableDmaapCertAuth" : "false"
}
}
} \ No newline at end of file
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();
diff --git a/prh-app-server/src/test/resources/prh_endpoints.json b/prh-app-server/src/test/resources/correct_config.json
index 07e87c67..d250114d 100644
--- a/prh-app-server/src/test/resources/prh_endpoints.json
+++ b/prh-app-server/src/test/resources/correct_config.json
@@ -6,8 +6,8 @@
"aaiPort": 8080,
"aaiIgnoreSslCertificateErrors": true,
"aaiProtocol": "https",
- "aaiUserName": "AAI",
- "aaiUserPassword": "AAI",
+ "aaiUserName": "admin",
+ "aaiUserPassword": "admin",
"aaiBasePath": "/aai/v11",
"aaiPnfPath": "/network/pnfs/pnf",
"aaiHeaders": {
@@ -15,7 +15,8 @@
"X-TransactionId": "9999",
"Accept": "application/json",
"Real-Time": "true",
- "Content-Type": "application/merge-patch+json"
+ "Content-Type": "application/merge-patch+json",
+ "Authorization": "Basic QUFJOkFBSQ=="
}
}
},
@@ -27,7 +28,7 @@
"dmaapHostName": "localhost",
"dmaapPortNumber": 2222,
"dmaapProtocol": "http",
- "dmaapTopicName": "/events/pnfReady",
+ "dmaapTopicName": "temp",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin",
"messageLimit": 1000,
@@ -38,10 +39,19 @@
"dmaapHostName": "localhost",
"dmaapPortNumber": 2223,
"dmaapProtocol": "http",
- "dmaapTopicName": "/events/pnfReady",
+ "dmaapTopicName": "temp",
"dmaapUserName": "admin",
"dmaapUserPassword": "admin"
}
+ },
+ "security": {
+ "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",
+ "enableDmaapCertAuth": "false"
}
}
} \ No newline at end of file
diff --git a/prh-app-server/src/test/resources/flattened_configuration.json b/prh-app-server/src/test/resources/flattened_configuration.json
new file mode 100644
index 00000000..6584a594
--- /dev/null
+++ b/prh-app-server/src/test/resources/flattened_configuration.json
@@ -0,0 +1,35 @@
+{
+ "aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors": true,
+ "dmaap.dmaapProducerConfiguration.dmaapTopicName": "/events/unauthenticated.PNF_READY",
+ "dmaap.dmaapConsumerConfiguration.timeoutMs": -1,
+ "dmaap.dmaapConsumerConfiguration.dmaapHostName": "message-router.onap.svc.cluster.local",
+ "aai.aaiClientConfiguration.aaiPnfPath": "/network/pnfs/pnf",
+ "aai.aaiClientConfiguration.aaiUserPassword": "AAI",
+ "dmaap.dmaapConsumerConfiguration.dmaapUserName": "admin",
+ "aai.aaiClientConfiguration.aaiBasePath": "/aai/v12",
+ "dmaap.dmaapProducerConfiguration.dmaapPortNumber": 3904,
+ "aai.aaiClientConfiguration.aaiHost": "aai.onap.svc.cluster.local",
+ "dmaap.dmaapConsumerConfiguration.dmaapUserPassword": "admin",
+ "dmaap.dmaapProducerConfiguration.dmaapProtocol": "http",
+ "dmaap.dmaapProducerConfiguration.dmaapContentType": "application/json",
+ "dmaap.dmaapConsumerConfiguration.dmaapTopicName": "/events/unauthenticated.SEC_OTHER_OUTPUT",
+ "dmaap.dmaapConsumerConfiguration.dmaapPortNumber": 3904,
+ "dmaap.dmaapConsumerConfiguration.dmaapContentType": "application/json",
+ "dmaap.dmaapConsumerConfiguration.messageLimit": -1,
+ "dmaap.dmaapConsumerConfiguration.dmaapProtocol": "http",
+ "aai.aaiClientConfiguration.aaiUserName": "AAI",
+ "dmaap.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.dmaapUserPassword": "admin",
+ "security.keyFile": "/opt/app/prh/local/org.onap.prh.keyfile",
+ "security.trustStore": "/opt/app/prh/local/org.onap.prh.trust.jks",
+ "security.trustStorePassword": "change_it",
+ "security.keyStore": "/opt/app/prh/local/org.onap.prh.p12",
+ "security.keyStorePassword": "change_it",
+ "security.enableAaiCertAuth": false,
+ "security.enableDmaapCertAuth": false
+} \ No newline at end of file
diff --git a/prh-app-server/src/test/resources/incorrect_config.json b/prh-app-server/src/test/resources/incorrect_config.json
new file mode 100644
index 00000000..f320d982
--- /dev/null
+++ b/prh-app-server/src/test/resources/incorrect_config.json
@@ -0,0 +1,57 @@
+{
+ "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"
+ }
+ },
+ "security": {
+ "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",
+ "enableDmaapCertAuth": "false"
+ }
+ }
+} \ No newline at end of file