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.reregistration.configKey\": \"config_key_2\","
78 + "\"application.cpeAuth.configKey\": \"config_key_1\","
79 + "\"application.closeLoop.configKey\": \"config_key_3\","
80 + "\"streams_subscribes\": {"
81 + "\"config_key_1\": {"
82 + "\"type\": \"message_router\","
83 + "\"aaf_username\": \"some-user\","
84 + "\"aaf_password\": \"some-password\","
86 + "\"client_id\": \"1500462518108\","
87 + "\"client_role\": \"com.dcae.member\","
88 + "\"location\": \"mtc00\","
89 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION\""
92 + "\"config_key_2\": {"
93 + "\"type\": \"message_router\","
94 + "\"aaf_username\": \"some-user\","
95 + "\"aaf_password\": \"some-password\","
97 + "\"client_id\": \"1500462518108\","
98 + "\"client_role\": \"com.dcae.member\","
99 + "\"location\": \"mtc00\","
100 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE\""
104 + "\"streams_publishes\": {"
105 + "\"config_key_3\": {"
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.DCAE_CL_OUTPUT\""
117 + "\"services_calls\": {"
118 + "\"aai-interaction\": []"
122 // Create expected configuration
123 // Create Subscribes Objects
124 Map<String, GeneratedAppConfigObject.StreamsObject> subscribes = new HashMap<>();
126 GeneratedAppConfigObject.DmaapInfo dmaapInfo1 = ImmutableDmaapInfo.builder()
127 .clientId("1500462518108")
128 .clientRole("com.dcae.member")
130 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION")
132 GeneratedAppConfigObject.StreamsObject streamsObject1 = ImmutableStreamsObject.builder()
133 .type("message_router")
134 .aafUsername("some-user")
135 .aafPassword("some-password")
136 .dmaapInfo(dmaapInfo1)
138 GeneratedAppConfigObject.DmaapInfo dmaapInfo2 = ImmutableDmaapInfo.builder()
139 .clientId("1500462518108")
140 .clientRole("com.dcae.member")
142 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE")
144 GeneratedAppConfigObject.StreamsObject streamsObject2 = ImmutableStreamsObject.builder()
145 .type("message_router")
146 .aafUsername("some-user")
147 .aafPassword("some-password")
148 .dmaapInfo(dmaapInfo2)
151 subscribes.put("config_key_1", streamsObject1);
152 subscribes.put("config_key_2", streamsObject2);
154 // Create Publishes Objects
155 GeneratedAppConfigObject.DmaapInfo dmaapInfo3 = ImmutableDmaapInfo.builder()
156 .clientId("1500462518108")
157 .clientRole("com.dcae.member")
159 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT")
161 GeneratedAppConfigObject.StreamsObject streamsObject3 = ImmutableStreamsObject.builder()
162 .type("message_router")
163 .aafUsername("some-user")
164 .aafPassword("some-password")
165 .dmaapInfo(dmaapInfo3)
168 // Expected final config object
169 GeneratedAppConfigObject expectedConfiguration = ImmutableGeneratedAppConfigObject.builder()
170 .dmaapProtocol("http")
171 .dmaapContentType("application/json")
172 .dmaapConsumerConsumerId("c12")
173 .dmaapConsumerConsumerGroup("OpenDcae-c12")
174 .dmaapMessageLimit(1)
176 .aaiHost("aai.onap.svc.cluster.local")
178 .aaiProtocol("https")
181 .aaiIgnoreSslCertificateErrors(true)
182 .pipelinesPollingIntervalSec(30)
183 .pipelinesTimeoutSec(15)
184 .cbsPollingIntervalSec(180)
185 .reRegistrationPolicyScope("policyScope")
186 .reRegistrationClControlName("controlName")
187 .cpeAuthPolicyScope("policyScope")
188 .cpeAuthClControlName("controlName")
189 .reRegConfigKey("config_key_2")
190 .cpeAuthConfigKey("config_key_1")
191 .closeLoopConfigKey("config_key_3")
192 .streamSubscribesMap(subscribes)
193 .streamPublishesMap(Collections.singletonMap("config_key_3", streamsObject3))
196 ConsulConfigurationGateway spiedGateway = Mockito.spy(configurationGateway);
197 doReturn(false).when(spiedGateway).environmentNotReady();
198 assertEquals(expectedConfiguration,
199 spiedGateway.generateAppConfigObject(jsonParser.parse(validJson).getAsJsonObject()));