d94d10cf0f4ba8ea1b7a9a4f9db5028e193d3aea
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.healing.healers;
18
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;
26
27 import static java.lang.Boolean.FALSE;
28 import static java.lang.Boolean.TRUE;
29 import static org.mockito.Mockito.any;
30
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;
43
44 public class NetworkPackageHealerTest {
45
46   @Mock
47   private VendorSoftwareProductInfoDao vspInfoDaoMock;
48   @Mock
49   private ZusammenAdaptor zusammenAdaptorMock;
50   @Mock
51   private CandidateService candidateService;
52
53   private NetworkPackageHealer networkPackageHealer;
54   private static final String tenant = "dox";
55
56   @Before
57   public void init() {
58     SessionContextProviderFactory.getInstance().createInterface().create("test", tenant);
59     MockitoAnnotations.initMocks(this);
60     networkPackageHealer = new NetworkPackageHealer(vspInfoDaoMock, zusammenAdaptorMock, candidateService);
61   }
62
63   @After
64   public void tearDown(){
65     SessionContextProviderFactory.getInstance().createInterface().close();
66   }
67
68   @Test
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
80         (elementInfos);
81     Assert.assertEquals(TRUE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));
82 }
83
84   @Test
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<>();
90
91     ElementInfo elementInfo = new ElementInfo();
92     Info info = new Info();
93     info.setName(ElementType.OrchestrationTemplateCandidate.name());
94     elementInfo.setInfo(info);
95     elementInfos.add(elementInfo);
96
97     ElementInfo elementInfo1 = new ElementInfo();
98     Info info1 = new Info();
99     info1.setName(ElementType.OrchestrationTemplateCandidateValidationData.name());
100     elementInfo1.setInfo(info1);
101     elementInfos.add(elementInfo1);
102
103     Mockito.when(zusammenAdaptorMock.listElementsByName(any(),any(),any(),any())).thenReturn
104         (elementInfos);
105     Assert.assertEquals(FALSE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));
106   }
107
108   @Test
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);
113
114     Assert.assertEquals(FALSE,networkPackageHealer.isHealingNeeded("ITEM_ID", new Version()));
115   }
116 }