diff options
6 files changed, 873 insertions, 0 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java new file mode 100644 index 00000000..69ad43d9 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java @@ -0,0 +1,224 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; + +public class InlineBusTopicSinkTest extends BusTopicTestBase { + + private InlineBusTopicSinkImpl sink; + + /** + * Creates the object to be tested. + */ + @Before + public void setUp() { + super.setUp(); + + sink = new InlineBusTopicSinkImpl(makeBuilder().build()); + } + + @After + public void tearDown() { + sink.shutdown(); + } + + @Test + public void testInlineBusTopicSinkImpl() { + // verify that different wrappers can be built + sink = new InlineBusTopicSinkImpl(makeBuilder().build()); + assertEquals(MY_PARTITION, sink.getPartitionKey()); + + sink = new InlineBusTopicSinkImpl(makeBuilder().partitionId(null).build()); + assertNotNull(sink.getPartitionKey()); + } + + @Test + public void testStart() { + assertTrue(sink.start()); + assertEquals(1, sink.initCount); + + // re-start, init() should not be invoked again + assertTrue(sink.start()); + assertEquals(1, sink.initCount); + } + + @Test(expected = IllegalStateException.class) + public void testStart_Locked() { + sink.lock(); + sink.start(); + } + + @Test + public void testStop() { + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + assertTrue(sink.stop()); + verify(pub).close(); + + // stop again, shouldn't not invoke close() again + assertFalse(sink.stop()); + verify(pub).close(); + + // publisher throws exception + sink = new InlineBusTopicSinkImpl(makeBuilder().build()); + sink.publisher = pub; + doThrow(new RuntimeException(EXPECTED)).when(pub).close(); + assertTrue(sink.stop()); + } + + @Test + public void testSend() { + sink.start(); + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + TopicListener listener = mock(TopicListener.class); + sink.register(listener); + + assertTrue(sink.send(MY_MESSAGE)); + + verify(pub).send(MY_PARTITION, MY_MESSAGE); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE); + assertEquals(Arrays.asList(MY_MESSAGE), Arrays.asList(sink.getRecentEvents())); + + // arrange for send to throw an exception + when(pub.send(anyString(), anyString())).thenThrow(new RuntimeException(EXPECTED)); + + assertFalse(sink.send(MY_MESSAGE)); + + // no more event deliveries + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE); + } + + @Test(expected = IllegalArgumentException.class) + public void testSend_NullMessage() { + sink.start(); + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + sink.send(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSend_EmptyMessage() { + sink.start(); + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + sink.send(""); + } + + @Test(expected = IllegalStateException.class) + public void testSend_NotStarted() { + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + sink.send(MY_MESSAGE); + } + + @Test + public void testSetPartitionKey_getPartitionKey() { + assertEquals(MY_PARTITION, sink.getPartitionKey()); + + sink.setPartitionKey("part-B"); + assertEquals("part-B", sink.getPartitionKey()); + } + + @Test + public void testShutdown() { + BusPublisher pub = mock(BusPublisher.class); + sink.publisher = pub; + + sink.shutdown(); + verify(pub).close(); + } + + @Test + public void testAnyNullOrEmpty() { + assertFalse(sink.anyNullOrEmpty()); + assertFalse(sink.anyNullOrEmpty("any-none-null", "any-none-null-B")); + + assertTrue(sink.anyNullOrEmpty(null, "any-first-null")); + assertTrue(sink.anyNullOrEmpty("any-middle-null", null, "any-middle-null-B")); + assertTrue(sink.anyNullOrEmpty("any-last-null", null)); + assertTrue(sink.anyNullOrEmpty("any-empty", "")); + } + + @Test + public void testAllNullOrEmpty() { + assertTrue(sink.allNullOrEmpty()); + assertTrue(sink.allNullOrEmpty("")); + assertTrue(sink.allNullOrEmpty(null, "")); + + assertFalse(sink.allNullOrEmpty("all-ok-only-one")); + assertFalse(sink.allNullOrEmpty("all-ok-one", "all-ok-two")); + assertFalse(sink.allNullOrEmpty("all-ok-null", null)); + assertFalse(sink.allNullOrEmpty("", "all-ok-empty")); + assertFalse(sink.allNullOrEmpty("", "all-one-ok", null)); + } + + @Test + public void testToString() { + assertTrue(sink.toString().startsWith("InlineBusTopicSink [")); + } + + /** + * Implementation of InlineBusTopicSink that tracks the number of times that init() is + * invoked. + */ + private static class InlineBusTopicSinkImpl extends InlineBusTopicSink { + + private int initCount = 0; + + public InlineBusTopicSinkImpl(BusTopicParams busTopicParams) { + super(busTopicParams); + } + + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return CommInfrastructure.NOOP; + } + + @Override + public void init() { + ++initCount; + } + + } +} diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java new file mode 100644 index 00000000..2f02a7b7 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; + +public class InlineDmaapTopicSinkTest extends BusTopicTestBase { + private InlineDmaapTopicSink sink; + + /** + * Creates the object to be tested. + */ + @Before + public void setUp() { + super.setUp(); + + sink = new InlineDmaapTopicSink(makeBuilder().build()); + } + + @After + public void tearDown() { + sink.shutdown(); + } + + @Test + public void testToString() { + assertTrue(sink.toString().startsWith("InlineDmaapTopicSink [")); + } + + @Test + public void testInit() { + // nothing null + sink = new InlineDmaapTopicSink(makeBuilder().build()); + sink.init(); + sink.shutdown(); + + // no DME2 info + sink = new InlineDmaapTopicSink(makeBuilder().environment(null).aftEnvironment(null).latitude(null) + .longitude(null).partner(null).build()); + sink.init(); + sink.shutdown(); + } + + @Test + public void testGetTopicCommInfrastructure() { + assertEquals(CommInfrastructure.DMAAP, sink.getTopicCommInfrastructure()); + } + +} diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java new file mode 100644 index 00000000..02714d7c --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; + +public class InlineUebTopicSinkTest extends BusTopicTestBase { + private InlineUebTopicSink sink; + + /** + * Creates the object to be tested. + */ + @Before + public void setUp() { + super.setUp(); + + sink = new InlineUebTopicSink(makeBuilder().build()); + } + + @After + public void tearDown() { + sink.shutdown(); + } + + @Test + public void testToString() { + assertTrue(sink.toString().startsWith("InlineUebTopicSink [")); + } + + @Test + public void testInit() { + sink.init(); + } + + @Test + public void testGetTopicCommInfrastructure() { + assertEquals(CommInfrastructure.UEB, sink.getTopicCommInfrastructure()); + } + +} diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java new file mode 100644 index 00000000..eaeafef6 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java @@ -0,0 +1,359 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.Collections; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusConsumer.FilterableBusConsumer; + +public class SingleThreadedBusTopicSourceTest extends BusTopicTestBase { + private Thread thread; + private BusConsumer cons; + private TopicListener listener; + private SingleThreadedBusTopicSourceImpl source; + + /** + * Creates the object to be tested, as well as various mocks. + */ + @Before + public void setUp() { + super.setUp(); + + thread = mock(Thread.class); + cons = mock(BusConsumer.class); + listener = mock(TopicListener.class); + source = new SingleThreadedBusTopicSourceImpl(makeBuilder().build()); + } + + @After + public void tearDown() { + source.shutdown(); + } + + @Test + public void testRegister() { + source.register(listener); + assertEquals(1, source.initCount); + source.offer(MY_MESSAGE); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE); + + // register another - should not re-init + TopicListener listener2 = mock(TopicListener.class); + source.register(listener2); + assertEquals(1, source.initCount); + source.offer(MY_MESSAGE + "z"); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE + "z"); + verify(listener2).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE + "z"); + + // re-register - should not re-init + source.register(listener); + assertEquals(1, source.initCount); + source.offer(MY_MESSAGE2); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE2); + + // lock & register - should not init + source = new SingleThreadedBusTopicSourceImpl(makeBuilder().build()); + source.lock(); + source.register(listener); + assertEquals(0, source.initCount); + + // exception during init + source = new SingleThreadedBusTopicSourceImpl(makeBuilder().build()); + source.initEx = true; + source.register(listener); + } + + @Test + public void testUnregister() { + TopicListener listener2 = mock(TopicListener.class); + source.register(listener); + source.register(listener2); + + // unregister first listener - should NOT invoke close + source.unregister(listener); + verify(cons, never()).close(); + assertEquals(Arrays.asList(listener2), source.snapshotTopicListeners()); + + // unregister same listener - should not invoke close + source.unregister(listener); + verify(cons, never()).close(); + assertEquals(Arrays.asList(listener2), source.snapshotTopicListeners()); + + // unregister second listener - SHOULD invoke close + source.unregister(listener2); + verify(cons).close(); + assertTrue(source.snapshotTopicListeners().isEmpty()); + + // unregister same listener - should not invoke close again + source.unregister(listener2); + verify(cons).close(); + assertTrue(source.snapshotTopicListeners().isEmpty()); + } + + @Test + public void testToString() { + assertTrue(source.toString().startsWith("SingleThreadedBusTopicSource [")); + } + + @Test + public void testMakePollerThread() { + SingleThreadedBusTopicSource source2 = new SingleThreadedBusTopicSource(makeBuilder().build()) { + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return CommInfrastructure.NOOP; + } + + @Override + public void init() throws MalformedURLException { + // do nothing + } + }; + + assertNotNull(source2.makePollerThread()); + } + + @Test + public void testSingleThreadedBusTopicSource() { + // verify that different wrappers can be built + new SingleThreadedBusTopicSourceImpl(makeBuilder().consumerGroup(null).build()); + new SingleThreadedBusTopicSourceImpl(makeBuilder().consumerInstance(null).build()); + new SingleThreadedBusTopicSourceImpl(makeBuilder().fetchTimeout(-1).build()); + new SingleThreadedBusTopicSourceImpl(makeBuilder().fetchLimit(-1).build()); + } + + @Test + public void testStart() { + source.start(); + assertTrue(source.isAlive()); + assertEquals(1, source.initCount); + verify(thread).start(); + + // attempt to start again - nothing should be invoked again + source.start(); + assertTrue(source.isAlive()); + assertEquals(1, source.initCount); + verify(thread).start(); + + // stop & re-start + source.stop(); + source.start(); + assertTrue(source.isAlive()); + assertEquals(2, source.initCount); + verify(thread, times(2)).start(); + } + + @Test(expected = IllegalStateException.class) + public void testStart_Locked() { + source.lock(); + source.start(); + } + + @Test(expected = IllegalStateException.class) + public void testStart_InitEx() { + source.initEx = true; + source.start(); + } + + @Test + public void testStop() { + source.start(); + source.stop(); + verify(cons).close(); + + // stop it again - not re-closed + source.stop(); + verify(cons).close(); + + // start & stop again, but with an exception + doThrow(new RuntimeException(EXPECTED)).when(cons).close(); + source.start(); + source.stop(); + } + + @Test + public void testRun() throws Exception { + source.register(listener); + + /* + * Die in the middle of fetching messages. Also, throw an exception during the + * first fetch attempt. + */ + when(cons.fetch()).thenAnswer(new Answer<Iterable<String>>() { + int count = 0; + + @Override + public Iterable<String> answer(InvocationOnMock invocation) throws Throwable { + if (++count > 1) { + source.alive = false; + return Arrays.asList(MY_MESSAGE, MY_MESSAGE2); + + } else { + throw new IOException(EXPECTED); + } + } + }); + source.alive = true; + source.run(); + assertEquals(Arrays.asList(MY_MESSAGE), Arrays.asList(source.getRecentEvents())); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE); + verify(listener, never()).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE2); + + /* + * Die AFTER fetching messages. + */ + final String msga = "message-A"; + final String msgb = "message-B"; + when(cons.fetch()).thenAnswer(new Answer<Iterable<String>>() { + int count = 0; + + @Override + public Iterable<String> answer(InvocationOnMock invocation) throws Throwable { + if (++count > 1) { + source.alive = false; + return Collections.emptyList(); + + } else { + return Arrays.asList(msga, msgb); + } + } + }); + source.alive = true; + source.run(); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, msga); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, msgb); + + assertEquals(Arrays.asList(MY_MESSAGE, msga, msgb), Arrays.asList(source.getRecentEvents())); + } + + @Test + public void testOffer() { + source.register(listener); + source.offer(MY_MESSAGE); + verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE); + assertEquals(Arrays.asList(MY_MESSAGE), Arrays.asList(source.getRecentEvents())); + } + + @Test(expected = IllegalStateException.class) + public void testOffer_NotStarted() { + source.offer(MY_MESSAGE); + } + + @Test + public void testSetFilter() { + FilterableBusConsumer filt = mock(FilterableBusConsumer.class); + cons = filt; + + source.start(); + source.setFilter("my-filter"); + verify(filt).setFilter("my-filter"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testSetFilter_Unsupported() { + source.start(); + source.setFilter("unsupported-filter"); + } + + @Test + public void testGetConsumerGroup() { + assertEquals(MY_CONS_GROUP, source.getConsumerGroup()); + } + + @Test + public void testGetConsumerInstance() { + assertEquals(MY_CONS_INST, source.getConsumerInstance()); + } + + @Test + public void testShutdown() { + source.register(listener); + + source.shutdown(); + verify(cons).close(); + assertTrue(source.snapshotTopicListeners().isEmpty()); + } + + @Test + public void testGetFetchTimeout() { + assertEquals(MY_FETCH_TIMEOUT, source.getFetchTimeout()); + } + + @Test + public void testGetFetchLimit() { + assertEquals(MY_FETCH_LIMIT, source.getFetchLimit()); + } + + /** + * Implementation of SingleThreadedBusTopicSource that counts the number of times + * init() is invoked. + */ + private class SingleThreadedBusTopicSourceImpl extends SingleThreadedBusTopicSource { + + private int initCount = 0; + private boolean initEx = false; + + public SingleThreadedBusTopicSourceImpl(BusTopicParams busTopicParams) { + super(busTopicParams); + } + + @Override + public CommInfrastructure getTopicCommInfrastructure() { + return CommInfrastructure.NOOP; + } + + @Override + public void init() throws MalformedURLException { + ++initCount; + + if (initEx) { + throw new MalformedURLException(EXPECTED); + } + + consumer = cons; + } + + @Override + protected Thread makePollerThread() { + return thread; + } + + } +} diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java new file mode 100644 index 00000000..fa5a67a8 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.net.MalformedURLException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; + +public class SingleThreadedDmaapTopicSourceTest extends BusTopicTestBase { + private SingleThreadedDmaapTopicSource source; + + /** + * Creates the object to be tested. + */ + @Before + public void setUp() { + super.setUp(); + + source = new SingleThreadedDmaapTopicSource(makeBuilder().build()); + } + + @After + public void tearDown() { + source.shutdown(); + } + + @Test + public void testToString() { + assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource [")); + source.shutdown(); + + // try with null password + source = new SingleThreadedDmaapTopicSource(makeBuilder().password(null).build()); + assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource [")); + source.shutdown(); + + // try with empty password + source = new SingleThreadedDmaapTopicSource(makeBuilder().password("").build()); + assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource [")); + source.shutdown(); + } + + @Test + public void testInit() { + // verify with different parameters + new SingleThreadedDmaapTopicSource(makeBuilder().userName(null).build()).shutdown(); + new SingleThreadedDmaapTopicSource(makeBuilder().environment(null).aftEnvironment(null).latitude(null) + .longitude(null).partner(null).build()).shutdown(); + } + + @Test(expected = IllegalArgumentException.class) + public void testSingleThreadedDmaapTopicSource_Ex() { + new SingleThreadedDmaapTopicSource(makeBuilder().build()) { + @Override + public void init() throws MalformedURLException { + throw new MalformedURLException(EXPECTED); + } + }.shutdown(); + } + + @Test + public void testGetTopicCommInfrastructure() { + assertEquals(CommInfrastructure.DMAAP, source.getTopicCommInfrastructure()); + } + +} diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java new file mode 100644 index 00000000..373e80a4 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * policy-endpoints + * ================================================================================ + * Copyright (C) 2018 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.bus.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.event.comm.bus.BusTopicTestBase; + +public class SingleThreadedUebTopicSourceTest extends BusTopicTestBase { + private SingleThreadedUebTopicSource source; + + /** + * Creates the object to be tested. + */ + @Before + public void setUp() { + super.setUp(); + + source = new SingleThreadedUebTopicSource(makeBuilder().build()); + } + + @After + public void tearDown() { + source.shutdown(); + } + + @Test + public void testToString() { + assertTrue(source.toString().startsWith("SingleThreadedUebTopicSource [")); + source.shutdown(); + } + + @Test + public void testGetTopicCommInfrastructure() { + assertEquals(CommInfrastructure.UEB, source.getTopicCommInfrastructure()); + } + +} |