ee75926b3aaecf47b263e97b3bdc3812771fe580
[dcaegen2/services.git] /
1 /*
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
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.bbs.event.processor.config;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.mockito.Mockito.doReturn;
25
26 import com.google.gson.JsonParser;
27
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.Map;
31
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;
39
40 class ConsulConfigurationGatewayTest {
41
42     private ConsulConfigurationGateway configurationGateway;
43     private static JsonParser jsonParser;
44
45     @BeforeAll
46     static void setup() {
47         jsonParser = new JsonParser();
48     }
49
50     ConsulConfigurationGatewayTest() {
51         ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
52         this.configurationGateway = new ConsulConfigurationGateway(configuration);
53     }
54
55     @Test
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\","
85                 + "\"dmaap_info\": {"
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\""
90                 + "}"
91                 + "},"
92                 + "\"config_key_2\": {"
93                 + "\"type\": \"message_router\","
94                 + "\"aaf_username\": \"some-user\","
95                 + "\"aaf_password\": \"some-password\","
96                 + "\"dmaap_info\": {"
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\""
101                 + "}"
102                 + "}"
103                 + "},"
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\""
114                 + "}"
115                 + "}"
116                 + "},"
117                 + "\"services_calls\": {"
118                 + "\"aai-interaction\": []"
119                 + "}"
120                 + "}";
121
122         // Create expected configuration
123         // Create Subscribes Objects
124         Map<String, GeneratedAppConfigObject.StreamsObject> subscribes = new HashMap<>();
125
126         GeneratedAppConfigObject.DmaapInfo dmaapInfo1 = ImmutableDmaapInfo.builder()
127                 .clientId("1500462518108")
128                 .clientRole("com.dcae.member")
129                 .location("mtc00")
130                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION")
131                 .build();
132         GeneratedAppConfigObject.StreamsObject streamsObject1 = ImmutableStreamsObject.builder()
133                 .type("message_router")
134                 .aafUsername("some-user")
135                 .aafPassword("some-password")
136                 .dmaapInfo(dmaapInfo1)
137                 .build();
138         GeneratedAppConfigObject.DmaapInfo dmaapInfo2 = ImmutableDmaapInfo.builder()
139                 .clientId("1500462518108")
140                 .clientRole("com.dcae.member")
141                 .location("mtc00")
142                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE")
143                 .build();
144         GeneratedAppConfigObject.StreamsObject streamsObject2 = ImmutableStreamsObject.builder()
145                 .type("message_router")
146                 .aafUsername("some-user")
147                 .aafPassword("some-password")
148                 .dmaapInfo(dmaapInfo2)
149                 .build();
150
151         subscribes.put("config_key_1", streamsObject1);
152         subscribes.put("config_key_2", streamsObject2);
153
154         // Create Publishes Objects
155         GeneratedAppConfigObject.DmaapInfo dmaapInfo3 = ImmutableDmaapInfo.builder()
156                 .clientId("1500462518108")
157                 .clientRole("com.dcae.member")
158                 .location("mtc00")
159                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT")
160                 .build();
161         GeneratedAppConfigObject.StreamsObject streamsObject3 = ImmutableStreamsObject.builder()
162                 .type("message_router")
163                 .aafUsername("some-user")
164                 .aafPassword("some-password")
165                 .dmaapInfo(dmaapInfo3)
166                 .build();
167
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)
175                 .dmaapTimeoutMs(-1)
176                 .aaiHost("aai.onap.svc.cluster.local")
177                 .aaiPort(8443)
178                 .aaiProtocol("https")
179                 .aaiUsername("AAI")
180                 .aaiPassword("AAI")
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))
194                 .build();
195
196         ConsulConfigurationGateway spiedGateway = Mockito.spy(configurationGateway);
197         doReturn(false).when(spiedGateway).environmentNotReady();
198         assertEquals(expectedConfiguration,
199                 spiedGateway.generateAppConfigObject(jsonParser.parse(validJson).getAsJsonObject()));
200     }
201 }