aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-01-10 17:24:53 -0600
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2019-01-11 20:37:19 -0600
commit55f5c4dc9e130e48a25b048e1f3091b10c17e365 (patch)
tree2db4bf0af7a00a91f207137afff93e46ac8b2942 /policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
parent2fa29d8632a6dc9fb855a732320b679d724f384f (diff)
Adding NOOP sources support
In addition, Noop* classes have been refactored to increase code reuse and clean some checkstyle issues. Additional Junits have been added for existing functionality. Change-Id: I072f9ff2f415630ac82eca949a8360249f73da86 Issue-ID: POLICY-1397 Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java358
1 files changed, 358 insertions, 0 deletions
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
new file mode 100644
index 00000000..19dde432
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/TopicEndpointProxyTest.java
@@ -0,0 +1,358 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+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.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Properties;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicPropertyBuilder;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicPropertyBuilder;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+
+public class TopicEndpointProxyTest {
+
+ private static final String NOOP_SOURCE_TOPIC = "noop-source";
+ private static final String NOOP_SINK_TOPIC = "noop-sink";
+
+ private static final String UEB_SOURCE_TOPIC = "ueb-source";
+ private static final String UEB_SINK_TOPIC = "ueb-sink";
+
+ private static final String DMAAP_SOURCE_TOPIC = "dmaap-source";
+ private static final String DMAAP_SINK_TOPIC = "dmaap-sink";
+
+ private Properties configuration = new Properties();
+
+ /**
+ * Constructor.
+ */
+ public TopicEndpointProxyTest() {
+ Properties noopSourceProperties =
+ new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS)
+ .makeTopic(NOOP_SOURCE_TOPIC).build();
+
+ Properties noopSinkProperties =
+ new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS)
+ .makeTopic(NOOP_SINK_TOPIC).build();
+
+ Properties uebSourceProperties =
+ new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_UEB_SOURCE_TOPICS)
+ .makeTopic(UEB_SOURCE_TOPIC).build();
+
+ Properties uebSinkProperties =
+ new NoopTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_UEB_SINK_TOPICS)
+ .makeTopic(UEB_SINK_TOPIC).build();
+
+ Properties dmaapSourceProperties =
+ new DmaapTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_DMAAP_SOURCE_TOPICS)
+ .makeTopic(DMAAP_SOURCE_TOPIC).build();
+
+ Properties dmaapSinkProperties =
+ new DmaapTopicPropertyBuilder(PolicyEndPointProperties.PROPERTY_DMAAP_SINK_TOPICS)
+ .makeTopic(DMAAP_SINK_TOPIC).build();
+
+ configuration.putAll(noopSourceProperties);
+ configuration.putAll(noopSinkProperties);
+ configuration.putAll(uebSourceProperties);
+ configuration.putAll(uebSinkProperties);
+ configuration.putAll(dmaapSourceProperties);
+ configuration.putAll(dmaapSinkProperties);
+ }
+
+ private <T extends Topic> boolean exists(List<T> topics, String topicName) {
+ return topics.stream().map(Topic::getTopic).anyMatch(topicName::equals);
+ }
+
+ private <T extends Topic> boolean allSources(List<T> topics) {
+ return exists(topics, NOOP_SOURCE_TOPIC)
+ && exists(topics, UEB_SOURCE_TOPIC)
+ && exists(topics, DMAAP_SOURCE_TOPIC);
+ }
+
+ private <T extends Topic> boolean allSinks(List<T> topics) {
+ return exists(topics, NOOP_SINK_TOPIC)
+ && exists(topics, UEB_SINK_TOPIC)
+ && exists(topics, DMAAP_SINK_TOPIC);
+ }
+
+ private <T extends Topic> boolean anySource(List<T> topics) {
+ return exists(topics, NOOP_SOURCE_TOPIC)
+ || exists(topics, UEB_SOURCE_TOPIC)
+ || exists(topics, DMAAP_SOURCE_TOPIC);
+ }
+
+ private <T extends Topic> boolean anySink(List<T> topics) {
+ return exists(topics, NOOP_SINK_TOPIC)
+ || exists(topics, UEB_SINK_TOPIC)
+ || exists(topics, DMAAP_SINK_TOPIC);
+ }
+
+ @Test
+ public void addTopicSources() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ List<TopicSource> sources = manager.addTopicSources(configuration);
+ assertSame(3, sources.size());
+
+ assertTrue(allSources(sources));
+ assertFalse(anySink(sources));
+ }
+
+ @Test
+ public void addTopicSinks() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ List<TopicSink> sinks = manager.addTopicSinks(configuration);
+ assertSame(3, sinks.size());
+
+ assertFalse(anySource(sinks));
+ assertTrue(allSinks(sinks));
+ }
+
+ @Test
+ public void getTopicSources() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSources(configuration);
+ manager.addTopicSinks(configuration);
+
+ List<TopicSource> sources = manager.getTopicSources();
+ assertSame(3, sources.size());
+
+ assertTrue(allSources(sources));
+ assertFalse(anySink(sources));
+ }
+
+ @Test
+ public void getTopicSinks() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSources(configuration);
+ manager.addTopicSinks(configuration);
+
+ List<TopicSink> sinks = manager.getTopicSinks();
+ assertSame(3, sinks.size());
+
+ assertFalse(anySource(sinks));
+ assertTrue(allSinks(sinks));
+ }
+
+ @Test
+ public void getUebTopicSources() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSources(configuration);
+ assertSame(1, manager.getUebTopicSources().size());
+ }
+
+ @Test
+ public void getDmaapTopicSources() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSources(configuration);
+ assertSame(1, manager.getDmaapTopicSources().size());
+ }
+
+ @Test
+ public void getNoopTopicSources() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSources(configuration);
+ assertSame(1, manager.getNoopTopicSources().size());
+ }
+
+ @Test
+ public void getUebTopicSinks() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSinks(configuration);
+ assertSame(1, manager.getUebTopicSinks().size());
+ }
+
+ @Test
+ public void getDmaapTopicSinks() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSinks(configuration);
+ assertSame(1, manager.getDmaapTopicSinks().size());
+ }
+
+ @Test
+ public void getNoopTopicSinks() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.addTopicSinks(configuration);
+ assertSame(1, manager.getNoopTopicSinks().size());
+ }
+
+ @Test
+ public void lifecycle() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ assertTrue(manager.start());
+ assertTrue(manager.isAlive());
+
+ assertTrue(manager.stop());
+ assertFalse(manager.isAlive());
+
+ assertTrue(manager.start());
+ assertTrue(manager.isAlive());
+
+ manager.shutdown();
+ assertFalse(manager.isAlive());
+ }
+
+ @Test
+ public void lock() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+
+ manager.lock();
+ assertTrue(manager.isLocked());
+
+ manager.unlock();
+ assertFalse(manager.isLocked());
+ }
+
+ @Test
+ public void getTopicSource() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSources(configuration);
+
+ assertSame(NOOP_SOURCE_TOPIC, manager.getTopicSource(CommInfrastructure.NOOP, NOOP_SOURCE_TOPIC).getTopic());
+ assertSame(UEB_SOURCE_TOPIC, manager.getTopicSource(CommInfrastructure.UEB, UEB_SOURCE_TOPIC).getTopic());
+ assertSame(DMAAP_SOURCE_TOPIC, manager.getTopicSource(CommInfrastructure.DMAAP, DMAAP_SOURCE_TOPIC).getTopic());
+
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSource(CommInfrastructure.NOOP, NOOP_SINK_TOPIC));
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSource(CommInfrastructure.UEB, UEB_SINK_TOPIC));
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSource(CommInfrastructure.DMAAP, DMAAP_SINK_TOPIC));
+ }
+
+ @Test
+ public void getTopicSink() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSinks(configuration);
+
+ assertSame(NOOP_SINK_TOPIC, manager.getTopicSink(CommInfrastructure.NOOP, NOOP_SINK_TOPIC).getTopic());
+ assertSame(UEB_SINK_TOPIC, manager.getTopicSink(CommInfrastructure.UEB, UEB_SINK_TOPIC).getTopic());
+ assertSame(DMAAP_SINK_TOPIC, manager.getTopicSink(CommInfrastructure.DMAAP, DMAAP_SINK_TOPIC).getTopic());
+
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSink(CommInfrastructure.NOOP, NOOP_SOURCE_TOPIC));
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSink(CommInfrastructure.UEB, UEB_SOURCE_TOPIC));
+ assertThatIllegalStateException()
+ .isThrownBy(() -> manager.getTopicSink(CommInfrastructure.DMAAP, DMAAP_SOURCE_TOPIC));
+ }
+
+ @Test
+ public void getUebTopicSource() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSources(configuration);
+
+ assertSame(UEB_SOURCE_TOPIC, manager.getUebTopicSource(UEB_SOURCE_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getUebTopicSource(NOOP_SOURCE_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getUebTopicSource(DMAAP_SOURCE_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getUebTopicSource(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getUebTopicSource(""));
+ }
+
+ @Test
+ public void getUebTopicSink() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSinks(configuration);
+
+ assertSame(UEB_SINK_TOPIC, manager.getUebTopicSink(UEB_SINK_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getUebTopicSink(NOOP_SINK_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getUebTopicSink(DMAAP_SINK_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getUebTopicSink(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getUebTopicSink(""));
+ }
+
+ @Test
+ public void getDmaapTopicSource() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSources(configuration);
+
+ assertSame(DMAAP_SOURCE_TOPIC, manager.getDmaapTopicSource(DMAAP_SOURCE_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getDmaapTopicSource(NOOP_SOURCE_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getDmaapTopicSource(UEB_SOURCE_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getDmaapTopicSource(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getDmaapTopicSource(""));
+ }
+
+ @Test
+ public void getDmaapTopicSink() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSinks(configuration);
+
+ assertSame(DMAAP_SINK_TOPIC, manager.getDmaapTopicSink(DMAAP_SINK_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getDmaapTopicSink(NOOP_SINK_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getDmaapTopicSink(UEB_SINK_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getDmaapTopicSink(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getDmaapTopicSink(""));
+ }
+
+
+ @Test
+ public void getNoopTopicSource() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSources(configuration);
+
+ assertSame(NOOP_SOURCE_TOPIC, manager.getNoopTopicSource(NOOP_SOURCE_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getNoopTopicSource(DMAAP_SOURCE_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getNoopTopicSource(UEB_SOURCE_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getNoopTopicSource(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getNoopTopicSource(""));
+ }
+
+ @Test
+ public void getNoopTopicSink() {
+ TopicEndpoint manager = new TopicEndpointProxy();
+ manager.addTopicSinks(configuration);
+
+ assertSame(NOOP_SINK_TOPIC, manager.getNoopTopicSink(NOOP_SINK_TOPIC).getTopic());
+
+ assertThatIllegalStateException().isThrownBy(() -> manager.getNoopTopicSink(DMAAP_SINK_TOPIC));
+ assertThatIllegalStateException().isThrownBy(() -> manager.getNoopTopicSink(UEB_SINK_TOPIC));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getNoopTopicSink(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> manager.getNoopTopicSink(""));
+ }
+} \ No newline at end of file