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 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;
34 import java.util.HashSet;
35 import java.util.LinkedList;
36 import java.util.List;
38 public class DistributionEnginePollingTaskTest extends BeConfDependentTest {
41 private ComponentsUtils componentsUtils;
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);
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(),
63 public void testStartTask() throws Exception {
64 DistributionEnginePollingTask testSubject;
65 String topicName = "UEBTopic";
68 testSubject = createTestSubject();
69 testSubject.startTask(topicName);
73 public void testStopTask() throws Exception {
74 DistributionEnginePollingTask testSubject;
77 testSubject = createTestSubject();
78 testSubject.stopTask();
82 public void testDestroy() throws Exception {
83 DistributionEnginePollingTask testSubject;
86 testSubject = createTestSubject();
87 testSubject.destroy();
91 public void testRun() throws Exception {
92 DistributionEnginePollingTask testSubject;
95 testSubject = createTestSubject();
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");
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));
122 public void testShutdownExecutor() throws Exception {
123 DistributionEnginePollingTask testSubject;
126 testSubject = createTestSubject();
127 Deencapsulation.invoke(testSubject, "shutdownExecutor");
130 private class DistributionCompleteReporterMock implements DistributionCompleteReporter {
133 public void reportDistributionComplete(DistributionStatusNotification distributionStatusNotification) {
134 // TODO Auto-generated method stub