aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-07-25 15:58:58 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-07-25 15:58:58 +0000
commit208e75751007395086ac2f8dad6f5a280173eea1 (patch)
treeaf3e43fc77d13b41b3e54cf850593ab15b29c788 /policy-endpoints/src/test
parentf2b5c0111e65d1033157da0a1dc09dd3b681cce9 (diff)
Changes to add missing topic parameters
Changes to support parameters which would be critical to run in a secure environment. Change-Id: Ia7df174261041b35e57b9f1f2be7552e5dcd2cec Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'policy-endpoints/src/test')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java52
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json60
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json12
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json4
4 files changed, 126 insertions, 2 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
index db26a1a4..db200c80 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
@@ -27,6 +27,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Method;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.utils.coder.Coder;
@@ -77,6 +80,53 @@ public class TopicParameterGroupTest {
TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
final GroupValidationResult result = topicParameterGroup.validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains("parameter group has status INVALID"));
+ assertTrue(result.getResult().contains("INVALID"));
+ }
+
+ @Test
+ public void test_missing_mandatory_params() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json");
+ TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
+ final GroupValidationResult result = topicParameterGroup.validate();
+ assertTrue(result.getResult().contains("Mandatory parameters are missing"));
+ assertFalse(result.isValid());
+ }
+
+ @Test
+ public void test_allparams() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json");
+ TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
+ final GroupValidationResult result = topicParameterGroup.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ assertTrue(checkIfAllParamsNotEmpty(topicParameterGroup.getTopicSinks()));
+ assertTrue(checkIfAllParamsNotEmpty(topicParameterGroup.getTopicSources()));
+ }
+
+ /**
+ * Method to check if all parameters in TopicParameters are set.
+ * Any parameters added to @link TopicParameters or @link BusTopicParams must be added to
+ * TopicParameters_all_params.json.
+ *
+ * @param topicParameters topic parameters
+ * @return true if all parameters are not empty (if string) or true (if boolean)
+ * @throws Exception the exception
+ */
+ private boolean checkIfAllParamsNotEmpty(List<TopicParameters> topicParametersList) throws Exception {
+ for (TopicParameters topicParameters : topicParametersList) {
+ for (Method m : topicParameters.getClass().getMethods()) {
+ if (m.getName().startsWith("get") && m.getParameterTypes().length == 0) {
+ final Object parameter = m.invoke(topicParameters);
+ if ((parameter instanceof String && StringUtils.isBlank(parameter.toString()))
+ || (parameter instanceof Boolean && !(Boolean) parameter)
+ || (parameter instanceof Number && ((Number)parameter).longValue() == 0)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
}
}
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json
new file mode 100644
index 00000000..7d9cce7b
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_all_params.json
@@ -0,0 +1,60 @@
+{
+ "topicSources" : [ {
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap",
+ "effectiveTopic" : "my-effective-topic",
+ "apiKey" : "my-api-key",
+ "apiSecret" : "my-api-secret",
+ "port": 123,
+ "useHttps" : true,
+ "allowSelfSignedCerts" : true,
+ "consumerGroup" : "consumer group",
+ "consumerInstance" : "consumer instance",
+ "fetchTimeout" : 15000,
+ "fetchLimit" : 100,
+ "userName": "username",
+ "password": "password",
+ "managed": true,
+ "environment": "environment1",
+ "aftEnvironment": "aftEnvironment1",
+ "partner": "partner1",
+ "latitude": "1234",
+ "longitude": "1234",
+ "partitionId": "partition_id",
+ "additionalProps": {"xyz":"xyz"},
+ "clientName": "clientName1",
+ "hostname": "hostname1",
+ "basePath": "basePath1",
+ "serializationProvider": "serializationProvider1"
+ }],
+ "topicSinks" : [ {
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap",
+ "effectiveTopic" : "my-effective-topic",
+ "apiKey" : "my-api-key",
+ "apiSecret" : "my-api-secret",
+ "port": 123,
+ "useHttps" : true,
+ "allowSelfSignedCerts" : true,
+ "consumerGroup" : "consumer group",
+ "consumerInstance" : "consumer instance",
+ "fetchTimeout" : 15000,
+ "fetchLimit" : 100,
+ "userName": "username",
+ "password": "password",
+ "managed": true,
+ "environment": "environment1",
+ "aftEnvironment": "aftEnvironment1",
+ "partner": "partner1",
+ "latitude": "1234",
+ "longitude": "1234",
+ "partitionId": "partition_id",
+ "additionalProps": {"xyz":"xyz"},
+ "clientName": "clientName1",
+ "hostname": "hostname1",
+ "basePath": "basePath1",
+ "serializationProvider": "serializationProvider1"
+ }]
+} \ No newline at end of file
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json
new file mode 100644
index 00000000..157d6086
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_missing_mandatory.json
@@ -0,0 +1,12 @@
+{
+ "topicSources" : [ {
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [ {
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
+} \ No newline at end of file
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json
index 9222afa5..b89f1525 100644
--- a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json
@@ -23,6 +23,8 @@
},{
"topic" : "POLICY-PDP-PAP3",
"servers" : [ "message-router2, message-router3" ],
- "topicCommInfrastructure" : "dmaap"
+ "topicCommInfrastructure" : "dmaap",
+ "effectiveTopic":"effectiveTopic1",
+ "allowSelfSignedCerts":true
}]
} \ No newline at end of file