summaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java24
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java29
2 files changed, 47 insertions, 6 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
index 34d72203..130f1efc 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
@@ -3,6 +3,7 @@
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modification Copyright 2022. Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +27,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Paths;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -86,6 +88,28 @@ public class CommonTestData {
}
/**
+ * Gets the postgres PAP parameters, as a String.
+ *
+ * @param port port to be inserted into the parameters
+ * @return the postgres PAP parameters
+ */
+ public String getPapPostgresParameterGroupAsString(int port) {
+
+ try {
+ String json = new String(Files.readAllBytes(Paths.get(
+ "src/test/resources/parameters/PapConfigParameters_Postgres.json")));
+
+ json = json.replace("${port}", String.valueOf(port));
+ json = json.replace("${dbName}", "jdbc:h2:mem:testdb" + dbNum);
+
+ return json;
+
+ } catch (IOException e) {
+ throw new PolicyPapRuntimeException("cannot read PAP parameters", e);
+ }
+ }
+
+ /**
* Gets the full path to the parameter file, which may vary depending on whether or
* not this is an end-to-end test.
*
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java
index 926a1f49..d52e21f4 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java
@@ -3,6 +3,7 @@
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modification Copyright 2022. Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +32,7 @@ import org.junit.Test;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
/**
@@ -52,12 +54,14 @@ public class TestPapParameterGroup {
@Test
public void testPapParameterGroup() {
final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
- final TopicParameterGroup topicParameterGroup = papParameters.getTopicParameterGroup();
- final ValidationResult validationResult = papParameters.validate();
- assertTrue(validationResult.isValid());
- assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
- assertEquals(topicParameterGroup.getTopicSinks(), papParameters.getTopicParameterGroup().getTopicSinks());
- assertEquals(topicParameterGroup.getTopicSources(), papParameters.getTopicParameterGroup().getTopicSources());
+ validateParameters(papParameters);
+ }
+
+ @Test
+ public void testPapParameterGroup_Postgres() throws CoderException {
+ String json = commonTestData.getPapPostgresParameterGroupAsString(1);
+ final PapParameterGroup papPostgresParameters = coder.decode(json, PapParameterGroup.class);
+ validateParameters(papPostgresParameters);
}
@Test
@@ -89,4 +93,17 @@ public class TestPapParameterGroup {
assertEquals("PapNewGroup", papParameters.getName());
}
+ /**
+ * Validates the pap parameters.
+ *
+ * @param parameterGroup parameter group being tested
+ */
+ public void validateParameters(PapParameterGroup parameterGroup) {
+ final TopicParameterGroup topicParameterGroup = parameterGroup.getTopicParameterGroup();
+ final ValidationResult validationResult = parameterGroup.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(CommonTestData.PAP_GROUP_NAME, parameterGroup.getName());
+ assertEquals(topicParameterGroup.getTopicSinks(), parameterGroup.getTopicParameterGroup().getTopicSinks());
+ assertEquals(topicParameterGroup.getTopicSources(), parameterGroup.getTopicParameterGroup().getTopicSources());
+ }
}