2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.common.endpoints.event.comm.bus;
21 import static org.assertj.core.api.Assertions.assertThatThrownBy;
23 import java.util.List;
24 import org.apache.kafka.clients.ClientUtils;
25 import org.junit.jupiter.api.Test;
26 import org.mockito.Mock;
27 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
29 class IndexedKafkaTopicSourceFactoryTest {
31 private IndexedKafkaTopicSourceFactory factory;
34 ClientUtils mockClientUtils;
38 factory = new IndexedKafkaTopicSourceFactory();
39 BusTopicParams params = new BusTopicParams();
41 // set servers to null
42 params.setServers(null);
43 assertThatThrownBy(() -> factory.build(params))
44 .isInstanceOf(IllegalArgumentException.class)
45 .hasMessageContaining("KAFKA Server(s) must be provided");
47 // set servers to empty
48 params.setServers(List.of());
49 assertThatThrownBy(() -> factory.build(params))
50 .isInstanceOf(IllegalArgumentException.class)
51 .hasMessageContaining("KAFKA Server(s) must be provided");
53 List<String> servers = List.of("kafka:9092", "kafka:29092");
54 params.setServers(servers);
57 params.setTopic(null);
58 assertThatThrownBy(() -> factory.build(params))
59 .isInstanceOf(IllegalArgumentException.class)
60 .hasMessageContaining("A topic must be provided");
64 assertThatThrownBy(() -> factory.build(params))
65 .isInstanceOf(IllegalArgumentException.class)
66 .hasMessageContaining("A topic must be provided");
68 params.setTopic("topic01");
70 assertThatThrownBy(() -> factory.build(servers, "topic1"))
71 .isInstanceOf(IllegalArgumentException.class)
72 .hasMessageContaining("cannot create topic");