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                 + "\"streams_subscribes\": {"
 
  88                 + "\"config_key_1\": {"
 
  89                 + "\"type\": \"message_router\","
 
  90                 + "\"aaf_username\": \"some-user\","
 
  91                 + "\"aaf_password\": \"some-password\","
 
  93                 + "\"client_id\": \"1500462518108\","
 
  94                 + "\"client_role\": \"com.dcae.member\","
 
  95                 + "\"location\": \"mtc00\","
 
  96                 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION\""
 
  99                 + "\"config_key_2\": {"
 
 100                 + "\"type\": \"message_router\","
 
 101                 + "\"aaf_username\": \"some-user\","
 
 102                 + "\"aaf_password\": \"some-password\","
 
 103                 + "\"dmaap_info\": {"
 
 104                 + "\"client_id\": \"1500462518108\","
 
 105                 + "\"client_role\": \"com.dcae.member\","
 
 106                 + "\"location\": \"mtc00\","
 
 107                 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE\""
 
 111                 + "\"streams_publishes\": {"
 
 112                 + "\"config_key_3\": {"
 
 113                 + "\"type\": \"message_router\","
 
 114                 + "\"aaf_username\": \"some-user\","
 
 115                 + "\"aaf_password\": \"some-password\","
 
 116                 + "\"dmaap_info\": {"
 
 117                 + "\"client_id\": \"1500462518108\","
 
 118                 + "\"client_role\": \"com.dcae.member\","
 
 119                 + "\"location\": \"mtc00\","
 
 120                 + "\"topic_url\": \"https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT\""
 
 124                 + "\"services_calls\": {"
 
 125                 + "\"aai-interaction\": []"
 
 129         // Create expected configuration
 
 130         // Create Subscribes Objects
 
 131         Map<String, GeneratedAppConfigObject.StreamsObject> subscribes = new HashMap<>();
 
 133         GeneratedAppConfigObject.DmaapInfo dmaapInfo1 = ImmutableDmaapInfo.builder()
 
 134                 .clientId("1500462518108")
 
 135                 .clientRole("com.dcae.member")
 
 137                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.CPE_AUTHENTICATION")
 
 139         GeneratedAppConfigObject.StreamsObject streamsObject1 = ImmutableStreamsObject.builder()
 
 140                 .type("message_router")
 
 141                 .aafUsername("some-user")
 
 142                 .aafPassword("some-password")
 
 143                 .dmaapInfo(dmaapInfo1)
 
 145         GeneratedAppConfigObject.DmaapInfo dmaapInfo2 = ImmutableDmaapInfo.builder()
 
 146                 .clientId("1500462518108")
 
 147                 .clientRole("com.dcae.member")
 
 149                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.PNF_UPDATE")
 
 151         GeneratedAppConfigObject.StreamsObject streamsObject2 = ImmutableStreamsObject.builder()
 
 152                 .type("message_router")
 
 153                 .aafUsername("some-user")
 
 154                 .aafPassword("some-password")
 
 155                 .dmaapInfo(dmaapInfo2)
 
 158         subscribes.put("config_key_1", streamsObject1);
 
 159         subscribes.put("config_key_2", streamsObject2);
 
 161         // Create Publishes Objects
 
 162         GeneratedAppConfigObject.DmaapInfo dmaapInfo3 = ImmutableDmaapInfo.builder()
 
 163                 .clientId("1500462518108")
 
 164                 .clientRole("com.dcae.member")
 
 166                 .topicUrl("https://we-are-message-router.us:3905/events/unauthenticated.DCAE_CL_OUTPUT")
 
 168         GeneratedAppConfigObject.StreamsObject streamsObject3 = ImmutableStreamsObject.builder()
 
 169                 .type("message_router")
 
 170                 .aafUsername("some-user")
 
 171                 .aafPassword("some-password")
 
 172                 .dmaapInfo(dmaapInfo3)
 
 175         // Expected final config object
 
 176         GeneratedAppConfigObject expectedConfiguration = ImmutableGeneratedAppConfigObject.builder()
 
 177                 .dmaapProtocol("http")
 
 178                 .dmaapContentType("application/json")
 
 179                 .dmaapConsumerConsumerId("c12")
 
 180                 .dmaapConsumerConsumerGroup("OpenDcae-c12")
 
 181                 .dmaapMessageLimit(1)
 
 183                 .aaiHost("aai.onap.svc.cluster.local")
 
 185                 .aaiProtocol("https")
 
 188                 .aaiIgnoreSslCertificateErrors(true)
 
 189                 .pipelinesPollingIntervalSec(30)
 
 190                 .pipelinesTimeoutSec(15)
 
 191                 .cbsPollingIntervalSec(180)
 
 192                 .reRegistrationPolicyScope("policyScope")
 
 193                 .reRegistrationClControlName("controlName")
 
 194                 .cpeAuthPolicyScope("policyScope")
 
 195                 .cpeAuthClControlName("controlName")
 
 196                 .policyVersion("1.0")
 
 197                 .closeLoopTargetType("VM")
 
 198                 .closeLoopEventStatus("ONSET")
 
 199                 .closeLoopVersion("1.0.2")
 
 200                 .closeLoopTarget("vserver.vserver-name")
 
 201                 .closeLoopOriginator("DCAE-bbs-event-processor")
 
 202                 .reRegConfigKey("config_key_2")
 
 203                 .cpeAuthConfigKey("config_key_1")
 
 204                 .closeLoopConfigKey("config_key_3")
 
 205                 .loggingLevel("TRACE")
 
 206                 .streamSubscribesMap(subscribes)
 
 207                 .streamPublishesMap(Collections.singletonMap("config_key_3", streamsObject3))
 
 210         ConsulConfigurationGateway spiedGateway = Mockito.spy(configurationGateway);
 
 211         doReturn(false).when(spiedGateway).environmentNotReady();
 
 212         assertEquals(expectedConfiguration,
 
 213                 spiedGateway.generateAppConfigObject(jsonParser.parse(validJson).getAsJsonObject()));