95e3553990a5c2b72dcbaaef5e05e6916ae29796
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
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;
40
41 class DistributionEnginePollingTaskTest extends BeConfDependentTest {
42
43     // TODO - remove this setup after migration to Junit5 BeConfDependentTest
44     @BeforeAll
45     private static void setup() {
46         configurationManager =
47             new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
48     }
49
50     @Mock
51     private ComponentsUtils componentsUtils;
52
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);
62
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);
69     }
70
71     @Test
72     void testStartTask() throws Exception {
73         DistributionEnginePollingTask testSubject;
74         String topicName = "UEBTopic";
75
76         // default test
77         testSubject = createTestSubject();
78         testSubject.startTask(topicName);
79     }
80
81     @Test
82     void testStopTask() throws Exception {
83         DistributionEnginePollingTask testSubject;
84
85         // default test
86         testSubject = createTestSubject();
87         testSubject.stopTask();
88     }
89
90     @Test
91     void testDestroy() throws Exception {
92         DistributionEnginePollingTask testSubject;
93
94         // default test
95         testSubject = createTestSubject();
96         testSubject.destroy();
97     }
98
99     @Test
100     void testRun() throws Exception {
101         DistributionEnginePollingTask testSubject;
102
103         // default test
104         testSubject = createTestSubject();
105         testSubject.run();
106     }
107
108     @Test
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");
118
119         // default test
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());
124
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));
129     }
130
131     private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
132
133         @Override
134         public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
135             // TODO Auto-generated method stub
136         }
137
138     }
139 }