From 63d5702986d5dc63eb3d0ed2e3b57ce3b529966f Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 30 Jul 2019 09:53:19 -0400 Subject: Fix managed noop topic source NOOP topic sources configured via TopicParameterGroup are left unmanaged. Removed a new override method, as it did not pass the "managed" flag down, while the method that already existed in the superclass already works correctly. Also restored "null" lists to TopicParameterGroup so-as not to break the behavior of its validate() method. Change-Id: Id392a3263c3bd1c8f278461715b441719817c47c Issue-ID: POLICY-1953 Signed-off-by: Jim Hahn --- .../common/endpoints/event/comm/TopicEndpointProxy.java | 12 +++++++++--- .../endpoints/event/comm/bus/NoopTopicSourceFactory.java | 9 --------- .../common/endpoints/parameters/TopicParameterGroup.java | 5 ++--- .../common/endpoints/event/comm/TopicEndpointProxyTest.java | 13 +++++++++++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java index c9e73152..9aabad52 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxy.java @@ -22,6 +22,7 @@ package org.onap.policy.common.endpoints.event.comm; import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; import org.onap.policy.common.capabilities.Startable; @@ -69,9 +70,14 @@ class TopicEndpointProxy implements TopicEndpoint { @Override public List addTopics(TopicParameterGroup params) { - List topics = new ArrayList<>(params.getTopicSinks().size() + params.getTopicSources().size()); - topics.addAll(addTopicSources(params.getTopicSources())); - topics.addAll(addTopicSinks(params.getTopicSinks())); + List sinks = + (params.getTopicSinks() != null ? params.getTopicSinks() : Collections.emptyList()); + List sources = + (params.getTopicSources() != null ? params.getTopicSources() : Collections.emptyList()); + + List topics = new ArrayList<>(sinks.size() + sources.size()); + topics.addAll(addTopicSources(sources)); + topics.addAll(addTopicSinks(sinks)); return topics; } diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactory.java index 7164f919..ca5e41d3 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicSourceFactory.java @@ -21,7 +21,6 @@ package org.onap.policy.common.endpoints.event.comm.bus; import java.util.List; -import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; /** @@ -37,14 +36,6 @@ public class NoopTopicSourceFactory extends NoopTopicFactory { return PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS; } - /** - * {@inheritDoc}. - */ - @Override - public NoopTopicSource build(BusTopicParams param) { - return build(param.getServers(), param.getTopic()); - } - /** * {@inheritDoc}. */ diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java index eab9c12f..4cd3893d 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroup.java @@ -21,7 +21,6 @@ package org.onap.policy.common.endpoints.parameters; -import java.util.LinkedList; import java.util.List; import lombok.Getter; import lombok.Setter; @@ -43,8 +42,8 @@ import org.onap.policy.common.parameters.annotations.NotNull; @Setter public class TopicParameterGroup extends ParameterGroupImpl { - private final List topicSources = new LinkedList<>(); - private final List topicSinks = new LinkedList<>(); + private List topicSources; + private List topicSinks; public TopicParameterGroup() { super(TopicParameterGroup.class.getSimpleName()); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java index 22ddecd1..fa432265 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java @@ -22,10 +22,12 @@ package org.onap.policy.common.endpoints.event.comm; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.util.LinkedList; import java.util.List; import java.util.Properties; import org.junit.After; @@ -60,6 +62,9 @@ public class TopicEndpointProxyTest { * Constructor. */ public TopicEndpointProxyTest() { + group.setTopicSinks(new LinkedList<>()); + group.setTopicSources(new LinkedList<>()); + NoopTopicPropertyBuilder noopSourceBuilder = new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS) .makeTopic(NOOP_SOURCE_TOPIC); @@ -223,6 +228,14 @@ public class TopicEndpointProxyTest { assertTrue(allSinks(topics)); } + @Test + public void addTopicsTopicParameterGroupNull() { + TopicEndpoint manager = new TopicEndpointProxy(); + + List topics = manager.addTopics(new TopicParameterGroup()); + assertEquals(0, topics.size()); + } + @Test public void lockSinks_lockSources_locked() { TopicEndpoint manager = new TopicEndpointProxy(); -- cgit 1.2.3-korg