Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / test / java / org / onap / blueprintgenerator / service / common / kafka / KafkaStreamServiceTest.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2021 Nokia Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.service.common.kafka;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.Map;
31 import org.junit.Test;
32
33 import org.junit.runner.RunWith;
34 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
39
40 @RunWith(SpringJUnit4ClassRunner.class)
41 @ContextConfiguration(classes = {KafkaStreamService.class, BlueprintHelperService.class},
42     initializers = ConfigFileApplicationContextInitializer.class)
43 public class KafkaStreamServiceTest {
44
45     private static final String TEST_STREAM_NAME = "test_stream_name";
46     private static final String PUBLISH_URL_SUFFIX = "_publish_url";
47     private static final String SUBSCRIBE_URL_SUFFIX = "_subscribe_url";
48     private static final String DEFAULT_KEY = "default";
49     private static final String KAFKA_TYPE = "kafka";
50
51     @Autowired
52     private KafkaStreamService kafkaStreamService;
53
54     @Test
55     public void createCorrectStreamCommonInputs() {
56
57         Map<String, Map<String, Object>> publishInputs = kafkaStreamService
58             .createStreamPublishInputs("test_stream_name");
59
60         Map<String, Object> kafka_bootstrap_servers = publishInputs.get("kafka_bootstrap_servers");
61         Map<String, Object> kafka_username = publishInputs.get("kafka_username");
62         Map<String, Object> kafka_password = publishInputs.get("kafka_password");
63
64         assertNotNull(kafka_bootstrap_servers);
65         assertNotNull(kafka_username);
66         assertNotNull(kafka_password);
67
68         assertNotNull(kafka_bootstrap_servers.get(DEFAULT_KEY));
69         assertNotNull(kafka_username.get(DEFAULT_KEY));
70         assertNotNull(kafka_password.get(DEFAULT_KEY));
71     }
72
73     @Test
74     public void createCorrectStreamPublishInput() {
75         Map<String, Map<String, Object>> publishInputs = kafkaStreamService
76             .createStreamPublishInputs(TEST_STREAM_NAME);
77
78         Map<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX);
79
80         assertNotNull(kafka_stream_name);
81
82         assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
83     }
84
85     @Test
86     public void createCorrectStreamSubscribeInput() {
87         Map<String, Map<String, Object>> publishInputs = kafkaStreamService
88             .createStreamSubscribeInputs(TEST_STREAM_NAME);
89
90         Map<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX);
91
92         assertNotNull(kafka_stream_name);
93
94         assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
95     }
96
97     @Test
98     public void createCorrectPublishAppConfig() {
99         Map<String, KafkaStream> appPropertiesPublish = kafkaStreamService
100             .createAppPropertiesPublish(TEST_STREAM_NAME);
101
102         KafkaStream kafkaStream = appPropertiesPublish.get(TEST_STREAM_NAME);
103
104         assertEquals(KAFKA_TYPE, kafkaStream.getType());
105         assertNotNull(kafkaStream.getAafCredential());
106         assertNotNull(kafkaStream.getKafkaInfo());
107         assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX));
108
109     }
110
111     @Test
112     public void createCorrectSubscribeAppConfig() {
113         Map<String, KafkaStream> appPropertiesSubscribe = kafkaStreamService
114             .createAppPropertiesSubscribe(TEST_STREAM_NAME);
115
116         KafkaStream kafkaStream = appPropertiesSubscribe.get(TEST_STREAM_NAME);
117
118         assertEquals(KAFKA_TYPE, kafkaStream.getType());
119         assertNotNull(kafkaStream.getAafCredential());
120         assertNotNull(kafkaStream.getKafkaInfo());
121         assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX));
122
123     }
124 }