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