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