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