[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / VspHealTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.vendorsoftwareproduct;
22
23 public class VspHealTest {/*
24   private static VendorSoftwareProductManager vendorSoftwareProductManager = null;
25   //new VendorSoftwareProductManagerImpl();
26   private VendorSoftwareProductManagerImplTest vendorSoftwareProductManagerTest =
27       new VendorSoftwareProductManagerImplTest();
28   private static OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDataDao =
29       OrchestrationTemplateCandidateDaoFactory.getInstance().createInterface();
30   private static VendorSoftwareProductDao vendorSoftwareProductDao =
31       VendorSoftwareProductDaoFactory.getInstance().createInterface();
32   private static ComponentDao componentDao =
33       ComponentDaoFactory.getInstance().createInterface();
34   private static CompositionDataExtractor compositionDataExtractor =
35       CompositionDataExtractorFactory.getInstance().createInterface();
36   private static NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
37   private static NicDao nicDao = NicDaoFactory.getInstance().createInterface();
38   private static VspDetails vspDetails;
39   private static final String USER = "vspTestUser1";
40   public static final Version VERSION01 = new Version(0, 1);
41   private static String vspId;
42   private OrchestrationTemplateCandidateManager candidateManager;
43
44   @BeforeTest
45   private void init() {
46     try {
47       vspDetails = new VspDetails();
48       vspDetails.setName("vspName_" + CommonMethods.nextUuId());
49       vspDetails.setVendorName("vendor");
50       vspId = vendorSoftwareProductManager.createVsp(vspDetails, USER).getId();
51
52     } catch (Exception ignored) {
53       System.out.println(ignored.getMessage());
54     }
55   }
56
57   @Test
58   public void shouldReturnEmptyFileDataStructureBeforeZipUpload() {
59     Optional<FilesDataStructure> candidateFilesDataStructure = candidateManager
60         .getFilesDataStructure(vspId, VERSION01, USER);
61     Assert.assertNotNull(candidateFilesDataStructure);
62     Assert.assertTrue(candidateFilesDataStructure.isPresent());
63
64     checkFileDataStructureListsAreEmpty(candidateFilesDataStructure.get());
65   }
66
67   @Test(dependsOnMethods = "shouldReturnEmptyFileDataStructureBeforeZipUpload")
68   public void shouldReturnFileDataStructureOnEmptyFileDataStructureInDB() {
69     uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/emptyComposition.zip");
70
71     orchestrationTemplateCandidateDataDao
72         .deleteOrchestrationTemplateCandidateFileDataStructure(vspId, VERSION01);
73     Assert.assertEquals(Optional.empty(), orchestrationTemplateCandidateDataDao
74         .getOrchestrationTemplateCandidateFileDataStructure(vspId, VERSION01));
75
76     Optional<FilesDataStructure> candidateFilesDataStructure = candidateManager
77         .getFilesDataStructure(vspId, VERSION01, USER);
78     Assert.assertNotNull(candidateFilesDataStructure);
79     Assert.assertTrue(candidateFilesDataStructure.isPresent());
80   }
81
82   @Test(dependsOnMethods = "shouldReturnEmptyFileDataStructureBeforeZipUpload")
83   public void shouldReturnEmptyFileDataStructureOnEmptyUpload() {
84     try {
85       uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/zipFileWithFolder.zip");
86     } catch (Exception e) {
87       Assert.assertEquals(e.getMessage(),
88           "Failed to get orchestration template for VSP with id " + vspId);
89     }
90   }
91
92   @Test(dependsOnMethods = {"shouldReturnEmptyFileDataStructureOnEmptyUpload"})
93   public void shouldHealVspOnIsOldTrue() {
94     vspDetails.setOldVersion(VersionHealingValues.True);
95     vendorSoftwareProductDao.updateQuestionnaire(vspId, VERSION01, null);
96
97     vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
98
99     VspQuestionnaireEntity questionnaire =
100         vendorSoftwareProductDao.getQuestionnaire(vspId, VERSION01);
101
102     Assert.assertNotNull(questionnaire.getQuestionnaireData());
103   }
104
105   @Test(dependsOnMethods = {"shouldHealVspOnIsOldTrue"})
106   public void shouldHealNullQuestionnaire() {
107     vendorSoftwareProductDao.updateQuestionnaire(vspId, VERSION01, null);
108     vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
109     QuestionnaireResponse vspQuestionnaire =
110         vendorSoftwareProductManager.getVspQuestionnaire(vspId, VERSION01, USER);
111
112     Assert.assertNotNull(vspQuestionnaire.getData());
113   }
114
115   @Test(dependsOnMethods = {"shouldHealNullQuestionnaire"})
116   public void shouldHealNullCompositionData() {
117     uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/fullComposition.zip");
118
119     Collection<ComponentEntity> componentEntitiesBeforeHeal =
120         vendorSoftwareProductDao.listComponents(vspId, VERSION01);
121     Collection<NetworkEntity> networkEntitiesBeforeHeal =
122         vendorSoftwareProductDao.listNetworks(vspId, VERSION01);
123
124     deleteCompositionData(vspId, VERSION01);
125
126     vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
127
128     Collection<ComponentEntity> componentEntitiesAfterHeal =
129         vendorSoftwareProductDao.listComponents(vspId, VERSION01);
130     Collection<NetworkEntity> networkEntitiesAfterHeal =
131         vendorSoftwareProductDao.listNetworks(vspId, VERSION01);
132
133     checkCompositionDataIsHealed(componentEntitiesBeforeHeal, networkEntitiesBeforeHeal,
134         componentEntitiesAfterHeal, networkEntitiesAfterHeal);
135   }
136
137   @Test(dependsOnMethods = {"shouldHealNullCompositionData"})
138   public void shouldChangeComponentDisplayName() {
139     uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/vCDN.zip");
140
141     List<ComponentEntity> componentEntitiesBeforeHeal =
142         (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, VERSION01);
143     Collection<ComponentEntity> componentsToHeal = new ArrayList<>();
144
145     for (ComponentEntity component : componentEntitiesBeforeHeal) {
146       changeComponentDisplayNameToOldVersion(component);
147     }
148
149     vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
150
151     List<ComponentEntity> componentEntitiesAfterHeal =
152         (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, VERSION01);
153
154     assertComponentdisplayNameAsExpected(componentEntitiesBeforeHeal, componentEntitiesAfterHeal);
155   }
156
157   private void assertComponentdisplayNameAsExpected(
158       List<ComponentEntity> componentEntitiesBeforeHeal,
159       List<ComponentEntity> componentEntitiesAfterHeal) {
160     ComponentEntity componentBefore = componentEntitiesBeforeHeal.get(0);
161     ComponentEntity componentAfter = componentEntitiesAfterHeal.get(0);
162     Assert.assertNotEquals(componentBefore, componentAfter);
163
164     ComponentData componsitionDataBefore = componentBefore.getComponentCompositionData();
165     ComponentData compositionDataAfter = componentAfter.getComponentCompositionData();
166     Assert.assertTrue(
167         componsitionDataBefore.getDisplayName().contains(compositionDataAfter.getDisplayName()));
168     Assert.assertEquals(
169         compositionDataExtractor.getComponentDisplayName(componsitionDataBefore.getName()),
170         compositionDataAfter.getDisplayName());
171   }
172
173   private void changeComponentDisplayNameToOldVersion(ComponentEntity component) {
174     ComponentData componentData = component.getComponentCompositionData();
175     componentData.setDisplayName(componentData.getName());
176     componentData.setVfcCode(componentData.getDisplayName());
177     component.setComponentCompositionData(componentData);
178     vendorSoftwareProductDao.updateComponent(component);
179   }
180
181
182   private void uploadAndProcessOrchestrationTemplate(String vspId, String user,
183                                                      String filePath) {
184
185     candidateManager.upload(vspId, VERSION01,
186         vendorSoftwareProductManagerTest
187             .getFileInputStream(filePath), user);
188     candidateManager.process(vspId, VERSION01, user);
189   }
190
191   private void deleteCompositionData(String vspId, Version version) {
192     componentDao.deleteAll(vspId, version);
193     networkDao.deleteAll(vspId, version);
194     nicDao.deleteByVspId(vspId, version);
195   }
196
197   private void checkCompositionDataIsHealed(Collection<ComponentEntity> componentEntitiesBeforeHeal,
198                                             Collection<NetworkEntity> networkEntitiesBeforeHeal,
199                                             Collection<ComponentEntity> componentEntitiesAfterHeal,
200                                             Collection<NetworkEntity> networkEntitiesAfterHeal) {
201     Assert.assertNotNull(componentEntitiesAfterHeal);
202     Assert.assertNotNull(networkEntitiesAfterHeal);
203
204     Assert.assertEquals(componentEntitiesBeforeHeal.size(), componentEntitiesAfterHeal.size());
205     Assert.assertEquals(networkEntitiesBeforeHeal.size(), networkEntitiesAfterHeal.size());
206   }
207
208
209   private void checkFileDataStructureListsAreEmpty(FilesDataStructure filesDataStructure) {
210     Assert.assertEquals(filesDataStructure.getArtifacts().size(), 0);
211     Assert.assertEquals(filesDataStructure.getModules().size(), 0);
212     Assert.assertEquals(filesDataStructure.getNested().size(), 0);
213     Assert.assertEquals(filesDataStructure.getUnassigned().size(), 0);
214   }
215
216 */
217 }