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_UEB_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 UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSink> {
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();
68 // check parameters that were used
69 BusTopicParams params = getLastParams();
70 assertEquals(false, params.isAllowSelfSignedCerts());
75 public void testBuildProperties() {
76 super.testBuildProperties();
77 super.testBuildProperties_Variations();
78 super.testBuildProperties_Multiple();
82 assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
84 BusTopicParams params = getLastParams();
85 assertEquals(MY_PARTITION, params.getPartitionId());
90 public void testDestroyString_testGet_testInventory() {
91 super.testDestroyString_testGet_testInventory();
92 super.testDestroyString_Ex();
97 public void testDestroy() {
102 public void testGet() {
107 public void testToString() {
108 assertTrue(factory.toString().startsWith("IndexedUebTopicSinkFactory ["));
112 protected void initFactory() {
113 if (factory != null) {
117 factory = new SinkFactory();
121 protected List<UebTopicSink> buildTopics(Properties properties) {
122 return factory.build(properties);
126 protected UebTopicSink buildTopic(BusTopicParams params) {
127 return factory.build(params);
131 protected UebTopicSink buildTopic(List<String> servers, String topic) {
132 return factory.build(servers, topic);
136 protected void destroyFactory() {
141 protected void destroyTopic(String topic) {
142 factory.destroy(topic);
146 protected List<UebTopicSink> getInventory() {
147 return factory.inventory();
151 protected UebTopicSink getTopic(String topic) {
152 return factory.get(topic);
156 protected BusTopicParams getLastParams() {
157 return factory.params.getLast();
161 protected TopicPropertyBuilder makePropBuilder() {
162 return new UebTopicPropertyBuilder(PROPERTY_UEB_SINK_TOPICS);
166 * Factory that records the parameters of all of the sinks it creates.
168 private static class SinkFactory extends IndexedUebTopicSinkFactory {
169 private Deque<BusTopicParams> params = new LinkedList<>();
172 protected UebTopicSink makeSink(BusTopicParams busTopicParams) {
173 params.add(busTopicParams);
174 return super.makeSink(busTopicParams);