2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.healing.healers;
19 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
20 import com.amdocs.zusammen.datatypes.item.Info;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
27 import static java.lang.Boolean.FALSE;
28 import static java.lang.Boolean.TRUE;
29 import static org.mockito.Mockito.any;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
34 import org.openecomp.sdc.common.session.SessionContextProviderFactory;
35 import org.openecomp.sdc.datatypes.model.ElementType;
36 import org.openecomp.sdc.healing.healers.NetworkPackageHealer;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
39 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
40 import org.openecomp.sdc.versioning.dao.types.Version;
41 import java.util.ArrayList;
42 import java.util.Collection;
44 public class NetworkPackageHealerTest {
47 private VendorSoftwareProductInfoDao vspInfoDaoMock;
49 private ZusammenAdaptor zusammenAdaptorMock;
51 private CandidateService candidateService;
53 private NetworkPackageHealer networkPackageHealer;
54 private static final String tenant = "dox";
58 SessionContextProviderFactory.getInstance().createInterface().create("test", tenant);
59 MockitoAnnotations.initMocks(this);
60 networkPackageHealer = new NetworkPackageHealer(vspInfoDaoMock, zusammenAdaptorMock, candidateService);
64 public void tearDown(){
65 SessionContextProviderFactory.getInstance().createInterface().close();
69 public void testIsHealingNeeded_Positive() {
70 VspDetails vspDetails = new VspDetails("ITEM_ID",new Version());
71 vspDetails.setOnboardingMethod("NetworkPackage");
72 Mockito.when(vspInfoDaoMock.get(any())).thenReturn(vspDetails);
73 Collection<ElementInfo> elementInfos = new ArrayList<>();
74 ElementInfo elementInfo = new ElementInfo();
75 Info info = new Info();
76 info.setName(ElementType.OrchestrationTemplateCandidate.name());
77 elementInfo.setInfo(info);
78 elementInfos.add(elementInfo);
79 Mockito.when(zusammenAdaptorMock.listElementsByName(any(),any(),any(),any())).thenReturn
81 Assert.assertEquals(TRUE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));
85 public void testIsHealingNeeded_Negative() {
86 VspDetails vspDetails = new VspDetails("ITEM_ID",new Version());
87 vspDetails.setOnboardingMethod("NetworkPackage");
88 Mockito.when(vspInfoDaoMock.get(any())).thenReturn(vspDetails);
89 Collection<ElementInfo> elementInfos = new ArrayList<>();
91 ElementInfo elementInfo = new ElementInfo();
92 Info info = new Info();
93 info.setName(ElementType.OrchestrationTemplateCandidate.name());
94 elementInfo.setInfo(info);
95 elementInfos.add(elementInfo);
97 ElementInfo elementInfo1 = new ElementInfo();
98 Info info1 = new Info();
99 info1.setName(ElementType.OrchestrationTemplateCandidateValidationData.name());
100 elementInfo1.setInfo(info1);
101 elementInfos.add(elementInfo1);
103 Mockito.when(zusammenAdaptorMock.listElementsByName(any(),any(),any(),any())).thenReturn
105 Assert.assertEquals(FALSE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));
109 public void testIsHealingNeeded_OnboardingMethod() {
110 VspDetails vspDetails = new VspDetails("ITEM_ID",new Version());
111 vspDetails.setOnboardingMethod("Manual");
112 Mockito.when(vspInfoDaoMock.get(any())).thenReturn(vspDetails);
114 Assert.assertEquals(FALSE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));