5628a23919e585d1514523dde841a38778ae112e
[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     public void setUp() {
43         super.setUp();
44
45         base = new BusTopicBaseImpl(builder.build());
46     }
47
48     @Test
49     public void testToString() {
50         assertNotNull(base.toString());
51     }
52
53     @Test
54     public void testSerialize() {
55         new GsonTestUtils().compareGson(base, BusTopicBaseTest.class);
56     }
57
58     @Test
59     public void testGetApiKey() {
60         assertEquals(MY_API_KEY, base.getApiKey());
61     }
62
63     @Test
64     public void testGetApiSecret() {
65         assertEquals(MY_API_SECRET, base.getApiSecret());
66     }
67
68     @Test
69     public void testIsUseHttps() {
70         assertEquals(true, base.isUseHttps());
71         assertEquals(false, new BusTopicBaseImpl(builder.useHttps(false).build()).isUseHttps());
72     }
73
74     @Test
75     public void testIsAllowSelfSignedCerts() {
76         assertEquals(true, base.isAllowSelfSignedCerts());
77         assertEquals(false, new BusTopicBaseImpl(builder.allowSelfSignedCerts(false).build()).isAllowSelfSignedCerts());
78     }
79
80     @Test
81     public void testTopic() {
82         assertEquals(MY_TOPIC, base.getTopic());
83         assertEquals(MY_EFFECTIVE_TOPIC, base.getEffectiveTopic());
84         assertNotEquals(base.getTopic(), base.getEffectiveTopic());
85     }
86
87     @Test
88     public void testAnyNullOrEmpty() {
89         assertFalse(base.anyNullOrEmpty());
90         assertFalse(base.anyNullOrEmpty("any-none-null", "any-none-null-B"));
91
92         assertTrue(base.anyNullOrEmpty(null, "any-first-null"));
93         assertTrue(base.anyNullOrEmpty("any-middle-null", null, "any-middle-null-B"));
94         assertTrue(base.anyNullOrEmpty("any-last-null", null));
95         assertTrue(base.anyNullOrEmpty("any-empty", ""));
96     }
97
98     @Test
99     public void testAllNullOrEmpty() {
100         assertTrue(base.allNullOrEmpty());
101         assertTrue(base.allNullOrEmpty(""));
102         assertTrue(base.allNullOrEmpty(null, ""));
103
104         assertFalse(base.allNullOrEmpty("all-ok-only-one"));
105         assertFalse(base.allNullOrEmpty("all-ok-one", "all-ok-two"));
106         assertFalse(base.allNullOrEmpty("all-ok-null", null));
107         assertFalse(base.allNullOrEmpty("", "all-ok-empty"));
108         assertFalse(base.allNullOrEmpty("", "all-one-ok", null));
109     }
110
111     private static class BusTopicBaseImpl extends BusTopicBase {
112
113         public BusTopicBaseImpl(BusTopicParams busTopicParams) {
114             super(busTopicParams);
115         }
116
117         @Override
118         public CommInfrastructure getTopicCommInfrastructure() {
119             return CommInfrastructure.NOOP;
120         }
121
122         @Override
123         public boolean start() {
124             return true;
125         }
126
127         @Override
128         public boolean stop() {
129             return true;
130         }
131
132         @Override
133         public void shutdown() {
134             // do nothing
135         }
136
137     }
138 }