diff options
11 files changed, 874 insertions, 37 deletions
diff --git a/common-logging/pom.xml b/common-logging/pom.xml index 2d3186b9..e32014fe 100644 --- a/common-logging/pom.xml +++ b/common-logging/pom.xml @@ -33,10 +33,6 @@ <description>ONAP Logging Framework</description> <packaging>jar</packaging> - <properties> - <powermock.version>1.6.6</powermock.version> - </properties> - <dependencies> <dependency> <groupId>log4j</groupId> @@ -60,7 +56,6 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>${powermock.version}</version> <scope>test</scope> </dependency> </dependencies> diff --git a/integrity-monitor/pom.xml b/integrity-monitor/pom.xml index 9a25c000..2255138b 100644 --- a/integrity-monitor/pom.xml +++ b/integrity-monitor/pom.xml @@ -35,15 +35,10 @@ <name>Integrity Monitor</name> - <properties> - <powermock.version>1.6.6</powermock.version> - </properties> - <dependencies> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> 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()); + } + +} diff --git a/utils-test/pom.xml b/utils-test/pom.xml index c87da916..d069d0db 100644 --- a/utils-test/pom.xml +++ b/utils-test/pom.xml @@ -54,7 +54,6 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>${powermock.version}</version> <scope>test</scope> </dependency> </dependencies> diff --git a/utils/pom.xml b/utils/pom.xml index 4b0f03ba..82f07b38 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -32,11 +32,6 @@ <description>Common Utilities</description> <packaging>jar</packaging> - <properties> - <powermock.version>1.6.6</powermock.version> - <slf4j.version>1.7.25</slf4j.version> - </properties> - <dependencies> <dependency> <groupId>org.apache.commons</groupId> @@ -60,32 +55,12 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>${powermock.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> - <version>${powermock.version}</version> <scope>test</scope> - <exclusions> - <exclusion> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </exclusion> - <exclusion> - <groupId>org.powermock</groupId> - <artifactId>powermock-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.powermock</groupId> - <artifactId>powermock-reflect</artifactId> - </exclusion> - <exclusion> - <groupId>org.javassist</groupId> - <artifactId>javassist</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>com.openpojo</groupId> diff --git a/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java b/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java index 1e402d2a..6dd09d6e 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java +++ b/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java @@ -32,7 +32,7 @@ public class NetworkUtilTest { @Test public void test() throws InterruptedException, IOException { assertNotNull(NetworkUtil.IPv4_WILDCARD_ADDRESS); - assertFalse(NetworkUtil.isTcpPortOpen("localhost", 8080, 1, 5)); + assertFalse(NetworkUtil.isTcpPortOpen("localhost", 8180, 1, 5)); assertNotNull(NetworkUtil.getHostname()); assertNotNull(NetworkUtil.getHostIp()); } |