diff options
author | a.sreekumar <ajith.sreekumar@est.tech> | 2019-07-05 13:00:35 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@est.tech> | 2019-07-05 13:00:35 +0000 |
commit | c5231f939d724dd59cb385d8521924a1bff19cee (patch) | |
tree | bed6d13d5986b0cd5f3b8d0fcea8b7010d951340 /models-sim/policy-models-sim-pdp/src/test/java/org | |
parent | b359a4b56b4527b3215b89e7d637da9fbcb022af (diff) |
Remove topic.properties and incorporate into overall config file for pdp-simulator
Change-Id: Iac882c7ffb28a80ef474d15a90307cd68b78d417
Issue-ID: POLICY-1744
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'models-sim/policy-models-sim-pdp/src/test/java/org')
6 files changed, 62 insertions, 28 deletions
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorActivator.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorActivator.java index e75bb6d26..dbf7bbcea 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorActivator.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorActivator.java @@ -33,6 +33,7 @@ import java.util.Properties; import org.junit.After; import org.junit.Before; import org.junit.Test; +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.sim.pdp.exception.PdpSimulatorException; @@ -57,18 +58,12 @@ public class TestPdpSimulatorActivator { @Before public void setUp() throws Exception { Registry.newRegistry(); - final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json", - "-p", "src/test/resources/topic.properties" }; + final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" }; final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments(pdpSimulatorConfigParameters); final PdpSimulatorParameterGroup parGroup = new PdpSimulatorParameterHandler().getParameters(arguments); - final Properties props = new Properties(); - final String propFile = arguments.getFullPropertyFilePath(); - try (FileInputStream stream = new FileInputStream(propFile)) { - props.load(stream); - } - + final Properties props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup()); activator = new PdpSimulatorActivator(parGroup, props); } diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorMain.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorMain.java index 7a3239891..4b7944436 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorMain.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorMain.java @@ -64,8 +64,7 @@ public class TestPdpSimulatorMain { @Test public void testPdpSimulator() throws PdpSimulatorException { - final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json", - "-p", "src/test/resources/topic.properties" }; + final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" }; pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters); assertTrue(pdpSimulator.getParameters().isValid()); assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulator.getParameters().getName()); diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java index 324edd7c5..2b3704738 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java @@ -23,7 +23,6 @@ package org.onap.policy.models.sim.pdp.comm; import static org.junit.Assert.assertEquals; -import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -37,6 +36,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; 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; @@ -73,8 +73,7 @@ public class TestPdpStateChangeListener { pdpUpdateMessageListener = new PdpUpdateListener(); pdpStateChangeListener = new PdpStateChangeListener(); Registry.newRegistry(); - final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json", - "-p", "src/test/resources/topic.properties" }; + final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" }; final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments(); PdpSimulatorParameterGroup pdpSimulatorParameterGroup; // The arguments return a string if there is a message to print and we should @@ -90,11 +89,8 @@ public class TestPdpStateChangeListener { pdpSimulatorParameterGroup = new PdpSimulatorParameterHandler().getParameters(arguments); // Read the properties - final Properties topicProperties = new Properties(); - final String propFile = arguments.getFullPropertyFilePath(); - try (FileInputStream stream = new FileInputStream(propFile)) { - topicProperties.load(stream); - } + final Properties topicProperties = + ParameterUtils.getTopicProperties(pdpSimulatorParameterGroup.getTopicParameterGroup()); activator = new PdpSimulatorActivator(pdpSimulatorParameterGroup, topicProperties); Registry.register(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, activator); activator.initialize(); diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java index e5eebf066..9ae8d370a 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java @@ -23,7 +23,6 @@ package org.onap.policy.models.sim.pdp.comm; import static org.junit.Assert.assertEquals; -import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -37,6 +36,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; 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; @@ -67,8 +67,7 @@ public class TestPdpUpdateListener { @Before public void setUp() throws Exception { Registry.newRegistry(); - final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json", - "-p", "src/test/resources/topic.properties" }; + final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" }; final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments(); PdpSimulatorParameterGroup pdpSimulatorParameterGroup; // The arguments return a string if there is a message to print and we should @@ -84,11 +83,8 @@ public class TestPdpUpdateListener { pdpSimulatorParameterGroup = new PdpSimulatorParameterHandler().getParameters(arguments); // Read the properties - final Properties topicProperties = new Properties(); - final String propFile = arguments.getFullPropertyFilePath(); - try (FileInputStream stream = new FileInputStream(propFile)) { - topicProperties.load(stream); - } + final Properties topicProperties = + ParameterUtils.getTopicProperties(pdpSimulatorParameterGroup.getTopicParameterGroup()); activator = new PdpSimulatorActivator(pdpSimulatorParameterGroup, topicProperties); Registry.register(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, activator); activator.initialize(); diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java index e0da3d805..123aa4444 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java @@ -25,7 +25,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; @@ -48,6 +48,7 @@ public class CommonTestData { public static final String POLICY_VERSION = "0.0.1"; protected 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_PASS = "zb!XztG34"; private static final String REST_SERVER_USER = "healthcheck"; private static final int REST_SERVER_PORT = 6969; @@ -70,6 +71,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 @@ -98,7 +112,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; } @@ -142,4 +156,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/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterGroup.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterGroup.java index b4a54b8ae..df24f3eb9 100644 --- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterGroup.java +++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterGroup.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.Test; +import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; import org.onap.policy.common.parameters.GroupValidationResult; /** @@ -49,6 +50,7 @@ public class TestPdpSimulatorParameterGroup { commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME), PdpSimulatorParameterGroup.class); final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters(); + final TopicParameterGroup topicParameterGroup = pdpSimulatorParameters.getTopicParameterGroup(); final GroupValidationResult validationResult = pdpSimulatorParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName()); @@ -56,6 +58,8 @@ public class TestPdpSimulatorParameterGroup { 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()); } @Test @@ -104,4 +108,19 @@ public class TestPdpSimulatorParameterGroup { + "parameter group has status INVALID")); } + @Test + public void testApexStarterParameterGroupp_EmptyTopicParameters() { + final Map<String, Object> map = + commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME); + map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true)); + + final PdpSimulatorParameterGroup parGroup = + commonTestData.toObject(map, PdpSimulatorParameterGroup.class); + final GroupValidationResult validationResult = parGroup.validate(); + assertFalse(validationResult.isValid()); + assertTrue(validationResult.getResult() + .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, " + + "parameter group has status INVALID")); + } + } |