2 * ============LICENSE_START=======================================================
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.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.
48 factory = new SinkFactory();
52 public void tearDown() {
58 public void testBuildBusTopicParams() {
59 super.testBuildBusTopicParams();
60 super.testBuildBusTopicParams_Ex();
65 public void testBuildListOfStringString() {
66 super.testBuildListOfStringString();
71 public void testBuildProperties() {
72 super.testBuildProperties();
73 super.testBuildProperties_Variations();
74 super.testBuildProperties_Multiple();
76 // check sink-specific parameters that were used
77 BusTopicParams params = factory.params.getFirst();
78 assertEquals(MY_PARTITION, params.getPartitionId());
83 public void testDestroyString_testGet_testInventory() {
84 super.testDestroyString_testGet_testInventory();
85 super.testDestroyString_Ex();
90 public void testDestroy() {
95 public void testGet() {
100 public void testToString() {
101 assertTrue(factory.toString().startsWith("IndexedDmaapTopicSinkFactory ["));
105 protected void initFactory() {
106 if (factory != null) {
110 factory = new SinkFactory();
114 protected List<DmaapTopicSink> buildTopics(Properties properties) {
115 return factory.build(properties);
119 protected DmaapTopicSink buildTopic(BusTopicParams params) {
120 return factory.build(params);
124 protected DmaapTopicSink buildTopic(List<String> servers, String topic) {
125 return factory.build(servers, topic);
129 protected void destroyFactory() {
134 protected void destroyTopic(String topic) {
135 factory.destroy(topic);
139 protected List<DmaapTopicSink> getInventory() {
140 return factory.inventory();
144 protected DmaapTopicSink getTopic(String topic) {
145 return factory.get(topic);
149 protected BusTopicParams getLastParams() {
150 return factory.params.getLast();
154 protected TopicPropertyBuilder makePropBuilder() {
155 return new DmaapTopicPropertyBuilder(PROPERTY_DMAAP_SINK_TOPICS);
159 * Factory that records the parameters of all of the sinks it creates.
161 private static class SinkFactory extends IndexedDmaapTopicSinkFactory {
162 private Deque<BusTopicParams> params = new LinkedList<>();
165 protected DmaapTopicSink makeSink(BusTopicParams busTopicParams) {
166 params.add(busTopicParams);
167 return super.makeSink(busTopicParams);