2 * ============LICENSE_START=======================================================
3 * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.bbs.event.processor.config;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.mockito.Mockito.doReturn;
26 import com.google.gson.JsonParser;
28 import java.util.Collections;
29 import java.util.HashMap;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.api.Test;
34 import org.mockito.Mockito;
35 import org.onap.bbs.event.processor.model.GeneratedAppConfigObject;
36 import org.onap.bbs.event.processor.model.ImmutableDmaapInfo;
37 import org.onap.bbs.event.processor.model.ImmutableGeneratedAppConfigObject;
38 import org.onap.bbs.event.processor.model.ImmutableStreamsObject;
40 class ConsulConfigurationGatewayTest {
42 private ConsulConfigurationGateway configurationGateway;
43 private static JsonParser jsonParser;
47 jsonParser = new JsonParser();
50 ConsulConfigurationGatewayTest() {
51 ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
52 this.configurationGateway = new ConsulConfigurationGateway(configuration);
56 void passingValidJson_constructsGeneratedAppConfigObject() {
57 final String validJson = "{"
58 + "\"dmaap.protocol\": \"http\","
59 + "\"dmaap.contentType\": \"application/json\","
60 + "\"dmaap.consumer.consumerId\": \"c12\","
61 + "\"dmaap.consumer.consumerGroup\": \"OpenDcae-c12\","
62 + "\"dmaap.messageLimit\": 1,"
63 + "\"dmaap.timeoutMs\": -1,"
64 + "\"aai.host\": \"aai.onap.svc.cluster.local\","
65 + "\"aai.port\": \"8443\","
66 + "\"aai.protocol\": \"https\","
67 + "\"aai.username\": \"AAI\","
68 + "\"aai.password\": \"AAI\","
69 + "\"aai.aaiIgnoreSslCertificateErrors\": true,"
70 + "\"application.pipelinesPollingIntervalSec\": 30,"
71 + "\"application.pipelinesTimeoutSec\": 15,"
72 + "\"application.cbsPollingIntervalSec\": 180,"
73 + "\"application.reregistration.policyScope\": \"policyScope\","
74 + "\"application.reregistration.clControlName\": \"controlName\","
75 + "\"application.cpe.authentication.policyScope\": \"policyScope\","
76 + "\"application.cpe.authentication.clControlName\": \"controlName\","
77 + "\"application.policyVersion\": \"1.0\","
78 + "\"application.clTargetType\": \"VM\","
79 + "\"application.clEventStatus\": \"ONSET\","
80 + "\"application.clVersion\": \"1.0.2\","
81 + "\"application.clTarget\": \"vserver.vserver-name\","
82 + "\"application.clOriginator\": \"DCAE-bbs-event-processor\","
83 + "\"application.reregistration.configKey\": \"config_key_2\","
84 + "\"application.cpeAuth.configKey\": \"config_key_1\","
85 + "\"application.closeLoop.configKey\": \"config_key_3\","
86 + "\"application.loggingLevel\": \"TRACE\","
87 + "\"application.ssl.keyStorePath\": \"/opt/app/bbs-event-processor/etc/cert/key.p12\","
88 + "\"application.ssl.keyStorePasswordPath\": \"/opt/app/bbs-event-processor/etc/cert/key.pass\","
89 + "\"application.ssl.trustStorePath\": \"/opt/app/bbs-event-processor/etc/cert/trust.jks\","
90 + "\"application.ssl.trustStorePasswordPath\": \"/opt/app/bbs-event-processor/etc/cert/trust.pass\","
91 + "\"application.ssl.enableAaiCertAuth\": true,"
92 + "\"application.ssl.enableDmaapCertAuth\": true,"
93 + "\"streams_subscribes\": {"
94 + "\"config_key_1\": {"
95 + "\"type\": \"message_router\","
96 + "\"aaf_username\": \"some-user\","
97 + "\"aaf_password\": \"some-password\","
99 + "\"client_id\": \"1500462518108\","
100 + "\"client_role\": \"com.dcae.member\","
101 + "\"location\": \"mtc00\","
102 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION\""
105 + "\"config_key_2\": {"
106 + "\"type\": \"message_router\","
107 + "\"aaf_username\": \"some-user\","
108 + "\"aaf_password\": \"some-password\","
109 + "\"dmaap_info\": {"
110 + "\"client_id\": \"1500462518108\","
111 + "\"client_role\": \"com.dcae.member\","
112 + "\"location\": \"mtc00\","
113 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE\""
117 + "\"streams_publishes\": {"
118 + "\"config_key_3\": {"
119 + "\"type\": \"message_router\","
120 + "\"aaf_username\": \"some-user\","
121 + "\"aaf_password\": \"some-password\","
122 + "\"dmaap_info\": {"
123 + "\"client_id\": \"1500462518108\","
124 + "\"client_role\": \"com.dcae.member\","
125 + "\"location\": \"mtc00\","
126 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT\""
130 + "\"services_calls\": {"
131 + "\"aai-interaction\": []"
135 // Create expected configuration
136 // Create Subscribes Objects
137 Map<String, GeneratedAppConfigObject.StreamsObject> subscribes = new HashMap<>();
139 GeneratedAppConfigObject.DmaapInfo dmaapInfo1 = ImmutableDmaapInfo.builder()
140 .clientId("1500462518108")
141 .clientRole("com.dcae.member")
143 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION")
145 GeneratedAppConfigObject.StreamsObject streamsObject1 = ImmutableStreamsObject.builder()
146 .type("message_router")
147 .aafUsername("some-user")
148 .aafPassword("some-password")
149 .dmaapInfo(dmaapInfo1)
151 GeneratedAppConfigObject.DmaapInfo dmaapInfo2 = ImmutableDmaapInfo.builder()
152 .clientId("1500462518108")
153 .clientRole("com.dcae.member")
155 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE")
157 GeneratedAppConfigObject.StreamsObject streamsObject2 = ImmutableStreamsObject.builder()
158 .type("message_router")
159 .aafUsername("some-user")
160 .aafPassword("some-password")
161 .dmaapInfo(dmaapInfo2)
164 subscribes.put("config_key_1", streamsObject1);
165 subscribes.put("config_key_2", streamsObject2);
167 // Create Publishes Objects
168 GeneratedAppConfigObject.DmaapInfo dmaapInfo3 = ImmutableDmaapInfo.builder()
169 .clientId("1500462518108")
170 .clientRole("com.dcae.member")
172 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT")
174 GeneratedAppConfigObject.StreamsObject streamsObject3 = ImmutableStreamsObject.builder()
175 .type("message_router")
176 .aafUsername("some-user")
177 .aafPassword("some-password")
178 .dmaapInfo(dmaapInfo3)
181 // Expected final config object
182 GeneratedAppConfigObject expectedConfiguration = ImmutableGeneratedAppConfigObject.builder()
183 .dmaapProtocol("http")
184 .dmaapContentType("application/json")
185 .dmaapConsumerConsumerId("c12")
186 .dmaapConsumerConsumerGroup("OpenDcae-c12")
187 .dmaapMessageLimit(1)
189 .aaiHost("aai.onap.svc.cluster.local")
191 .aaiProtocol("https")
194 .aaiIgnoreSslCertificateErrors(true)
195 .pipelinesPollingIntervalSec(30)
196 .pipelinesTimeoutSec(15)
197 .cbsPollingIntervalSec(180)
198 .reRegistrationPolicyScope("policyScope")
199 .reRegistrationClControlName("controlName")
200 .cpeAuthPolicyScope("policyScope")
201 .cpeAuthClControlName("controlName")
202 .policyVersion("1.0")
203 .closeLoopTargetType("VM")
204 .closeLoopEventStatus("ONSET")
205 .closeLoopVersion("1.0.2")
206 .closeLoopTarget("vserver.vserver-name")
207 .closeLoopOriginator("DCAE-bbs-event-processor")
208 .reRegConfigKey("config_key_2")
209 .cpeAuthConfigKey("config_key_1")
210 .closeLoopConfigKey("config_key_3")
211 .loggingLevel("TRACE")
212 .keyStorePath("/opt/app/bbs-event-processor/etc/cert/key.p12")
213 .keyStorePasswordPath("/opt/app/bbs-event-processor/etc/cert/key.pass")
214 .trustStorePath("/opt/app/bbs-event-processor/etc/cert/trust.jks")
215 .trustStorePasswordPath("/opt/app/bbs-event-processor/etc/cert/trust.pass")
216 .enableAaiCertAuth(true)
217 .enableDmaapCertAuth(true)
218 .streamSubscribesMap(subscribes)
219 .streamPublishesMap(Collections.singletonMap("config_key_3", streamsObject3))
222 ConsulConfigurationGateway spiedGateway = Mockito.spy(configurationGateway);
223 doReturn(false).when(spiedGateway).environmentNotReady();
224 assertEquals(expectedConfiguration,
225 spiedGateway.generateAppConfigObject(jsonParser.parse(validJson).getAsJsonObject()));