3 * * ============LICENSE_START=======================================================
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
12 * * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.blueprintgenerator.service.common.kafka;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.LinkedHashMap;
32 import org.junit.Test;
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;
41 @RunWith(SpringJUnit4ClassRunner.class)
42 @ContextConfiguration(classes = {KafkaStreamService.class, BlueprintHelperService.class},
43 initializers = ConfigFileApplicationContextInitializer.class)
44 public class KafkaStreamServiceTest {
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";
53 private KafkaStreamService kafkaStreamService;
56 public void createCorrectStreamCommonInputs() {
58 Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
59 .createStreamPublishInputs("test_stream_name");
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");
65 assertNotNull(kafka_bootstrap_servers);
66 assertNotNull(kafka_username);
67 assertNotNull(kafka_password);
69 assertNotNull(kafka_bootstrap_servers.get(DEFAULT_KEY));
70 assertNotNull(kafka_username.get(DEFAULT_KEY));
71 assertNotNull(kafka_password.get(DEFAULT_KEY));
75 public void createCorrectStreamPublishInput() {
76 Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
77 .createStreamPublishInputs(TEST_STREAM_NAME);
79 LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX);
81 assertNotNull(kafka_stream_name);
83 assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
87 public void createCorrectStreamSubscribeInput() {
88 Map<String, LinkedHashMap<String, Object>> publishInputs = kafkaStreamService
89 .createStreamSubscribeInputs(TEST_STREAM_NAME);
91 LinkedHashMap<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX);
93 assertNotNull(kafka_stream_name);
95 assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
99 public void createCorrectPublishAppConfig() {
100 Map<String, KafkaStream> appPropertiesPublish = kafkaStreamService
101 .createAppPropertiesPublish(TEST_STREAM_NAME);
103 KafkaStream kafkaStream = appPropertiesPublish.get(TEST_STREAM_NAME);
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));
113 public void createCorrectSubscribeAppConfig() {
114 Map<String, KafkaStream> appPropertiesSubscribe = kafkaStreamService
115 .createAppPropertiesSubscribe(TEST_STREAM_NAME);
117 KafkaStream kafkaStream = appPropertiesSubscribe.get(TEST_STREAM_NAME);
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));