2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.assertSame;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.verify;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
35 import org.onap.policy.common.endpoints.event.comm.TopicListener;
37 public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T extends NoopTopicEndpoint>
38 extends TopicTestBase {
40 protected final F factory;
43 public NoopTopicEndpointTest(F factory) {
44 this.factory = factory;
47 protected abstract boolean io(String message);
53 this.endpoint = this.factory.build(servers, MY_TOPIC);
58 TopicListener listener = mock(TopicListener.class);
59 this.endpoint.register(listener);
60 this.endpoint.start();
62 assertTrue(io(MY_MESSAGE));
63 assertSame(MY_MESSAGE, this.endpoint.getRecentEvents()[0]);
64 assertEquals(Collections.singletonList(MY_MESSAGE), Arrays.asList(this.endpoint.getRecentEvents()));
65 verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE);
67 this.endpoint.unregister(listener);
70 @Test(expected = IllegalArgumentException.class)
71 public void testIoNullMessage() {
75 @Test(expected = IllegalArgumentException.class)
76 public void testIoEmptyMessage() {
80 @Test(expected = IllegalStateException.class)
81 public void testOfferNotStarted() {
86 public void testGetTopicCommInfrastructure() {
87 assertEquals(CommInfrastructure.NOOP, this.endpoint.getTopicCommInfrastructure());
91 public void testStart_testStop_testShutdown() {
92 this.endpoint.start();
93 assertTrue(this.endpoint.isAlive());
96 this.endpoint.start();
97 assertTrue(this.endpoint.isAlive());
100 this.endpoint.stop();
101 assertFalse(this.endpoint.isAlive());
104 this.endpoint.start();
105 assertTrue(this.endpoint.isAlive());
108 this.endpoint.shutdown();
109 assertFalse(this.endpoint.isAlive());
112 @Test(expected = IllegalStateException.class)
113 public void testStart_Locked() {
114 this.endpoint.lock();
115 this.endpoint.start();