Add method to support configure all topics at once 29/82729/1
authorJorge Hernandez <jorge.hernandez-herrero@att.com>
Tue, 19 Mar 2019 21:10:37 +0000 (16:10 -0500)
committerJorge Hernandez <jorge.hernandez-herrero@att.com>
Tue, 19 Mar 2019 21:10:37 +0000 (16:10 -0500)
regardless of type (source or sink)

Change-Id: Idaebae611746e364364d35375519173a7461ae61
Issue-ID: POLICY-1608
Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpoint.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java

index 52c1f07..ff8b951 100644 (file)
@@ -42,6 +42,15 @@ public interface TopicEndpoint extends Startable, Lockable {
      */
     TopicEndpoint manager = new TopicEndpointProxy();
 
+    /**
+     * Add topics configuration (sources and sinks) into a single list.
+     *
+     * @param properties topic configuration
+     * @return topic list
+     * @throws IllegalArgumentException when invalid arguments are provided
+     */
+    List<Topic> addTopics(Properties properties);
+
     /**
      * Add Topic Sources to the communication infrastructure initialized per properties.
      *
index ebed381..806d077 100644 (file)
@@ -55,6 +55,13 @@ class TopicEndpointProxy implements TopicEndpoint {
      */
     private volatile boolean alive = false;
 
+    @Override
+    public List<Topic> addTopics(Properties properties) {
+        List<Topic> topics = new ArrayList<>(addTopicSources(properties));
+        topics.addAll(addTopicSinks(properties));
+        return topics;
+    }
+
     @Override
     public List<TopicSource> addTopicSources(Properties properties) {
 
index a311c0b..ba5fe18 100644 (file)
@@ -144,6 +144,17 @@ public class TopicEndpointProxyTest {
         assertTrue(allSinks(sinks));
     }
 
+    @Test
+    public void addTopics() {
+        TopicEndpoint manager = new TopicEndpointProxy();
+
+        List<Topic>  topics = manager.addTopics(configuration);
+        assertSame(6, topics.size());
+
+        assertTrue(allSources(topics));
+        assertTrue(allSinks(topics));
+    }
+
     @Test
     public void getTopicSources() {
         TopicEndpoint manager = new TopicEndpointProxy();