2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27 import static org.junit.jupiter.api.Assertions.assertNotEquals;
28 import static org.junit.jupiter.api.Assertions.assertNotNull;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
34 import org.onap.policy.common.utils.gson.GsonTestUtils;
36 class BusTopicBaseTest extends TopicTestBase {
38 private BusTopicBaseImpl base;
41 * Initializes the object to be tested.
48 base = new BusTopicBaseImpl(builder.build());
53 assertNotNull(base.toString());
57 void testSerialize() {
58 assertThatCode(() -> new GsonTestUtils().compareGson(base, BusTopicBaseTest.class)).doesNotThrowAnyException();
62 void testGetApiKey() {
63 assertEquals(MY_API_KEY, base.getApiKey());
67 void testGetApiSecret() {
68 assertEquals(MY_API_SECRET, base.getApiSecret());
72 void testIsUseHttps() {
73 assertTrue(base.isUseHttps());
74 assertFalse(new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
78 void testIsAllowSelfSignedCerts() {
79 assertTrue(base.isAllowSelfSignedCerts());
80 assertFalse(new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
85 assertEquals(MY_TOPIC, base.getTopic());
86 assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
87 assertNotEquals(base.getTopic(), base.getEffectiveTopic());
91 void testAnyNullOrEmpty() {
92 assertFalse(base.anyNullOrEmpty());
93 assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
95 assertTrue(base.anyNullOrEmpty(null, "any-first-null"));
96 assertTrue(base.anyNullOrEmpty("any-middle-null", null, "any-middle-null-B"));
97 assertTrue(base.anyNullOrEmpty("any-last-null", null));
98 assertTrue(base.anyNullOrEmpty("any-empty", ""));
102 void testAllNullOrEmpty() {
103 assertTrue(base.allNullOrEmpty());
104 assertTrue(base.allNullOrEmpty(""));
105 assertTrue(base.allNullOrEmpty(null, ""));
107 assertFalse(base.allNullOrEmpty("all-ok-only-one"));
108 assertFalse(base.allNullOrEmpty("all-ok-one", "all-ok-two"));
109 assertFalse(base.allNullOrEmpty("all-ok-null", null));
110 assertFalse(base.allNullOrEmpty("", "all-ok-empty"));
111 assertFalse(base.allNullOrEmpty("", "all-one-ok", null));
114 private static class BusTopicBaseImpl extends BusTopicBase {
116 public BusTopicBaseImpl(BusTopicParams busTopicParams) {
117 super(busTopicParams);
121 public CommInfrastructure getTopicCommInfrastructure() {
122 return CommInfrastructure.NOOP;
126 public boolean start() {
131 public boolean stop() {
136 public void shutdown() {