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;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
36 import org.onap.policy.common.endpoints.event.comm.TopicListener;
38 public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T extends NoopTopicEndpoint>
39 extends TopicTestBase {
41 protected final F factory;
44 public NoopTopicEndpointTest(F factory) {
45 this.factory = factory;
48 protected abstract boolean io(String message);
54 this.endpoint = this.factory.build(servers, MY_TOPIC);
58 public void testIo() {
59 TopicListener listener = mock(TopicListener.class);
60 this.endpoint.register(listener);
61 this.endpoint.start();
63 assertTrue(io(MY_MESSAGE));
64 assertSame(MY_MESSAGE, this.endpoint.getRecentEvents()[0]);
65 assertEquals(Collections.singletonList(MY_MESSAGE), Arrays.asList(this.endpoint.getRecentEvents()));
66 verify(listener).onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MY_MESSAGE);
68 this.endpoint.unregister(listener);
71 @Test(expected = IllegalArgumentException.class)
72 public void testIoNullMessage() {
76 @Test(expected = IllegalArgumentException.class)
77 public void testIoEmptyMessage() {
81 @Test(expected = IllegalStateException.class)
82 public void testOfferNotStarted() {
87 public void testGetTopicCommInfrastructure() {
88 assertEquals(CommInfrastructure.NOOP, this.endpoint.getTopicCommInfrastructure());
92 public void testStart_testStop_testShutdown() {
93 this.endpoint.start();
94 assertTrue(this.endpoint.isAlive());
97 this.endpoint.start();
98 assertTrue(this.endpoint.isAlive());
101 this.endpoint.stop();
102 assertFalse(this.endpoint.isAlive());
105 this.endpoint.start();
106 assertTrue(this.endpoint.isAlive());
109 this.endpoint.shutdown();
110 assertFalse(this.endpoint.isAlive());
113 @Test(expected = IllegalStateException.class)
114 public void testStart_Locked() {
115 this.endpoint.lock();
116 this.endpoint.start();