summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/test/java
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-06-28 11:36:58 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-06-28 11:36:58 +0000
commit037e421b700ba836e053fdc58101104a0b6ccb0e (patch)
treeda5525ed70e0c033bf8a2d0f29a209979782bac8 /services/services-onappf/src/test/java
parentd139a68e359bfaa0e1ea1038345dd28e1869aca9 (diff)
Remove topic.properties and incorporate into overall properties
1) The properties in the topic.properties file is moved into overall config json file and the topic.properties file is removed. 2) Common parameters such as RestServer and Topic related parameters from policy-common is used. Change-Id: Ifc25185c8f717c95a226b2db25c1a8e96b9bbff9 Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services/services-onappf/src/test/java')
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java15
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java3
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java17
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java17
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java33
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java23
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java7
7 files changed, 71 insertions, 44 deletions
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
index 238a89f66..e4dd3d92d 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.FileInputStream;
import java.util.Properties;
import org.junit.After;
@@ -40,6 +39,7 @@ import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -60,19 +60,12 @@ public class TestApexStarterActivator {
@Before
public void setUp() throws Exception {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json"};
final ApexStarterCommandLineArguments arguments =
new ApexStarterCommandLineArguments(apexStarterConfigParameters);
final ApexStarterParameterGroup parGroup = new ApexStarterParameterHandler().getParameters(arguments);
-
- final Properties props = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- props.load(stream);
- }
-
- activator = new ApexStarterActivator(parGroup, props);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parGroup, topicProperties);
}
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
index 31c994cda..68d30258b 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
@@ -67,8 +67,7 @@ public class TestApexStarterMain {
@Test
public void testApexStarter() throws ApexStarterException {
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json"};
apexStarter = new ApexStarterMain(apexStarterConfigParameters);
assertTrue(apexStarter.getParameters().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index c6ed44556..fc7bd8fb2 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -22,7 +22,6 @@ package org.onap.policy.apex.services.onappf.comm;
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -44,6 +43,7 @@ import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -75,10 +75,9 @@ public class TestPdpStateChangeListener {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- ApexStarterParameterGroup apexStarterParameterGroup;
+ ApexStarterParameterGroup parameterGroup;
// The arguments return a string if there is a message to print and we should
// exit
final String argumentMessage = arguments.parse(apexStarterConfigParameters);
@@ -89,15 +88,11 @@ public class TestPdpStateChangeListener {
arguments.validate();
// Read the parameters
- apexStarterParameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
+ parameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
- activator = new ApexStarterActivator(apexStarterParameterGroup, topicProperties);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parameterGroup, topicProperties);
Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator);
activator.initialize();
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index ebe0fc957..98ca3eb59 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -22,7 +22,6 @@ package org.onap.policy.apex.services.onappf.comm;
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -45,6 +44,7 @@ import org.onap.policy.apex.services.onappf.handler.PdpMessageHandler;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
@@ -71,10 +71,9 @@ public class TestPdpUpdateListener {
@Before
public void setUp() throws ApexStarterException, FileNotFoundException, IOException {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- ApexStarterParameterGroup apexStarterParameterGroup;
+ ApexStarterParameterGroup parameterGroup;
// The arguments return a string if there is a message to print and we should
// exit
final String argumentMessage = arguments.parse(apexStarterConfigParameters);
@@ -85,15 +84,11 @@ public class TestPdpUpdateListener {
arguments.validate();
// Read the parameters
- apexStarterParameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
+ parameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
- activator = new ApexStarterActivator(apexStarterParameterGroup, topicProperties);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parameterGroup, topicProperties);
Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator);
activator.initialize();
pdpUpdateMessageListener = new PdpUpdateListener();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
index 7e668e9b2..c8d61f539 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
@@ -24,7 +24,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -47,6 +47,7 @@ public class CommonTestData {
public static final String POLICY_VERSION = "0.0.1";
public static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
+ public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
private static final String REST_SERVER_PASSWORD = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
@@ -69,6 +70,19 @@ public class CommonTestData {
}
/**
+ * Returns topic parameters for test cases.
+ *
+ * @return topic parameters
+ */
+ public static TopicParameters getTopicParams() {
+ final TopicParameters topicParams = new TopicParameters();
+ topicParams.setTopic("POLICY-PDP-PAP");
+ topicParams.setTopicCommInfrastructure("dmaap");
+ topicParams.setServers(Arrays.asList("message-router"));
+ return topicParams;
+ }
+
+ /**
* Converts the contents of a map to a parameter class.
*
* @param source property map
@@ -97,7 +111,7 @@ public class CommonTestData {
map.put("name", name);
map.put("restServerParameters", getRestServerParametersMap(false));
map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
-
+ map.put("topicParameterGroup", getTopicParametersMap(false));
return map;
}
@@ -141,4 +155,19 @@ public class CommonTestData {
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> getTopicParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("topicSources", TOPIC_PARAMS);
+ map.put("topicSinks", TOPIC_PARAMS);
+ }
+ return map;
+ }
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
index dd9e83f52..e96b136a0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
@@ -27,6 +27,8 @@ import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
/**
@@ -50,6 +52,7 @@ public class TestApexStarterParameterGroup {
ApexStarterParameterGroup.class);
final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
+ final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
@@ -57,6 +60,8 @@ public class TestApexStarterParameterGroup {
assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
assertEquals(restServerParameters.getHost(), apexStarterParameters.getRestServerParameters().getHost());
assertEquals(restServerParameters.getPort(), apexStarterParameters.getRestServerParameters().getPort());
assertEquals(restServerParameters.getUserName(), apexStarterParameters.getRestServerParameters().getUserName());
@@ -122,7 +127,23 @@ public class TestApexStarterParameterGroup {
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.apex.services.onappf.parameters.RestServerParameters\" INVALID, "
+ .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+
+
+ @Test
+ public void testApexStarterParameterGroupp_EmptyTopicParameters() {
+ final Map<String, Object> map =
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
+
+ final ApexStarterParameterGroup apexStarterParameters =
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ final GroupValidationResult validationResult = apexStarterParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
+ "parameter group has status INVALID"));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
index 72db6e091..006cad0b9 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
@@ -186,12 +186,7 @@ public class CommonApexStarterRestServer {
systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
System.setProperties(systemProps);
- // @formatter:off
- final String[] apexStarterConfigParameters = {
- "-c", "src/test/resources/TestConfigParams.json",
- "-p", "src/test/resources/topic.properties"
- };
- // @formatter:on
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/TestConfigParams.json" };
main = new ApexStarterMain(apexStarterConfigParameters);