1 package org.openecomp.sdc.be.components.distribution.engine;
3 import com.att.nsa.apiClient.credentials.ApiCredential;
5 import mockit.Deencapsulation;
6 import org.junit.Before;
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;
25 import java.util.HashMap;
26 import java.util.HashSet;
29 import java.util.concurrent.atomic.AtomicBoolean;
31 public class EnvironmentsEngineTest extends BeConfDependentTest {
34 EnvironmentsEngine testSubject;
37 ComponentsUtils componentUtils;
40 OperationalEnvironmentDao operationalEnvironmentDao;
43 CambriaHandler cambriaHandler;
46 AaiRequestHandler aaiRequestHandler;
49 public void setUpMocks() throws Exception {
50 MockitoAnnotations.initMocks(this);
54 public void testInit() throws Exception {
57 Deencapsulation.invoke(testSubject, "init");
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<>();
69 testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
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<>();
80 Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
81 envNamePerPollingTask);
85 public void testHandleMessage() throws Exception {
86 String notification = "";
90 result = testSubject.handleMessage(notification);
94 public void testHandleMessageLogic() throws Exception {
95 String notification = "";
99 result = testSubject.handleMessageLogic(notification);
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);
110 Deencapsulation.invoke(testSubject, "validateNotification", errorWrapper, notificationData,
111 auditNotificationData);
115 public void testSaveEntryWithFailedStatus() throws Exception {
116 Wrapper<Boolean> errorWrapper = new Wrapper<>();
117 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
120 Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
124 public void testRetrieveUebAddressesFromAftDme() throws Exception {
125 Wrapper<Boolean> errorWrapper = new Wrapper<>();
126 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
129 Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
133 public void testCreateUebKeys() throws Exception {
134 Wrapper<Boolean> errorWrapper = new Wrapper<>();
135 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
137 Set<String> dmaapUebAddress = new HashSet<>();
138 dmaapUebAddress.add("mock");
139 opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
141 Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.left(new ApiCredential("mock", "mock")));
144 Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
148 public void testCreateUebKeysError() throws Exception {
149 Wrapper<Boolean> errorWrapper = new Wrapper<>();
150 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
152 Set<String> dmaapUebAddress = new HashSet<>();
153 dmaapUebAddress.add("mock");
154 opEnvEntry.setDmaapUebAddress(dmaapUebAddress);
156 Mockito.when(cambriaHandler.createUebKeys(Mockito.any())).thenReturn(Either.right(new CambriaErrorResponse()));
159 Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
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));
169 Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
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));
179 Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI", new Wrapper<>(), opEnvEntry);
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);
188 Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus", errorWrapper, opEnvEntryWrapper,
193 public void testValidateStateGeneralError() throws Exception {
194 Wrapper<Boolean> errorWrapper = null;
195 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
197 Mockito.when(operationalEnvironmentDao.get(Mockito.nullable(String.class)))
198 .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
200 Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
204 public void testValidateState() throws Exception {
205 Wrapper<Boolean> errorWrapper = null;
206 IDmaapNotificationData notificationData = Mockito.mock(IDmaapNotificationData.class);
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));
212 Deencapsulation.invoke(testSubject, "validateState", new Wrapper<>(), notificationData);
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);
221 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
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);
230 Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
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);
242 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
243 auditNotificationData);
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);
255 Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
256 auditNotificationData);
260 public void testMap2OpEnvKey() throws Exception {
261 OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
265 result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
269 public void testReadEnvFromConfig() throws Exception {
270 OperationalEnvironmentEntry result;
273 result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
277 public void testCreateUebTopicsForEnvironment() throws Exception {
278 OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
281 testSubject.createUebTopicsForEnvironment(opEnvEntry);
285 public void testSetConfigurationManager() throws Exception {
286 ConfigurationManager configurationManager = null;
289 Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
293 public void testGetEnvironments() throws Exception {
294 Map<String, OperationalEnvironmentEntry> result;
297 result = testSubject.getEnvironments();
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());
309 ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
310 result = testSubject.isInMap(env);