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