Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / distribution / engine / DistributionEnginePollingTaskTest.java
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 mockit.Deencapsulation;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.openecomp.sdc.be.components.BeConfDependentTest;
28 import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
29 import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
30 import org.openecomp.sdc.be.impl.ComponentsUtils;
31 import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
32 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
33
34 import java.util.HashSet;
35 import java.util.LinkedList;
36 import java.util.List;
37
38 public class DistributionEnginePollingTaskTest extends BeConfDependentTest {
39
40         @Mock
41         private ComponentsUtils componentsUtils;
42
43         private DistributionEnginePollingTask createTestSubject() {
44                 componentsUtils = Mockito.mock(ComponentsUtils.class);
45                 DistributionEngineConfiguration distributionEngineConfiguration = configurationManager
46                                 .getDistributionEngineConfiguration();
47                 distributionEngineConfiguration.setDistributionNotifTopicName("StamName");
48                 distributionEngineConfiguration.setDistributionStatusTopicName("StamName");
49                 List uebList = new LinkedList<>();
50                 uebList.add("FirstUEBserver.com");
51                 distributionEngineConfiguration.setUebServers(uebList);
52
53                 OperationalEnvironmentEntry environmentEntry = new OperationalEnvironmentEntry();
54                 HashSet<String> dmaapUebAddress = new HashSet<>();
55                 dmaapUebAddress.add("STAM");
56                 environmentEntry.setDmaapUebAddress(dmaapUebAddress);
57                 return new DistributionEnginePollingTask(distributionEngineConfiguration,
58                                 new DistributionCompleteReporterMock(), componentsUtils, new DistributionEngineClusterHealth(),
59                                 environmentEntry);
60         }
61
62         @Test
63         public void testStartTask() throws Exception {
64                 DistributionEnginePollingTask testSubject;
65                 String topicName = "UEBTopic";
66
67                 // default test
68                 testSubject = createTestSubject();
69                 testSubject.startTask(topicName);
70         }
71
72         @Test
73         public void testStopTask() throws Exception {
74                 DistributionEnginePollingTask testSubject;
75
76                 // default test
77                 testSubject = createTestSubject();
78                 testSubject.stopTask();
79         }
80
81         @Test
82         public void testDestroy() throws Exception {
83                 DistributionEnginePollingTask testSubject;
84
85                 // default test
86                 testSubject = createTestSubject();
87                 testSubject.destroy();
88         }
89
90         @Test
91         public void testRun() throws Exception {
92                 DistributionEnginePollingTask testSubject;
93
94                 // default test
95                 testSubject = createTestSubject();
96                 testSubject.run();
97         }
98         
99         @Test
100         public void testHandleDistributionNotificationMsg() throws Exception {
101                 DistributionEnginePollingTask testSubject;
102                 DistributionStatusNotification notification = new DistributionStatusNotification();
103                 notification.setDistributionID("mock");
104                 notification.setConsumerID("mock");
105                 notification.setArtifactURL("mock");
106                 notification.setTimestamp(435435);
107                 notification.setStatus(DistributionStatusNotificationEnum.ALREADY_DEPLOYED);
108                 notification.setErrorReason("mock");
109                 
110                 
111                 
112                 // default test
113                 testSubject = createTestSubject();
114                 Mockito.doNothing().when(componentsUtils).auditDistributionStatusNotification( Mockito.anyString(),
115                                 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), 
116                                 Mockito.anyString(), Mockito.anyString(), Mockito.isNull());
117                 Deencapsulation.invoke(testSubject, "handleDistributionNotificationMsg",
118                                 notification, new LoggerSdcAudit(DistributionEnginePollingTask.class));
119         }
120
121         @Test
122         public void testShutdownExecutor() throws Exception {
123                 DistributionEnginePollingTask testSubject;
124
125                 // default test
126                 testSubject = createTestSubject();
127                 Deencapsulation.invoke(testSubject, "shutdownExecutor");
128         }
129
130         private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
131
132                 @Override
133                 public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
134                         // TODO Auto-generated method stub
135
136                 }
137
138         }
139 }