summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
blob: d1cc869835b9a3285b0ebb2d087445dc357d03f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package org.openecomp.sdc.be.components.distribution.engine;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Test;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
import org.openecomp.sdc.be.dao.impl.AuditingDao;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.info.OperationalEnvInfo;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.springframework.test.util.ReflectionTestUtils;

import fj.data.Either;
import mockit.Deencapsulation;

public class EnvironmentsEngineTest extends BeConfDependentTest {

	private EnvironmentsEngine createTestSubject() {
		return new EnvironmentsEngine(new DmaapConsumer(new ExecutorFactory(), new DmaapClientFactory()),
				new OperationalEnvironmentDao(), new DME2EndpointIteratorCreator(), new AaiRequestHandler(),
				new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao())),
				new CambriaHandler(), new DistributionEngineClusterHealth(), new DistributionCompleteReporterMock());
	}

	@Test
	public void testInit() throws Exception {
		EnvironmentsEngine testSubject;

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "init");
	}

	@Test
	public void testConnectUebTopicTenantIsolation() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
		opEnvEntry.setEnvironmentId("mock");
		AtomicBoolean status = null;
		Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
		Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();

		// default test
		testSubject = createTestSubject();
		testSubject.connectUebTopicTenantIsolation(opEnvEntry, status, envNamePerInitTask, envNamePerPollingTask);
	}

	@Test
	public void testConnectUebTopic() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
		AtomicBoolean status = new AtomicBoolean(true);
		Map<String, DistributionEngineInitTask> envNamePerInitTask = new HashMap<>();
		Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "connectUebTopic", opEnvEntry, status, envNamePerInitTask,
				envNamePerPollingTask);
	}

	@Test
	public void testHandleMessage() throws Exception {
		EnvironmentsEngine testSubject;
		String notification = "";
		boolean result;

		// default test
		testSubject = createTestSubject();
		result = testSubject.handleMessage(notification);
	}

	@Test
	public void testHandleMessageLogic() throws Exception {
		EnvironmentsEngine testSubject;
		String notification = "";
		boolean result;

		// default test
		testSubject = createTestSubject();
		result = testSubject.handleMessageLogic(notification);
	}

	@Test
	public void testValidateNotification() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		errorWrapper.setInnerElement(true);
		IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
		IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "validateNotification",
				errorWrapper, notificationData, auditNotificationData);
	}

	@Test(expected = NullPointerException.class)
	public void testSaveEntryWithFailedStatus() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "saveEntryWithFailedStatus", errorWrapper, opEnvEntry);
	}

	@Test
	public void testRetrieveUebAddressesFromAftDme() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "retrieveUebAddressesFromAftDme", errorWrapper, opEnvEntry);
	}

	@Test
	public void testCreateUebKeys() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();

		Set<String> dmaapUebAddress = new HashSet<>();
		dmaapUebAddress.add("mock");
		opEnvEntry.setDmaapUebAddress(dmaapUebAddress);

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "createUebKeys", errorWrapper, opEnvEntry);
	}

	/*@Test
	public void testRetrieveOpEnvInfoFromAAI() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();
		opEnvEntry.setEnvironmentId("mock");

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "retrieveOpEnvInfoFromAAI",
				Wrapper.class, opEnvEntry);
	}*/

	/*
	 * @Test public void testSaveEntryWithInProgressStatus() throws Exception {
	 * EnvironmentsEngine testSubject; Wrapper<Boolean> errorWrapper = new
	 * Wrapper<>(); Wrapper<OperationalEnvironmentEntry> opEnvEntryWrapper = new
	 * Wrapper<>(); IDmaapNotificationData notificationData = new
	 * IDmaapNotificationDataMock();
	 * 
	 * // default test testSubject = createTestSubject();
	 * Deencapsulation.invoke(testSubject, "saveEntryWithInProgressStatus",
	 * errorWrapper, opEnvEntryWrapper, notificationData); }
	 */

	/*
	 * @Test public void testValidateState() throws Exception { EnvironmentsEngine
	 * testSubject; Wrapper<Boolean> errorWrapper = null; IDmaapNotificationDataMock
	 * notificationData = new IDmaapNotificationDataMock();
	 * notificationData.setOperationalEnvironmentId("mock");
	 * 
	 * // default test testSubject = createTestSubject();
	 * Deencapsulation.invoke(testSubject, "validateState", Wrapper.class,
	 * notificationData); }
	 */

	@Test
	public void testValidateActionType() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
		notificationData.setDmaapActionEnum(DmaapActionEnum.DELETE);
		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);

		notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
		Deencapsulation.invoke(testSubject, "validateActionType", errorWrapper, notificationData);
	}

	@Test(expected=NullPointerException.class)
	public void testValidateEnvironmentType() throws Exception {
		EnvironmentsEngine testSubject;
		Wrapper<Boolean> errorWrapper = new Wrapper<>();
		IDmaapNotificationDataMock notificationData = new IDmaapNotificationDataMock();
		IDmaapAuditNotificationDataMock auditNotificationData = new IDmaapAuditNotificationDataMock();
		auditNotificationData.operationalEnvironmentName = "mock";
		notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.ECOMP;

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
				auditNotificationData);

		notificationData.operationaEnvironmentTypeEnum = OperationaEnvironmentTypeEnum.UNKONW;
		notificationData.setDmaapActionEnum(DmaapActionEnum.CREATE);
		Deencapsulation.invoke(testSubject, "validateEnvironmentType", errorWrapper, notificationData,
				auditNotificationData);
	}

	@Test
	public void testMap2OpEnvKey() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
		String result;

		// default test
		testSubject = createTestSubject();
		result = Deencapsulation.invoke(testSubject, "map2OpEnvKey", entry);
	}

	@Test
	public void testReadEnvFromConfig() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry result;

		// default test
		testSubject = createTestSubject();
		result = Deencapsulation.invoke(testSubject, "readEnvFromConfig");
	}

	@Test
	public void testCreateUebTopicsForEnvironment() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry opEnvEntry = new OperationalEnvironmentEntry();

		// default test
		testSubject = createTestSubject();
		testSubject.createUebTopicsForEnvironment(opEnvEntry);
	}

	@Test
	public void testSetConfigurationManager() throws Exception {
		EnvironmentsEngine testSubject;
		ConfigurationManager configurationManager = null;

		// default test
		testSubject = createTestSubject();
		Deencapsulation.invoke(testSubject, "setConfigurationManager", new Object[] { ConfigurationManager.class });
	}

	@Test
	public void testGetEnvironments() throws Exception {
		EnvironmentsEngine testSubject;
		Map<String, OperationalEnvironmentEntry> result;

		// default test
		testSubject = createTestSubject();
		result = testSubject.getEnvironments();
	}

	@Test
	public void testIsInMap() throws Exception {
		EnvironmentsEngine testSubject;
		OperationalEnvironmentEntry env = new OperationalEnvironmentEntry();
		env.setEnvironmentId("mock");
		Map<String, OperationalEnvironmentEntry> mockEnvironments = new HashMap<>();
		mockEnvironments.put("mock", new OperationalEnvironmentEntry());
		boolean result;

		// default test
		testSubject = createTestSubject();
		ReflectionTestUtils.setField(testSubject, "environments", mockEnvironments);
		result = testSubject.isInMap(env);
	}

	private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
		@Override
		public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
			// TODO Auto-generated method stub

		}
	}

	private class IDmaapNotificationDataMock implements IDmaapNotificationData {

		private String operationalEnvironmentId;
		private OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum;
		private DmaapActionEnum dmaapActionEnum;

		public OperationaEnvironmentTypeEnum getOperationaEnvironmentTypeEnum() {
			return operationaEnvironmentTypeEnum;
		}

		public void setOperationaEnvironmentTypeEnum(OperationaEnvironmentTypeEnum operationaEnvironmentTypeEnum) {
			this.operationaEnvironmentTypeEnum = operationaEnvironmentTypeEnum;
		}

		public DmaapActionEnum getDmaapActionEnum() {
			return dmaapActionEnum;
		}

		public void setDmaapActionEnum(DmaapActionEnum dmaapActionEnum) {
			this.dmaapActionEnum = dmaapActionEnum;
		}

		public void setOperationalEnvironmentId(String operationalEnvironmentId) {
			this.operationalEnvironmentId = operationalEnvironmentId;
		}

		@Override
		public String getOperationalEnvironmentId() {
			return operationalEnvironmentId;
		}

		@Override
		public OperationaEnvironmentTypeEnum getOperationalEnvironmentType() {
			return operationaEnvironmentTypeEnum;
		}

		@Override
		public DmaapActionEnum getAction() {
			return dmaapActionEnum;
		}
	}

	private class IDmaapAuditNotificationDataMock implements IDmaapAuditNotificationData {
		private String operationalEnvironmentName;
		private String tenantContext;

		@Override
		public String getOperationalEnvironmentName() {
			return null;
		}

		@Override
		public String getTenantContext() {
			return null;
		}

	}
}