d1cc869835b9a3285b0ebb2d087445dc357d03f7
[sdc.git] /
1 package org.openecomp.sdc.be.components.distribution.engine;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7 import java.util.concurrent.atomic.AtomicBoolean;
8
9 import org.junit.Test;
10 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
11 import org.openecomp.sdc.be.components.BeConfDependentTest;
12 import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
13 import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
14 import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
15 import org.openecomp.sdc.be.config.ConfigurationManager;
16 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
17 import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
18 import org.openecomp.sdc.be.dao.impl.AuditingDao;
19 import org.openecomp.sdc.be.impl.ComponentsUtils;
20 import org.openecomp.sdc.be.info.OperationalEnvInfo;
21 import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
22 import org.openecomp.sdc.common.datastructure.Wrapper;
23 import org.springframework.test.util.ReflectionTestUtils;
24
25 import fj.data.Either;
26 import mockit.Deencapsulation;
27
28 public class EnvironmentsEngineTest extends BeConfDependentTest {
29
30         private EnvironmentsEngine createTestSubject() {
31                 return new EnvironmentsEngine(new DmaapConsumer(new ExecutorFactory(), new DmaapClientFactory()),
32                                 new OperationalEnvironmentDao(), new DME2EndpointIteratorCreator(), new AaiRequestHandler(),
33                                 new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao())),
34                                 new CambriaHandler(), new DistributionEngineClusterHealth(), new DistributionCompleteReporterMock());
35         }
36
37         @Test
38         public void testInit() throws Exception {
39                 EnvironmentsEngine testSubject;
40
41                 // default test
42                 testSubject = createTestSubject();
43                 Deencapsulation.invoke(testSubject, "init");
44         }
45
46         @Test
47         public void testConnectUebTopicTenantIsolation() throws Exception {
48                 EnvironmentsEngine testSubject;
49                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
50                 opEnvEntry.setEnvironmentId("mock");
51                 AtomicBoolean status = null;
52                 Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
53                 Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
54
55                 // default test
56                 testSubject = createTestSubject();
57                 testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
58         }
59
60         @Test
61         public void testConnectUebTopic() throws Exception {
62                 EnvironmentsEngine testSubject;
63                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
64                 AtomicBoolean status = new AtomicBoolean(true);
65                 Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
66                 Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
67
68                 // default test
69                 testSubject = createTestSubject();
70                 Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
71                                 envNamePerPollingTask);
72         }
73
74         @Test
75         public void testHandleMessage() throws Exception {
76                 EnvironmentsEngine testSubject;
77                 String notification = "";
78                 boolean result;
79
80                 // default test
81                 testSubject = createTestSubject();
82                 result = testSubject.handleMessage(notification);
83         }
84
85         @Test
86         public void testHandleMessageLogic() throws Exception {
87                 EnvironmentsEngine testSubject;
88                 String notification = "";
89                 boolean result;
90
91                 // default test
92                 testSubject = createTestSubject();
93                 result = testSubject.handleMessageLogic(notification);
94         }
95
96         @Test
97         public void testValidateNotification() throws Exception {
98                 EnvironmentsEngine testSubject;
99                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
100                 errorWrapper.setInnerElement(true);
101                 IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
102                 IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();
103
104                 // default test
105                 testSubject = createTestSubject();
106                 Deencapsulation.invoke(testSubject, "validateNotification",
107                                 errorWrapper, notificationData, auditNotificationData);
108         }
109
110         @Test(expected = NullPointerException.class)
111         public void testSaveEntryWithFailedStatus() throws Exception {
112                 EnvironmentsEngine testSubject;
113                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
114                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
115
116                 // default test
117                 testSubject = createTestSubject();
118                 Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
119         }
120
121         @Test
122         public void testRetrieveUebAddressesFromAftDme() throws Exception {
123                 EnvironmentsEngine testSubject;
124                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
125                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
126
127                 // default test
128                 testSubject = createTestSubject();
129                 Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
130         }
131
132         @Test
133         public void testCreateUebKeys() throws Exception {
134                 EnvironmentsEngine testSubject;
135                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
136                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
137
138                 Set<String> dmaapUebAddress = new HashSet<>();
139                 dmaapUebAddress.add("mock");
140                 opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
141
142                 // default test
143                 testSubject = createTestSubject();
144                 Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
145         }
146
147         /*@Test
148         public void testRetrieveOpEnvInfoFromAAI() throws Exception {
149                 EnvironmentsEngine testSubject;
150                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
151                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
152                 opEnvEntry.setEnvironmentId("mock");
153
154                 // default test
155                 testSubject = createTestSubject();
156                 Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI",
157                                 Wrapper.class, opEnvEntry);
158         }*/
159
160         /*
161          * @Test public void testSaveEntryWithInProgressStatus() throws Exception {
162          * EnvironmentsEngine testSubject; Wrapper<Boolean> errorWrapper = new
163          * Wrapper<>(); Wrapper<OperationalEnvironmentEntry> opEnvEntryWrapper = new
164          * Wrapper<>(); IDmaapNotificationData notificationData = new
165          * IDmaapNotificationDataMock();
166          * 
167          * // default test testSubject = createTestSubject();
168          * Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus",
169          * errorWrapper, opEnvEntryWrapper, notificationData); }
170          */
171
172         /*
173          * @Test public void testValidateState() throws Exception { EnvironmentsEngine
174          * testSubject; Wrapper<Boolean> errorWrapper = null; IDmaapNotificationDataMock
175          * notificationData = new IDmaapNotificationDataMock();
176          * notificationData.setOperationalEnvironmentId("mock");
177          * 
178          * // default test testSubject = createTestSubject();
179          * Deencapsulation.invoke(testSubject, "validateState", Wrapper.class,
180          * notificationData); }
181          */
182
183         @Test
184         public void testValidateActionType() throws Exception {
185                 EnvironmentsEngine testSubject;
186                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
187                 IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
188                 notificationData.setDmaapActionEnum(DmaapActionEnum.DELETE);
189                 // default test
190                 testSubject = createTestSubject();
191                 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
192
193                 notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
194                 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
195         }
196
197         @Test(expected=NullPointerException.class)
198         public void testValidateEnvironmentType() throws Exception {
199                 EnvironmentsEngine testSubject;
200                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
201                 IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
202                 IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();
203                 auditNotificationData.operationalEnvironmentName = "mock";
204                 notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.ECOMP;
205
206                 // default test
207                 testSubject = createTestSubject();
208                 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
209                                 auditNotificationData);
210
211                 notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.UNKONW;
212                 notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
213                 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
214                                 auditNotificationData);
215         }
216
217         @Test
218         public void testMap2OpEnvKey() throws Exception {
219                 EnvironmentsEngine testSubject;
220                 OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
221                 String result;
222
223                 // default test
224                 testSubject = createTestSubject();
225                 result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
226         }
227
228         @Test
229         public void testReadEnvFromConfig() throws Exception {
230                 EnvironmentsEngine testSubject;
231                 OperationalEnvironmentEntry result;
232
233                 // default test
234                 testSubject = createTestSubject();
235                 result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
236         }
237
238         @Test
239         public void testCreateUebTopicsForEnvironment() throws Exception {
240                 EnvironmentsEngine testSubject;
241                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
242
243                 // default test
244                 testSubject = createTestSubject();
245                 testSubject.createUebTopicsForEnvironment(opEnvEntry);
246         }
247
248         @Test
249         public void testSetConfigurationManager() throws Exception {
250                 EnvironmentsEngine testSubject;
251                 ConfigurationManager configurationManager = null;
252
253                 // default test
254                 testSubject = createTestSubject();
255                 Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
256         }
257
258         @Test
259         public void testGetEnvironments() throws Exception {
260                 EnvironmentsEngine testSubject;
261                 Map<String, OperationalEnvironmentEntry> result;
262
263                 // default test
264                 testSubject = createTestSubject();
265                 result = testSubject.getEnvironments();
266         }
267
268         @Test
269         public void testIsInMap() throws Exception {
270                 EnvironmentsEngine testSubject;
271                 OperationalEnvironmentEntry env = new OperationalEnvironmentEntry();
272                 env.setEnvironmentId("mock");
273                 Map<String, OperationalEnvironmentEntry> mockEnvironments = new HashMap<>();
274                 mockEnvironments.put("mock", new OperationalEnvironmentEntry());
275                 boolean result;
276
277                 // default test
278                 testSubject = createTestSubject();
279                 ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
280                 result = testSubject.isInMap(env);
281         }
282
283         private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
284                 @Override
285                 public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
286                         // TODO Auto-generated method stub
287
288                 }
289         }
290
291         private class IDmaapNotificationDataMock implements IDmaapNotificationData {
292
293                 private String operationalEnvironmentId;
294                 private OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum;
295                 private DmaapActionEnum dmaapActionEnum;
296
297                 public OperationaEnvironmentTypeEnum getOperationaEnvironmentTypeEnum() {
298                         return operationaEnvironmentTypeEnum;
299                 }
300
301                 public void setOperationaEnvironmentTypeEnum(OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum) {
302                         this.operationaEnvironmentTypeEnum = operationaEnvironmentTypeEnum;
303                 }
304
305                 public DmaapActionEnum getDmaapActionEnum() {
306                         return dmaapActionEnum;
307                 }
308
309                 public void setDmaapActionEnum(DmaapActionEnum dmaapActionEnum) {
310                         this.dmaapActionEnum = dmaapActionEnum;
311                 }
312
313                 public void setOperationalEnvironmentId(String operationalEnvironmentId) {
314                         this.operationalEnvironmentId = operationalEnvironmentId;
315                 }
316
317                 @Override
318                 public String getOperationalEnvironmentId() {
319                         return operationalEnvironmentId;
320                 }
321
322                 @Override
323                 public OperationaEnvironmentTypeEnum getOperationalEnvironmentType() {
324                         return operationaEnvironmentTypeEnum;
325                 }
326
327                 @Override
328                 public DmaapActionEnum getAction() {
329                         return dmaapActionEnum;
330                 }
331         }
332
333         private class IDmaapAuditNotificationDataMock implements IDmaapAuditNotificationData {
334                 private String operationalEnvironmentName;
335                 private String tenantContext;
336
337                 @Override
338                 public String getOperationalEnvironmentName() {
339                         return null;
340                 }
341
342                 @Override
343                 public String getTenantContext() {
344                         return null;
345                 }
346
347         }
348 }