89f1a043cfc29d72c49404b5be5df6d852c52b8a
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2023 Deutsche Telekom 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 package org.onap.dcaegen2.services.prh.configuration;
21
22 import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
23 import static java.lang.ClassLoader.getSystemResource;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import org.junit.jupiter.api.Test;
29 import com.google.gson.Gson;
30 import com.google.gson.JsonObject;
31
32 /**
33  *  * @author <a href="mailto:PRANIT.KAPDULE@t-systems.com">Pranit Kapdule</a> on
34  *   *        24/08/23
35  *    */
36
37 public class CbsConfigurationForAutoCommitDisabledModeTest {
38
39     /**
40      * Testcase is used to check correctness of values provided by
41      * autoCommitDisabledConfigurationFromCbs2.json
42      */
43
44     @Test
45     void beforecbsConfigurationForAutoCommitDisabledMode() throws Exception {
46         withEnvironmentVariable("JAAS_CONFIG", "jaas_config").execute(() -> {
47             this.cbsConfigurationForAutoCommitDisabledMode();
48         });
49     }
50
51     void cbsConfigurationForAutoCommitDisabledMode() throws Exception {
52
53         JsonObject cbsConfigJsonForAutoCommitDisabled = new Gson().fromJson(
54                 new String(Files.readAllBytes(
55                         Paths.get(getSystemResource("autoCommitDisabledConfigurationFromCbs2.json").toURI()))),
56                 JsonObject.class);
57         CbsConfigurationForAutoCommitDisabledMode cbsConfigurationForAutoCommitDisabled = new CbsConfigurationForAutoCommitDisabledMode();
58
59         cbsConfigurationForAutoCommitDisabled.parseCBSConfig(cbsConfigJsonForAutoCommitDisabled);
60
61         String expectedKafKaBoostrapServerConfig = "onap-strimzi-kafka-bootstrap:9092";
62         String actualKafkaBoostrapServerConfig = (cbsConfigurationForAutoCommitDisabled.getKafkaConfig()
63                 .kafkaBoostrapServerConfig());
64
65         String expectedGroupIdConfig = "OpenDCAE-c12";
66         String actualGroupIdConfig = (cbsConfigurationForAutoCommitDisabled.getKafkaConfig().groupIdConfig());
67
68         String expectedKafkaSecurityProtocol = "SASL_PLAINTEXT";
69         String actualKafkaSecurityProtocol = (cbsConfigurationForAutoCommitDisabled.getKafkaConfig()
70                 .kafkaSecurityProtocol());
71
72         String expectedKafkaSaslMechanism = "SCRAM-SHA-512";
73         String actualKafkaSaslMechanism = (cbsConfigurationForAutoCommitDisabled.getKafkaConfig().kafkaSaslMechanism());
74
75         String expectedKafkaJaasConfig = "jaas_config";
76         String actualKafkaJaasConfig = (cbsConfigurationForAutoCommitDisabled.getKafkaConfig().kafkaJaasConfig());
77
78         String expectedAaiUserName = "AAI";
79         String actualAaiUserName = (cbsConfigurationForAutoCommitDisabled.getAaiClientConfiguration().aaiUserName());
80
81         String expectedConsumerGroup = "OpenDCAE-c12";
82         String actualConsumerGroup = (cbsConfigurationForAutoCommitDisabled.getMessageRouterSubscribeRequest()
83                 .consumerGroup());
84
85         assertEquals(expectedKafKaBoostrapServerConfig, actualKafkaBoostrapServerConfig,
86                 "Expected value of KafKaBoostrapServerConfig is not matching with actual value");
87         assertEquals(expectedGroupIdConfig, actualGroupIdConfig,
88                 "Expected value of GroupIdConfig is not matching with actual value");
89         assertEquals(expectedKafkaSecurityProtocol, actualKafkaSecurityProtocol,
90                 "Expected value of KafkaSecurityProtocol is not matching with actual value");
91         assertEquals(expectedKafkaSaslMechanism, actualKafkaSaslMechanism,
92                 "Expected value of KafkaSaslMechanism is not matching with actual value");
93         assertEquals(expectedKafkaJaasConfig, actualKafkaJaasConfig,
94                 "Expected value of KafkaJaasConfig is not matching with actual value");
95         assertEquals(expectedAaiUserName, actualAaiUserName,
96                 "Expected value of AaiUserName is not matching with actual value");
97         assertEquals(expectedConsumerGroup, actualConsumerGroup,
98                 "Expected value of ConsumerGroup is not matching with actual value");
99
100         assertThat((cbsConfigurationForAutoCommitDisabled).getAaiClientConfiguration()).isNotNull();
101         assertThat((cbsConfigurationForAutoCommitDisabled).getMessageRouterPublisher()).isNotNull();
102         assertThat((cbsConfigurationForAutoCommitDisabled).getMessageRouterSubscriber()).isNotNull();
103         assertThat((cbsConfigurationForAutoCommitDisabled).getMessageRouterPublishRequest()).isNotNull();
104         assertThat((cbsConfigurationForAutoCommitDisabled).getMessageRouterSubscribeRequest()).isNotNull();
105         assertThat((cbsConfigurationForAutoCommitDisabled).getMessageRouterUpdatePublishRequest()).isNotNull();
106
107     }
108
109 }