2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.distribution.engine;
23 import java.lang.reflect.Method;
24 import java.util.HashSet;
25 import java.util.LinkedList;
26 import java.util.List;
27 import org.junit.jupiter.api.BeforeAll;
28 import org.junit.jupiter.api.Test;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.openecomp.sdc.be.components.BeConfDependentTest;
32 import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
33 import org.openecomp.sdc.be.config.ConfigurationManager;
34 import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
35 import org.openecomp.sdc.be.impl.ComponentsUtils;
36 import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
37 import org.openecomp.sdc.common.impl.ExternalConfiguration;
38 import org.openecomp.sdc.common.impl.FSConfigurationSource;
39 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
41 class DistributionEnginePollingTaskTest extends BeConfDependentTest {
43 // TODO - remove this setup after migration to Junit5 BeConfDependentTest
45 private static void setup() {
46 configurationManager =
47 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
51 private ComponentsUtils componentsUtils;
53 private DistributionEnginePollingTask createTestSubject() {
54 componentsUtils = Mockito.mock(ComponentsUtils.class);
55 DistributionEngineConfiguration distributionEngineConfiguration = configurationManager
56 .getDistributionEngineConfiguration();
57 distributionEngineConfiguration.setDistributionNotifTopicName("StamName");
58 distributionEngineConfiguration.setDistributionStatusTopicName("StamName");
59 List uebList = new LinkedList<>();
60 uebList.add("FirstUEBserver.com");
61 distributionEngineConfiguration.setUebServers(uebList);
63 OperationalEnvironmentEntry environmentEntry = new OperationalEnvironmentEntry();
64 HashSet<String> dmaapUebAddress = new HashSet<>();
65 dmaapUebAddress.add("STAM");
66 environmentEntry.setDmaapUebAddress(dmaapUebAddress);
67 return new DistributionEnginePollingTask(distributionEngineConfiguration,
68 new DistributionCompleteReporterMock(), componentsUtils, new DistributionEngineClusterHealth(), environmentEntry);
72 void testStartTask() throws Exception {
73 DistributionEnginePollingTask testSubject;
74 String topicName = "UEBTopic";
77 testSubject = createTestSubject();
78 testSubject.startTask(topicName);
82 void testStopTask() throws Exception {
83 DistributionEnginePollingTask testSubject;
86 testSubject = createTestSubject();
87 testSubject.stopTask();
91 void testDestroy() throws Exception {
92 DistributionEnginePollingTask testSubject;
95 testSubject = createTestSubject();
96 testSubject.destroy();
100 void testRun() throws Exception {
101 DistributionEnginePollingTask testSubject;
104 testSubject = createTestSubject();
109 void testHandleDistributionNotificationMsg() throws Exception {
110 DistributionEnginePollingTask testSubject;
111 final DistributionStatusNotification notification = new DistributionStatusNotification();
112 notification.setDistributionID("mock");
113 notification.setConsumerID("mock");
114 notification.setArtifactURL("mock");
115 notification.setTimestamp(435435);
116 notification.setStatus(DistributionStatusNotificationEnum.ALREADY_DEPLOYED);
117 notification.setErrorReason("mock");
120 testSubject = createTestSubject();
121 Mockito.doNothing().when(componentsUtils).auditDistributionStatusNotification(Mockito.anyString(),
122 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
123 Mockito.anyString(), Mockito.anyString(), Mockito.isNull());
125 final Class[] argClasses = {DistributionStatusNotification.class, LoggerSdcAudit.class};
126 final Method method = DistributionEnginePollingTask.class.getDeclaredMethod("handleDistributionNotificationMsg", argClasses);
127 method.setAccessible(true);
128 method.invoke(testSubject, notification, new LoggerSdcAudit(DistributionEnginePollingTask.class));
131 private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
134 public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
135 // TODO Auto-generated method stub