2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.assertTrue;
25 import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperties.PROPERTY_DMAAP_SINK_TOPICS;
27 import java.util.Deque;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Properties;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
36 public class DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase<DmaapTopicSink> {
38 private SinkFactory factory;
41 * Creates the object to be tested.
47 factory = new SinkFactory();
51 public void tearDown() {
56 public void testBuildBusTopicParams() {
57 super.testBuildBusTopicParams();
58 super.testBuildBusTopicParams_Ex();
62 public void testBuildListOfStringString() {
63 super.testBuildListOfStringString();
67 public void testBuildProperties() {
68 super.testBuildProperties();
69 super.testBuildProperties_Variations();
70 super.testBuildProperties_Multiple();
72 // check sink-specific parameters that were used
73 BusTopicParams params = factory.params.getFirst();
74 assertEquals(MY_PARTITION, params.getPartitionId());
78 public void testDestroyString_testGet_testInventory() {
79 super.testDestroyString_testGet_testInventory();
80 super.testDestroyString_Ex();
84 public void testDestroy() {
89 public void testGet() {
94 public void testToString() {
95 assertTrue(factory.toString().startsWith("IndexedDmaapTopicSinkFactory ["));
99 protected void initFactory() {
100 if (factory != null) {
104 factory = new SinkFactory();
108 protected List<DmaapTopicSink> buildTopics(Properties properties) {
109 return factory.build(properties);
113 protected DmaapTopicSink buildTopic(BusTopicParams params) {
114 return factory.build(params);
118 protected DmaapTopicSink buildTopic(List<String> servers, String topic) {
119 return factory.build(servers, topic);
123 protected void destroyFactory() {
128 protected void destroyTopic(String topic) {
129 factory.destroy(topic);
133 protected List<DmaapTopicSink> getInventory() {
134 return factory.inventory();
138 protected DmaapTopicSink getTopic(String topic) {
139 return factory.get(topic);
143 protected BusTopicParams getLastParams() {
144 return factory.params.getLast();
148 protected TopicPropertyBuilder makePropBuilder() {
149 return new DmaapTopicPropertyBuilder(PROPERTY_DMAAP_SINK_TOPICS);
153 * Factory that records the parameters of all of the sinks it creates.
155 private static class SinkFactory extends IndexedDmaapTopicSinkFactory {
156 private Deque<BusTopicParams> params = new LinkedList<>();
159 protected DmaapTopicSink makeSink(BusTopicParams busTopicParams) {
160 params.add(busTopicParams);
161 return super.makeSink(busTopicParams);