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