0102804530cbcb11744d72e7b1357296a3e2a434
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2018-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
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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
32 import org.onap.policy.common.utils.gson.GsonTestUtils;
33
34 public class BusTopicBaseTest extends TopicTestBase {
35
36     private BusTopicBaseImpl base;
37
38     /**
39      * Initializes the object to be tested.
40      */
41     @Before
42     @Override
43     public void setUp() {
44         super.setUp();
45
46         base = new BusTopicBaseImpl(builder.build());
47     }
48
49     @Test
50     public void testToString() {
51         assertNotNull(base.toString());
52     }
53
54     @Test
55     public void testSerialize() {
56         new GsonTestUtils().compareGson(base, BusTopicBaseTest.class);
57     }
58
59     @Test
60     public void testGetApiKey() {
61         assertEquals(MY_API_KEY, base.getApiKey());
62     }
63
64     @Test
65     public void testGetApiSecret() {
66         assertEquals(MY_API_SECRET, base.getApiSecret());
67     }
68
69     @Test
70     public void testIsUseHttps() {
71         assertEquals(true, base.isUseHttps());
72         assertEquals(false, new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
73     }
74
75     @Test
76     public void testIsAllowSelfSignedCerts() {
77         assertEquals(true, base.isAllowSelfSignedCerts());
78         assertEquals(false, new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
79     }
80
81     @Test
82     public void testTopic() {
83         assertEquals(MY_TOPIC, base.getTopic());
84         assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
85         assertNotEquals(base.getTopic(), base.getEffectiveTopic());
86     }
87
88     @Test
89     public void testAnyNullOrEmpty() {
90         assertFalse(base.anyNullOrEmpty());
91         assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
92
93         assertTrue(base.anyNullOrEmpty(null, "any-first-null"));
94         assertTrue(base.anyNullOrEmpty("any-middle-null", null, "any-middle-null-B"));
95         assertTrue(base.anyNullOrEmpty("any-last-null", null));
96         assertTrue(base.anyNullOrEmpty("any-empty", ""));
97     }
98
99     @Test
100     public void testAllNullOrEmpty() {
101         assertTrue(base.allNullOrEmpty());
102         assertTrue(base.allNullOrEmpty(""));
103         assertTrue(base.allNullOrEmpty(null, ""));
104
105         assertFalse(base.allNullOrEmpty("all-ok-only-one"));
106         assertFalse(base.allNullOrEmpty("all-ok-one", "all-ok-two"));
107         assertFalse(base.allNullOrEmpty("all-ok-null", null));
108         assertFalse(base.allNullOrEmpty("", "all-ok-empty"));
109         assertFalse(base.allNullOrEmpty("", "all-one-ok", null));
110     }
111
112     private static class BusTopicBaseImpl extends BusTopicBase {
113
114         public BusTopicBaseImpl(BusTopicParams busTopicParams) {
115             super(busTopicParams);
116         }
117
118         @Override
119         public CommInfrastructure getTopicCommInfrastructure() {
120             return CommInfrastructure.NOOP;
121         }
122
123         @Override
124         public boolean start() {
125             return true;
126         }
127
128         @Override
129         public boolean stop() {
130             return true;
131         }
132
133         @Override
134         public void shutdown() {
135             // do nothing
136         }
137
138     }
139 }