2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.endpoints.event.comm.bus;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.verify;
29 import java.util.Arrays;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
33 import org.onap.policy.common.endpoints.event.comm.TopicListener;
35 public class NoopTopicSinkTest extends BusTopicTestBase {
37 private NoopTopicSink sink;
40 * Creates the object to be tested.
46 sink = new NoopTopicSink(servers, MY_TOPIC);
50 public void testToString() {
51 assertTrue(sink.toString().startsWith("NoopTopicSink ["));
55 public void testSend() {
56 TopicListener listener = mock(TopicListener.class);
57 sink.register(listener);
60 assertTrue(sink.send(MY_MESSAGE));
62 assertEquals(Arrays.asList(MY_MESSAGE), Arrays.asList(sink.getRecentEvents()));
63 verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE);
65 // generate exception during broadcast
66 sink = new NoopTopicSink(servers, MY_TOPIC) {
68 protected boolean broadcast(String message) {
69 throw new RuntimeException(EXPECTED);
75 assertFalse(sink.send(MY_MESSAGE));
78 @Test(expected = IllegalArgumentException.class)
79 public void testSend_NullMessage() {
83 @Test(expected = IllegalArgumentException.class)
84 public void testSend_EmptyMessage() {
88 @Test(expected = IllegalStateException.class)
89 public void testSend_NotStarted() {
90 sink.send(MY_MESSAGE);
94 public void testGetTopicCommInfrastructure() {
95 assertEquals(CommInfrastructure.NOOP, sink.getTopicCommInfrastructure());
99 public void testStart_testStop_testShutdown() {
101 assertTrue(sink.isAlive());
105 assertTrue(sink.isAlive());
109 assertFalse(sink.isAlive());
113 assertTrue(sink.isAlive());
117 assertFalse(sink.isAlive());
120 @Test(expected = IllegalStateException.class)
121 public void testStart_Locked() {