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