aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java1
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java30
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java18
3 files changed, 40 insertions, 9 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
index 7e22712b..0d59fd2f 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
@@ -25,6 +25,7 @@ public interface PolicyEndPointProperties {
/* Generic property suffixes */
String PROPERTY_TOPIC_SERVERS_SUFFIX = ".servers";
+ String PROPERTY_TOPIC_TOPICS_SUFFIX = ".topics";
String PROPERTY_TOPIC_API_KEY_SUFFIX = ".apiKey";
String PROPERTY_TOPIC_API_SECRET_SUFFIX = ".apiSecret";
String PROPERTY_TOPIC_AAF_MECHID_SUFFIX = ".aafMechId";
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
index 9e7c69a4..40ce8fa5 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/utils/ParameterUtils.java
@@ -25,6 +25,7 @@ import java.util.Properties;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
/**
* This is common utility class with utility methods for parameters.
@@ -54,24 +55,35 @@ public abstract class ParameterUtils {
// for each topicCommInfrastructure, there could be multiple topics (specified as comma separated string)
// for each such topics, there could be multiple servers (specified as comma separated string)
for (TopicParameters source : topicSources) {
- addTopicProperties(topicProperties, ".source.topics", source);
+ updateTopicProperties(topicProperties, "source", source.getTopicCommInfrastructure(), source.getTopic(),
+ source.getServers());
}
for (TopicParameters sink : topicSinks) {
- addTopicProperties(topicProperties, ".sink.topics", sink);
+ updateTopicProperties(topicProperties, "sink", sink.getTopicCommInfrastructure(), sink.getTopic(),
+ sink.getServers());
}
return topicProperties;
}
- private static void addTopicProperties(Properties topicProperties, String keyName, TopicParameters topicParameter) {
- String propKey = topicParameter.getTopicCommInfrastructure() + keyName;
+ /**
+ * Common method to update topic properties object using the parameters passed.
+ *
+ * @param topicProperties the topic properties object which is to be updated
+ * @param keyName either it is source or sink
+ * @param topicCommInfra the infra such as dmaap, ueb or noop
+ * @param topicName the topic
+ * @param servers the list of server names for the topic
+ */
+ public static void updateTopicProperties(Properties topicProperties, String keyName, String topicCommInfra,
+ String topicName, List<String> servers) {
+ String propKey = topicCommInfra + "." + keyName + PolicyEndPointProperties.PROPERTY_TOPIC_TOPICS_SUFFIX;
if (topicProperties.containsKey(propKey)) {
- topicProperties.setProperty(propKey,
- topicProperties.getProperty(propKey) + "," + topicParameter.getTopic());
+ topicProperties.setProperty(propKey, topicProperties.getProperty(propKey) + "," + topicName);
} else {
- topicProperties.setProperty(propKey, topicParameter.getTopic());
+ topicProperties.setProperty(propKey, topicName);
}
- topicProperties.setProperty(propKey + "." + topicParameter.getTopic() + ".servers",
- String.join(",", topicParameter.getServers()));
+ topicProperties.setProperty(propKey + "." + topicName + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX,
+ String.join(",", servers));
}
}
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
index e1c0dbcf..7e5c3a12 100644
--- 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
@@ -22,6 +22,7 @@ package org.onap.policy.common.endpoints.utils;
import static org.junit.Assert.assertEquals;
+import java.util.Arrays;
import java.util.Properties;
import org.junit.Test;
import org.onap.policy.common.endpoints.parameters.CommonTestData;
@@ -52,4 +53,21 @@ public class ParameterUtilsTest {
assertEquals(CommonTestData.TOPIC_SERVER, topicProperties
.getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + ".servers"));
}
+
+ @Test
+ public void testUpdateTopicProperties() {
+ Properties topicProperties = new Properties();
+ ParameterUtils.updateTopicProperties(topicProperties, "source", CommonTestData.TOPIC_INFRA,
+ CommonTestData.TOPIC_NAME, Arrays.asList(CommonTestData.TOPIC_SERVER));
+ assertEquals(CommonTestData.TOPIC_NAME,
+ topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".source.topics"));
+ assertEquals(CommonTestData.TOPIC_SERVER, topicProperties
+ .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + ".servers"));
+ ParameterUtils.updateTopicProperties(topicProperties, "sink", CommonTestData.TOPIC_INFRA,
+ CommonTestData.TOPIC_NAME, Arrays.asList(CommonTestData.TOPIC_SERVER));
+ assertEquals(CommonTestData.TOPIC_NAME,
+ topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics"));
+ assertEquals(CommonTestData.TOPIC_SERVER, topicProperties
+ .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + ".servers"));
+ }
}