2 * ============LICENSE_START=======================================================
3 * ONAP Policy Engine - Common Modules
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. 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.policy.common.endpoints.event.comm.bus;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_KAFKA_SOURCE_TOPICS;
28 import java.util.Deque;
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Properties;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.endpoints.event.comm.Topic;
36 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
37 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
39 public class KafkaTopicSourceFactoryTest extends KafkaTopicFactoryTestBase<KafkaTopicSource> {
41 private SourceFactory factory;
44 * Creates the object to be tested.
51 factory = new SourceFactory();
55 public void tearDown() {
61 public void testBuildBusTopicParams() {
62 super.testBuildBusTopicParams_Ex();
67 public void testBuildProperties() {
71 List<KafkaTopicSource> topics = buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
72 assertEquals(1, topics.size());
73 assertEquals(MY_TOPIC, topics.get(0).getTopic());
78 public void testDestroyString_testGet_testInventory() {
79 super.testDestroyString_Ex();
83 public void testGet() {
88 public void testToString() {
89 assertTrue(factory.toString().startsWith("IndexedKafkaTopicSourceFactory ["));
93 protected void initFactory() {
94 if (factory != null) {
98 factory = new SourceFactory();
102 protected List<KafkaTopicSource> buildTopics(Properties properties) {
103 return factory.build(properties);
107 protected KafkaTopicSource buildTopic(BusTopicParams params) {
108 return factory.build(params);
112 protected KafkaTopicSource buildTopic(List<String> servers, String topic) {
113 return factory.build(servers, topic);
117 protected void destroyFactory() {
122 protected void destroyTopic(String topic) {
123 factory.destroy(topic);
127 protected List<KafkaTopicSource> getInventory() {
128 return factory.inventory();
132 protected KafkaTopicSource getTopic(String topic) {
133 return factory.get(topic);
137 protected BusTopicParams getLastParams() {
138 return factory.params.getLast();
142 protected TopicPropertyBuilder makePropBuilder() {
143 return new KafkaTopicPropertyBuilder(PROPERTY_KAFKA_SOURCE_TOPICS);
147 * Factory that records the parameters of all of the sources it creates.
149 private static class SourceFactory extends IndexedKafkaTopicSourceFactory {
150 private Deque<BusTopicParams> params = new LinkedList<>();
153 protected KafkaTopicSource makeSource(BusTopicParams busTopicParams) {
154 params.add(busTopicParams);
155 return super.makeSource(busTopicParams);