aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-06-26 10:52:28 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-06-26 10:52:28 +0000
commit115a58a8c55d9dd1230b7373686f7934d40b2629 (patch)
tree217341f196473e7fa2fbe5e19fbffe46a9db4d4b /policy-endpoints/src/test
parentd1ab0ec8471deeb7739206dc2ef0aac3dc5b245f (diff)
Adding Topic and REST parameters to policy-endpoints
1) Adding Topic parameters and REST parameters into policy-endpoints module as these are used by other modules such as PAP, APEX and XACML PDPs. 2) ParameterUtils class is also added which can contain related utility methods Change-Id: I5421fbf2234259305e3626ec0859aee0f36ed9b1 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/CommonTestData.java139
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java85
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java80
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java55
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json7
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json8
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json6
-rw-r--r--policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json28
8 files changed, 408 insertions, 0 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java
new file mode 100644
index 00000000..80d1e865
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.parameters;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CommonTestData {
+
+ public static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ public static final String REST_SERVER_USER = "healthcheck";
+ public static final int REST_SERVER_PORT = 6969;
+ public static final String REST_SERVER_HOST = "0.0.0.0";
+ public static final boolean REST_SERVER_HTTPS = true;
+ public static final boolean REST_SERVER_AAF = false;
+
+ public static final String TOPIC_NAME = "POLICY-PDP-PAP";
+ public static final String TOPIC_INFRA = "dmaap";
+ public static final String TOPIC_SERVER = "message-router";
+ public static final List<TopicParameters> TOPIC_PARAMS =
+ Arrays.asList(getTopicParameters(TOPIC_NAME, TOPIC_INFRA, TOPIC_SERVER));
+ public static final Coder coder = new StandardCoder();
+
+ /**
+ * Create topic parameters for test cases.
+ *
+ * @param topicName name of topic
+ * @param topicInfra topicCommInfrastructure
+ * @param topicServer topic server
+ *
+ * @return topic parameters
+ */
+ public static TopicParameters getTopicParameters(String topicName, String topicInfra, String topicServer) {
+ final TopicParameters topicParams = new TopicParameters();
+ topicParams.setTopic(topicName);
+ topicParams.setTopicCommInfrastructure(topicInfra);
+ topicParams.setServers(Arrays.asList(topicServer));
+ return topicParams;
+ }
+
+ /**
+ * Converts the contents of a map to a parameter class.
+ *
+ * @param source property map
+ * @param clazz class of object to be created from the map
+ * @return a new object represented by the map
+ */
+ public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+ try {
+ return coder.decode(coder.encode(source), clazz);
+
+ } catch (final CoderException e) {
+ throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
+ }
+ }
+
+ /**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("https", REST_SERVER_HTTPS);
+ map.put("aaf", REST_SERVER_AAF);
+
+ if (!isEmpty) {
+ map.put("host", REST_SERVER_HOST);
+ map.put("port", REST_SERVER_PORT);
+ map.put("userName", REST_SERVER_USER);
+ map.put("password", REST_SERVER_PASSWORD);
+ }
+
+ return map;
+ }
+
+ /**
+ * Returns a property map for a TopicParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getTopicParameterGroupMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("topicSources", TOPIC_PARAMS);
+ map.put("topicSinks", TOPIC_PARAMS);
+ }
+
+ return map;
+ }
+
+ /**
+ * Gets the standard parameter group as a String.
+ *
+ * @param filePath path of the file
+ * @return the standard parameters
+ * @throws IOException when file read operation fails
+ */
+ public String getParameterGroupAsString(String filePath) throws IOException {
+ File file = new File(filePath);
+ String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
+ return json;
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java
new file mode 100644
index 00000000..ca2b3c4c
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+/**
+ * Class to perform unit test of {@link RestServerParameters}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class RestServerParametersTest {
+
+ private static CommonTestData testData = new CommonTestData();
+ private static final Coder coder = new StandardCoder();
+
+ @Test
+ public void test() throws Exception {
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final GroupValidationResult validationResult = restServerParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(CommonTestData.REST_SERVER_HOST, restServerParameters.getHost());
+ assertEquals(CommonTestData.REST_SERVER_PORT, restServerParameters.getPort());
+ assertEquals(CommonTestData.REST_SERVER_USER, restServerParameters.getUserName());
+ assertEquals(CommonTestData.REST_SERVER_PASSWORD, restServerParameters.getPassword());
+ assertEquals(CommonTestData.REST_SERVER_HTTPS, restServerParameters.isHttps());
+ assertEquals(CommonTestData.REST_SERVER_AAF, restServerParameters.isAaf());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final GroupValidationResult result = restServerParameters.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void test_valid() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json");
+ RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
+ final GroupValidationResult result = restServerParameters.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void test_invalid() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json");
+ RestServerParameters restServerParameters = coder.decode(json, RestServerParameters.class);
+ final GroupValidationResult result = restServerParameters.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("parameter group has status INVALID"));
+ }
+}
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
new file mode 100644
index 00000000..eaf0b2a9
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+/**
+ * Class to perform unit test of {@link TopicParameterGroup}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class TopicParameterGroupTest {
+ private static CommonTestData testData = new CommonTestData();
+ private static final Coder coder = new StandardCoder();
+
+ @Test
+ public void test() throws Exception {
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
+ final GroupValidationResult validationResult = topicParameterGroup.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
+ final GroupValidationResult result = topicParameterGroup.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void test_valid() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json");
+ TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
+ final GroupValidationResult result = topicParameterGroup.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void test_invalid() throws Exception {
+ String json = testData.getParameterGroupAsString(
+ "src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json");
+ TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
+ final GroupValidationResult result = topicParameterGroup.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("parameter group has status INVALID"));
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java
new file mode 100644
index 00000000..e1c0dbcf
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Properties;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.parameters.CommonTestData;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
+
+/**
+ * Class to perform unit test of {@link ParameterUtils}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ParameterUtilsTest {
+
+ /**
+ * Test getTopicProperties from TopicParameterGroup.
+ */
+ @Test
+ public void testGetTopicProperties() {
+ CommonTestData testData = new CommonTestData();
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
+ Properties topicProperties = ParameterUtils.getTopicProperties(topicParameterGroup);
+ assertEquals(CommonTestData.TOPIC_NAME,
+ topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".source.topics"));
+ assertEquals(CommonTestData.TOPIC_NAME,
+ topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics"));
+ assertEquals(CommonTestData.TOPIC_SERVER, topicProperties
+ .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + ".servers"));
+ assertEquals(CommonTestData.TOPIC_SERVER, topicProperties
+ .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + ".servers"));
+ }
+}
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json
new file mode 100644
index 00000000..b106d721
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_invalid.json
@@ -0,0 +1,7 @@
+{
+ "port": 6969,
+ "userName": "username",
+ "password": "password",
+ "https": true,
+ "aaf": false
+} \ No newline at end of file
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json
new file mode 100644
index 00000000..6c113056
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/RestServerParameters_valid.json
@@ -0,0 +1,8 @@
+{
+ "host": "0.0.0.0",
+ "port": 6969,
+ "userName": "username",
+ "password": "password",
+ "https": true,
+ "aaf": false
+} \ No newline at end of file
diff --git a/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json
new file mode 100644
index 00000000..775b4886
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_invalid.json
@@ -0,0 +1,6 @@
+{
+ "topicSources" : [{
+ "topic" : "ueb-source",
+ "servers" : ["my-server"]
+ }]
+} \ 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
new file mode 100644
index 00000000..9222afa5
--- /dev/null
+++ b/policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/parameters/TopicParameters_valid.json
@@ -0,0 +1,28 @@
+{
+ "topicSources" : [ {
+ "topic" : "ueb-source",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [ {
+ "topic" : "ueb-sink",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP3",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
+} \ No newline at end of file