2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2023 Nordix Foundation. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.kafka;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Properties;
29 import lombok.SneakyThrows;
31 public class TestConfiguration implements org.onap.dmaap.kafka.IKafkaConfig {
33 private Properties loadProperties(String configFileName) throws IOException {
34 Properties configuration = new Properties();
35 try (InputStream inputStream = TestConfiguration.class
37 .getResourceAsStream(configFileName)) {
38 configuration.load(inputStream);
43 private final Properties testConfig;
44 private List<String> bootstrapServers;
45 private List<String> consumerTopics;
48 public TestConfiguration(String configFilename) {
49 testConfig = loadProperties(configFilename);
50 bootstrapServers = new ArrayList<>(Arrays.asList(((String) testConfig.get("kafka.kafkaBootstrapServers")).split(",")));
54 public List<String> getKafkaBootstrapServers() {
55 return bootstrapServers;
58 public void setBootstrapServers(List<String> newBootstrapList) {
59 bootstrapServers = newBootstrapList;
63 public String getKafkaSaslMechanism() {
68 public String getKafkaSaslJaasConfig() {
69 return "org.apache.kafka.common.security.plain.PlainLoginModule required username=admin password=admin-secret;";
73 public int getPollingTimeout() {
74 return Integer.parseInt((String) testConfig.get("kafka.pollingTimeout"));
78 public String getConsumerGroup() {
79 return (String) testConfig.get("kafka.consumerGroup");
83 public String getConsumerID() {
84 return (String) testConfig.get("kafka.consumerID");
88 public List<String> getConsumerTopics() {
89 consumerTopics = new ArrayList<>();
90 String topicString = (String) testConfig.get("kafka.consumerTopics");
91 if (topicString != null) {
92 consumerTopics.addAll(Arrays.asList((topicString).split(",")));
94 return consumerTopics;
97 public void setConsumerTopics(List<String> newTopics) {
98 this.consumerTopics = newTopics;
102 public List<String> getProducerTopics() {
103 List<String> producerTopics = new ArrayList<>();
104 String topicString = (String) testConfig.get("kafka.producerTopics");
105 if (topicString != null) {
106 producerTopics.addAll(Arrays.asList((topicString).split(",")));
108 return producerTopics;