10d61f6056023d205064cfc7862fc2b2cc664407
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.common.endpoints.event.comm.bus;
22
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;
26
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;
35
36 public class UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSink> {
37
38     private SinkFactory factory;
39
40     /**
41      * Creates the object to be tested.
42      */
43     @Before
44     public void setUp() {
45         super.setUp();
46
47         factory = new SinkFactory();
48     }
49
50     @After
51     public void tearDown() {
52         factory.destroy();
53     }
54
55     @Test
56     public void testBuildBusTopicParams() {
57         super.testBuildBusTopicParams();
58         super.testBuildBusTopicParams_Ex();
59     }
60
61     @Test
62     public void testBuildListOfStringString() {
63         super.testBuildListOfStringString();
64
65         // check parameters that were used
66         BusTopicParams params = getLastParams();
67         assertEquals(false, params.isAllowSelfSignedCerts());
68     }
69
70     @Test
71     public void testBuildProperties() {
72         super.testBuildProperties();
73         super.testBuildProperties_Variations();
74         super.testBuildProperties_Multiple();
75         
76         initFactory();
77
78         assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
79
80         BusTopicParams params = getLastParams();
81         assertEquals(MY_PARTITION, params.getPartitionId());
82     }
83
84     @Test
85     public void testDestroyString_testGet_testInventory() {
86         super.testDestroyString_testGet_testInventory();
87         super.testDestroyString_Ex();
88     }
89
90     @Test
91     public void testDestroy() {
92         super.testDestroy();
93     }
94
95     @Test
96     public void testGet() {
97         super.testGet_Ex();
98     }
99
100     @Test
101     public void testToString() {
102         assertTrue(factory.toString().startsWith("IndexedUebTopicSinkFactory ["));
103     }
104
105     @Override
106     protected void initFactory() {
107         if (factory != null) {
108             factory.destroy();
109         }
110
111         factory = new SinkFactory();
112     }
113
114     @Override
115     protected List<UebTopicSink> buildTopics(Properties properties) {
116         return factory.build(properties);
117     }
118
119     @Override
120     protected UebTopicSink buildTopic(BusTopicParams params) {
121         return factory.build(params);
122     }
123
124     @Override
125     protected UebTopicSink buildTopic(List<String> servers, String topic) {
126         return factory.build(servers, topic);
127     }
128
129     @Override
130     protected void destroyFactory() {
131         factory.destroy();
132     }
133
134     @Override
135     protected void destroyTopic(String topic) {
136         factory.destroy(topic);
137     }
138
139     @Override
140     protected List<UebTopicSink> getInventory() {
141         return factory.inventory();
142     }
143
144     @Override
145     protected UebTopicSink getTopic(String topic) {
146         return factory.get(topic);
147     }
148
149     @Override
150     protected BusTopicParams getLastParams() {
151         return factory.params.getLast();
152     }
153
154     @Override
155     protected TopicPropertyBuilder makePropBuilder() {
156         return new UebTopicPropertyBuilder(PROPERTY_UEB_SINK_TOPICS);
157     }
158
159     /**
160      * Factory that records the parameters of all of the sinks it creates.
161      */
162     private static class SinkFactory extends IndexedUebTopicSinkFactory {
163         private Deque<BusTopicParams> params = new LinkedList<>();
164
165         @Override
166         protected UebTopicSink makeSink(BusTopicParams busTopicParams) {
167             params.add(busTopicParams);
168             return super.makeSink(busTopicParams);
169         }
170     }
171 }