cad3b71732149a8a546a85a48322e0ba8d5c706c
[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.LinkedHashMap;
31 import java.util.Map;
32 import org.junit.Test;
33
34 import org.junit.runner.RunWith;
35 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
38 import org.springframework.test.context.ContextConfiguration;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40
41 @RunWith(SpringJUnit4ClassRunner.class)
42 @ContextConfiguration(classes = {KafkaStreamService.class, BlueprintHelperService.class},
43     initializers = ConfigFileApplicationContextInitializer.class)
44 public class KafkaStreamServiceTest {
45
46     private static final String TEST_STREAM_NAME = "test_stream_name";
47     private static final String PUBLISH_URL_SUFFIX = "_publish_url";
48     private static final String SUBSCRIBE_URL_SUFFIX = "_subscribe_url";
49     private static final String DEFAULT_KEY = "default";
50     private static final String KAFKA_TYPE = "kafka";
51
52     @Autowired
53     private KafkaStreamService kafkaStreamService;
54
55     @Test
56     public void createCorrectStreamCommonInputs() {
57
58         Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
59             .createStreamPublishInputs("test_stream_name");
60
61         LinkedHashMap<String, Object> kafka_bootstrap_servers = publishInputs.get("kafka_bootstrap_servers");
62         LinkedHashMap<String, Object> kafka_username = publishInputs.get("kafka_username");
63         LinkedHashMap<String, Object> kafka_password = publishInputs.get("kafka_password");
64
65         assertNotNull(kafka_bootstrap_servers);
66         assertNotNull(kafka_username);
67         assertNotNull(kafka_password);
68
69         assertNotNull(kafka_bootstrap_servers.get(DEFAULT_KEY));
70         assertNotNull(kafka_username.get(DEFAULT_KEY));
71         assertNotNull(kafka_password.get(DEFAULT_KEY));
72     }
73
74     @Test
75     public void createCorrectStreamPublishInput() {
76         Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
77             .createStreamPublishInputs(TEST_STREAM_NAME);
78
79         LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX);
80
81         assertNotNull(kafka_stream_name);
82
83         assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
84     }
85
86     @Test
87     public void createCorrectStreamSubscribeInput() {
88         Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
89             .createStreamSubscribeInputs(TEST_STREAM_NAME);
90
91         LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX);
92
93         assertNotNull(kafka_stream_name);
94
95         assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
96     }
97
98     @Test
99     public void createCorrectPublishAppConfig() {
100         Map<String, KafkaStream> appPropertiesPublish = kafkaStreamService
101             .createAppPropertiesPublish(TEST_STREAM_NAME);
102
103         KafkaStream kafkaStream = appPropertiesPublish.get(TEST_STREAM_NAME);
104
105         assertEquals(KAFKA_TYPE, kafkaStream.getType());
106         assertNotNull(kafkaStream.getAafCredential());
107         assertNotNull(kafkaStream.getKafkaInfo());
108         assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX));
109
110     }
111
112     @Test
113     public void createCorrectSubscribeAppConfig() {
114         Map<String, KafkaStream> appPropertiesSubscribe = kafkaStreamService
115             .createAppPropertiesSubscribe(TEST_STREAM_NAME);
116
117         KafkaStream kafkaStream = appPropertiesSubscribe.get(TEST_STREAM_NAME);
118
119         assertEquals(KAFKA_TYPE, kafkaStream.getType());
120         assertNotNull(kafkaStream.getAafCredential());
121         assertNotNull(kafkaStream.getKafkaInfo());
122         assertTrue(kafkaStream.getKafkaInfo().toString().contains(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX));
123
124     }
125 }