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.
// 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));
}
}
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;
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"));
+ }
}