644219230b107644aa194ce05b5f50b8b4757c7d
[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.Before;
10 import org.junit.Test;
11 import org.mockito.InjectMocks;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.MockitoAnnotations;
15 import org.openecomp.sdc.be.components.BeConfDependentTest;
16 import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
17 import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
18 import org.openecomp.sdc.be.config.ConfigurationManager;
19 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
20 import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
21 import org.openecomp.sdc.be.datatypes.enums.EnvironmentStatusEnum;
22 import org.openecomp.sdc.be.impl.ComponentsUtils;
23 import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
24 import org.openecomp.sdc.common.datastructure.Wrapper;
25 import org.openecomp.sdc.common.http.client.api.HttpResponse;
26 import org.springframework.test.util.ReflectionTestUtils;
27
28 import com.att.nsa.apiClient.credentials.ApiCredential;
29
30 import fj.data.Either;
31 import groovyjarjarantlr.collections.List;
32 import mockit.Deencapsulation;
33
34 public class EnvironmentsEngineTest extends BeConfDependentTest {
35
36         @InjectMocks
37         EnvironmentsEngine testSubject;
38
39         @Mock
40         ComponentsUtils componentUtils;
41
42         @Mock
43         OperationalEnvironmentDao operationalEnvironmentDao;
44
45         @Mock
46         CambriaHandler cambriaHandler;
47         
48         @Mock
49         AaiRequestHandler aaiRequestHandler;
50         
51         @Before
52         public void setUpMocks() throws Exception {
53                 MockitoAnnotations.initMocks(this);
54         }
55
56         @Test
57         public void testInit() throws Exception {
58
59                 // default test
60                 Deencapsulation.invoke(testSubject, "init");
61         }
62
63         @Test
64         public void testConnectUebTopicTenantIsolation() throws Exception {
65                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
66                 opEnvEntry.setEnvironmentId("mock");
67                 AtomicBoolean status = null;
68                 Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
69                 Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
70
71                 // default test
72                 testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
73         }
74
75         @Test
76         public void testConnectUebTopic() throws Exception {
77                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
78                 AtomicBoolean status = new AtomicBoolean(true);
79                 Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
80                 Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
81
82                 // default test
83                 Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
84                                 envNamePerPollingTask);
85         }
86
87         @Test
88         public void testHandleMessage() throws Exception {
89                 String notification = "";
90                 boolean result;
91
92                 // default test
93                 result = testSubject.handleMessage(notification);
94         }
95
96         @Test
97         public void testHandleMessageLogic() throws Exception {
98                 String notification = "";
99                 boolean result;
100
101                 // default test
102                 result = testSubject.handleMessageLogic(notification);
103         }
104
105         @Test
106         public void testValidateNotification() throws Exception {
107                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
108                 errorWrapper.setInnerElement(true);
109                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
110                 IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
111
112                 // default test
113                 Deencapsulation.invoke(testSubject, "validateNotification", errorWrapper, notificationData,
114                                 auditNotificationData);
115         }
116
117         @Test
118         public void testSaveEntryWithFailedStatus() throws Exception {
119                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
120                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
121
122                 // default test
123                 Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
124         }
125
126         @Test
127         public void testRetrieveUebAddressesFromAftDme() throws Exception {
128                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
129                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
130
131                 // default test
132                 Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
133         }
134
135         @Test
136         public void testCreateUebKeys() throws Exception {
137                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
138                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
139
140                 Set<String> dmaapUebAddress = new HashSet<>();
141                 dmaapUebAddress.add("mock");
142                 opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
143                 
144                 Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.left(new ApiCredential("mock", "mock")));
145                 
146                 // default test
147                 Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
148         }
149         
150         @Test
151         public void testCreateUebKeysError() throws Exception {
152                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
153                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
154
155                 Set<String> dmaapUebAddress = new HashSet<>();
156                 dmaapUebAddress.add("mock");
157                 opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
158                 
159                 Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.right(new CambriaErrorResponse()));
160                 
161                 // default test
162                 Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
163         }
164         
165         @Test
166         public void testRetrieveOpEnvInfoFromAAI() throws Exception {
167                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
168                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
169                 opEnvEntry.setEnvironmentId("mock");
170                 Mockito.when(aaiRequestHandler.getOperationalEnvById(Mockito.nullable(String.class))).thenReturn(new HttpResponse<String>("{}", 200));
171                 // default test
172                 Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
173         }
174
175         @Test
176         public void testRetrieveOpEnvInfoFromAAIError() throws Exception {
177                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
178                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
179                 opEnvEntry.setEnvironmentId("mock");
180                 Mockito.when(aaiRequestHandler.getOperationalEnvById(Mockito.nullable(String.class))).thenReturn(new HttpResponse<String>("{}", 500));
181                 // default test
182                 Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
183         }
184         
185         @Test
186         public void testSaveEntryWithInProgressStatus() throws Exception {
187                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
188                 Wrapper<OperationalEnvironmentEntry> opEnvEntryWrapper = new Wrapper<>();
189                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
190
191                 Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus", errorWrapper, opEnvEntryWrapper,
192                                 notificationData);
193         }
194
195         @Test
196         public void testValidateStateGeneralError() throws Exception {
197                 Wrapper<Boolean> errorWrapper = null;
198                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
199
200                 Mockito.when(operationalEnvironmentDao.get(Mockito.nullable(String.class)))
201                                 .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
202
203                 Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
204         }
205
206         @Test
207         public void testValidateState() throws Exception {
208                 Wrapper<Boolean> errorWrapper = null;
209                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
210
211                 OperationalEnvironmentEntry a = new OperationalEnvironmentEntry();
212                 a.setStatus(EnvironmentStatusEnum.IN_PROGRESS.getName());
213                 Mockito.when(operationalEnvironmentDao.get(Mockito.nullable(String.class))).thenReturn(Either.left(a));
214
215                 Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
216         }
217
218         @Test
219         public void testValidateActionType() throws Exception {
220                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
221                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
222                 Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.DELETE);
223
224                 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
225         }
226
227         @Test
228         public void testValidateActionType2() throws Exception {
229                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
230                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
231                 Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.CREATE);
232
233                 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
234         }
235
236         @Test
237         public void testValidateEnvironmentType() throws Exception {
238                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
239                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
240                 IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
241                 Mockito.when(auditNotificationData.getOperationalEnvironmentName()).thenReturn("mock");
242                 Mockito.when(notificationData.getOperationalEnvironmentType()).thenReturn(OperationaEnvironmentTypeEnum.ECOMP);
243
244                 // default test
245                 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
246                                 auditNotificationData);
247         }
248
249         @Test
250         public void testValidateEnvironmentType1() throws Exception {
251                 Wrapper<Boolean> errorWrapper = new Wrapper<>();
252                 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
253                 IDmaapAuditNotificationData auditNotificationData = Mockito.mock(IDmaapAuditNotificationData.class);
254                 Mockito.when(auditNotificationData.getOperationalEnvironmentName()).thenReturn("mock");
255                 Mockito.when(notificationData.getOperationalEnvironmentType()).thenReturn(OperationaEnvironmentTypeEnum.UNKONW);
256                 Mockito.when(notificationData.getAction()).thenReturn(DmaapActionEnum.CREATE);
257
258                 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
259                                 auditNotificationData);
260         }
261
262         @Test
263         public void testMap2OpEnvKey() throws Exception {
264                 OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
265                 String result;
266
267                 // default test
268                 result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
269         }
270
271         @Test
272         public void testReadEnvFromConfig() throws Exception {
273                 OperationalEnvironmentEntry result;
274
275                 // default test
276                 result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
277         }
278
279         @Test
280         public void testCreateUebTopicsForEnvironment() throws Exception {
281                 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
282
283                 // default test
284                 testSubject.createUebTopicsForEnvironment(opEnvEntry);
285         }
286
287         @Test
288         public void testSetConfigurationManager() throws Exception {
289                 ConfigurationManager configurationManager = null;
290
291                 // default test
292                 Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
293         }
294
295         @Test
296         public void testGetEnvironments() throws Exception {
297                 Map<String, OperationalEnvironmentEntry> result;
298
299                 // default test
300                 result = testSubject.getEnvironments();
301         }
302
303         @Test
304         public void testIsInMap() throws Exception {
305                 OperationalEnvironmentEntry env = new OperationalEnvironmentEntry();
306                 env.setEnvironmentId("mock");
307                 Map<String, OperationalEnvironmentEntry> mockEnvironments = new HashMap<>();
308                 mockEnvironments.put("mock", new OperationalEnvironmentEntry());
309                 boolean result;
310
311                 // default test
312                 ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
313                 result = testSubject.isInMap(env);
314         }
315 }