f24f7e2ec744f1c6dd86ce75f77079ab3bbb9263
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
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;
30
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;
35
36 class BusTopicBaseTest extends TopicTestBase {
37
38     private BusTopicBaseImpl base;
39
40     /**
41      * Initializes the object to be tested.
42      */
43     @BeforeEach
44     @Override
45     public void setUp() {
46         super.setUp();
47
48         base = new BusTopicBaseImpl(builder.build());
49     }
50
51     @Test
52     void testToString() {
53         assertNotNull(base.toString());
54     }
55
56     @Test
57     void testSerialize() {
58         assertThatCode(() -> new GsonTestUtils().compareGson(base, BusTopicBaseTest.class)).doesNotThrowAnyException();
59     }
60
61     @Test
62     void testGetApiKey() {
63         assertEquals(MY_API_KEY, base.getApiKey());
64     }
65
66     @Test
67     void testGetApiSecret() {
68         assertEquals(MY_API_SECRET, base.getApiSecret());
69     }
70
71     @Test
72     void testIsUseHttps() {
73         assertTrue(base.isUseHttps());
74         assertFalse(new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
75     }
76
77     @Test
78     void testIsAllowSelfSignedCerts() {
79         assertTrue(base.isAllowSelfSignedCerts());
80         assertFalse(new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
81     }
82
83     @Test
84     void testTopic() {
85         assertEquals(MY_TOPIC, base.getTopic());
86         assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
87         assertNotEquals(base.getTopic(), base.getEffectiveTopic());
88     }
89
90     @Test
91     void testAnyNullOrEmpty() {
92         assertFalse(base.anyNullOrEmpty());
93         assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
94
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", ""));
99     }
100
101     @Test
102     void testAllNullOrEmpty() {
103         assertTrue(base.allNullOrEmpty());
104         assertTrue(base.allNullOrEmpty(""));
105         assertTrue(base.allNullOrEmpty(null, ""));
106
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));
112     }
113
114     private static class BusTopicBaseImpl extends BusTopicBase {
115
116         public BusTopicBaseImpl(BusTopicParams busTopicParams) {
117             super(busTopicParams);
118         }
119
120         @Override
121         public CommInfrastructure getTopicCommInfrastructure() {
122             return CommInfrastructure.NOOP;
123         }
124
125         @Override
126         public boolean start() {
127             return true;
128         }
129
130         @Override
131         public boolean stop() {
132             return true;
133         }
134
135         @Override
136         public void shutdown() {
137             // do nothing
138         }
139
140     }
141 }