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;
31 import org.junit.Test;
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;
40 @RunWith(SpringJUnit4ClassRunner.class)
41 @ContextConfiguration(classes = {KafkaStreamService.class, BlueprintHelperService.class},
42 initializers = ConfigFileApplicationContextInitializer.class)
43 public class KafkaStreamServiceTest {
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";
52 private KafkaStreamService kafkaStreamService;
55 public void createCorrectStreamCommonInputs() {
57 Map<String, Map<String, Object>> publishInputs = kafkaStreamService
58 .createStreamPublishInputs("test_stream_name");
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");
64 assertNotNull(kafka_bootstrap_servers);
65 assertNotNull(kafka_username);
66 assertNotNull(kafka_password);
68 assertNotNull(kafka_bootstrap_servers.get(DEFAULT_KEY));
69 assertNotNull(kafka_username.get(DEFAULT_KEY));
70 assertNotNull(kafka_password.get(DEFAULT_KEY));
74 public void createCorrectStreamPublishInput() {
75 Map<String, Map<String, Object>> publishInputs = kafkaStreamService
76 .createStreamPublishInputs(TEST_STREAM_NAME);
78 Map<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + PUBLISH_URL_SUFFIX);
80 assertNotNull(kafka_stream_name);
82 assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
86 public void createCorrectStreamSubscribeInput() {
87 Map<String, Map<String, Object>> publishInputs = kafkaStreamService
88 .createStreamSubscribeInputs(TEST_STREAM_NAME);
90 Map<String, Object> kafka_stream_name = publishInputs.get(TEST_STREAM_NAME + SUBSCRIBE_URL_SUFFIX);
92 assertNotNull(kafka_stream_name);
94 assertNotNull(kafka_stream_name.get(DEFAULT_KEY));
98 public void createCorrectPublishAppConfig() {
99 Map<String, KafkaStream> appPropertiesPublish = kafkaStreamService
100 .createAppPropertiesPublish(TEST_STREAM_NAME);
102 KafkaStream kafkaStream = appPropertiesPublish.get(TEST_STREAM_NAME);
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));
112 public void createCorrectSubscribeAppConfig() {
113 Map<String, KafkaStream> appPropertiesSubscribe = kafkaStreamService
114 .createAppPropertiesSubscribe(TEST_STREAM_NAME);
116 KafkaStream kafkaStream = appPropertiesSubscribe.get(TEST_STREAM_NAME);
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));