2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2020 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.internal;
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
33 import org.onap.policy.common.utils.gson.GsonTestUtils;
35 public class BusTopicBaseTest extends TopicTestBase {
37 private BusTopicBaseImpl base;
40 * Initializes the object to be tested.
47 base = new BusTopicBaseImpl(builder.build());
51 public void testToString() {
52 assertNotNull(base.toString());
56 public void testSerialize() {
57 assertThatCode(() -> new GsonTestUtils().compareGson(base, BusTopicBaseTest.class)).doesNotThrowAnyException();
61 public void testGetApiKey() {
62 assertEquals(MY_API_KEY, base.getApiKey());
66 public void testGetApiSecret() {
67 assertEquals(MY_API_SECRET, base.getApiSecret());
71 public void testIsUseHttps() {
72 assertEquals(true, base.isUseHttps());
73 assertEquals(false, new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
77 public void testIsAllowSelfSignedCerts() {
78 assertEquals(true, base.isAllowSelfSignedCerts());
79 assertEquals(false, new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
83 public void testTopic() {
84 assertEquals(MY_TOPIC, base.getTopic());
85 assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
86 assertNotEquals(base.getTopic(), base.getEffectiveTopic());
90 public void testAnyNullOrEmpty() {
91 assertFalse(base.anyNullOrEmpty());
92 assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
94 assertTrue(base.anyNullOrEmpty(null, "any-first-null"));
95 assertTrue(base.anyNullOrEmpty("any-middle-null", null, "any-middle-null-B"));
96 assertTrue(base.anyNullOrEmpty("any-last-null", null));
97 assertTrue(base.anyNullOrEmpty("any-empty", ""));
101 public void testAllNullOrEmpty() {
102 assertTrue(base.allNullOrEmpty());
103 assertTrue(base.allNullOrEmpty(""));
104 assertTrue(base.allNullOrEmpty(null, ""));
106 assertFalse(base.allNullOrEmpty("all-ok-only-one"));
107 assertFalse(base.allNullOrEmpty("all-ok-one", "all-ok-two"));
108 assertFalse(base.allNullOrEmpty("all-ok-null", null));
109 assertFalse(base.allNullOrEmpty("", "all-ok-empty"));
110 assertFalse(base.allNullOrEmpty("", "all-one-ok", null));
113 private static class BusTopicBaseImpl extends BusTopicBase {
115 public BusTopicBaseImpl(BusTopicParams busTopicParams) {
116 super(busTopicParams);
120 public CommInfrastructure getTopicCommInfrastructure() {
121 return CommInfrastructure.NOOP;
125 public boolean start() {
130 public boolean stop() {
135 public void shutdown() {