b4c7fff858f0e613526ec9452c0ea6604894ef49
[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_DMAAP_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 DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase<DmaapTopicSink> {
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
66     @Test
67     public void testBuildProperties() {
68         super.testBuildProperties();
69         super.testBuildProperties_Variations();
70         super.testBuildProperties_Multiple();
71
72         // check sink-specific parameters that were used
73         BusTopicParams params = factory.params.getFirst();
74         assertEquals(MY_PARTITION, params.getPartitionId());
75     }
76
77     @Test
78     public void testDestroyString_testGet_testInventory() {
79         super.testDestroyString_testGet_testInventory();
80         super.testDestroyString_Ex();
81     }
82
83     @Test
84     public void testDestroy() {
85         super.testDestroy();
86     }
87
88     @Test
89     public void testGet() {
90         super.testGet_Ex();
91     }
92
93     @Test
94     public void testToString() {
95         assertTrue(factory.toString().startsWith("IndexedDmaapTopicSinkFactory ["));
96     }
97
98     @Override
99     protected void initFactory() {
100         if (factory != null) {
101             factory.destroy();
102         }
103
104         factory = new SinkFactory();
105     }
106
107     @Override
108     protected List<DmaapTopicSink> buildTopics(Properties properties) {
109         return factory.build(properties);
110     }
111
112     @Override
113     protected DmaapTopicSink buildTopic(BusTopicParams params) {
114         return factory.build(params);
115     }
116
117     @Override
118     protected DmaapTopicSink buildTopic(List<String> servers, String topic) {
119         return factory.build(servers, topic);
120     }
121
122     @Override
123     protected void destroyFactory() {
124         factory.destroy();
125     }
126
127     @Override
128     protected void destroyTopic(String topic) {
129         factory.destroy(topic);
130     }
131
132     @Override
133     protected List<DmaapTopicSink> getInventory() {
134         return factory.inventory();
135     }
136
137     @Override
138     protected DmaapTopicSink getTopic(String topic) {
139         return factory.get(topic);
140     }
141
142     @Override
143     protected BusTopicParams getLastParams() {
144         return factory.params.getLast();
145     }
146
147     @Override
148     protected TopicPropertyBuilder makePropBuilder() {
149         return new DmaapTopicPropertyBuilder(PROPERTY_DMAAP_SINK_TOPICS);
150     }
151
152     /**
153      * Factory that records the parameters of all of the sinks it creates.
154      */
155     private static class SinkFactory extends IndexedDmaapTopicSinkFactory {
156         private Deque<BusTopicParams> params = new LinkedList<>();
157
158         @Override
159         protected DmaapTopicSink makeSink(BusTopicParams busTopicParams) {
160             params.add(busTopicParams);
161             return super.makeSink(busTopicParams);
162         }
163     }
164 }