2 * ============LICENSE_START=======================================================
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
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.vendorsoftwareproduct;
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;
47 vspDetails = new VspDetails();
48 vspDetails.setName("vspName_" + CommonMethods.nextUuId());
49 vspDetails.setVendorName("vendor");
50 vspId = vendorSoftwareProductManager.createVsp(vspDetails, USER).getId();
52 } catch (Exception ignored) {
53 System.out.println(ignored.getMessage());
58 public void shouldReturnEmptyFileDataStructureBeforeZipUpload() {
59 Optional<FilesDataStructure> candidateFilesDataStructure = candidateManager
60 .getFilesDataStructure(vspId, VERSION01, USER);
61 Assert.assertNotNull(candidateFilesDataStructure);
62 Assert.assertTrue(candidateFilesDataStructure.isPresent());
64 checkFileDataStructureListsAreEmpty(candidateFilesDataStructure.get());
67 @Test(dependsOnMethods = "shouldReturnEmptyFileDataStructureBeforeZipUpload")
68 public void shouldReturnFileDataStructureOnEmptyFileDataStructureInDB() {
69 uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/emptyComposition.zip");
71 orchestrationTemplateCandidateDataDao
72 .deleteOrchestrationTemplateCandidateFileDataStructure(vspId, VERSION01);
73 Assert.assertEquals(Optional.empty(), orchestrationTemplateCandidateDataDao
74 .getOrchestrationTemplateCandidateFileDataStructure(vspId, VERSION01));
76 Optional<FilesDataStructure> candidateFilesDataStructure = candidateManager
77 .getFilesDataStructure(vspId, VERSION01, USER);
78 Assert.assertNotNull(candidateFilesDataStructure);
79 Assert.assertTrue(candidateFilesDataStructure.isPresent());
82 @Test(dependsOnMethods = "shouldReturnEmptyFileDataStructureBeforeZipUpload")
83 public void shouldReturnEmptyFileDataStructureOnEmptyUpload() {
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);
92 @Test(dependsOnMethods = {"shouldReturnEmptyFileDataStructureOnEmptyUpload"})
93 public void shouldHealVspOnIsOldTrue() {
94 vspDetails.setOldVersion(VersionHealingValues.True);
95 vendorSoftwareProductDao.updateQuestionnaire(vspId, VERSION01, null);
97 vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
99 VspQuestionnaireEntity questionnaire =
100 vendorSoftwareProductDao.getQuestionnaire(vspId, VERSION01);
102 Assert.assertNotNull(questionnaire.getQuestionnaireData());
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);
112 Assert.assertNotNull(vspQuestionnaire.getData());
115 @Test(dependsOnMethods = {"shouldHealNullQuestionnaire"})
116 public void shouldHealNullCompositionData() {
117 uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/fullComposition.zip");
119 Collection<ComponentEntity> componentEntitiesBeforeHeal =
120 vendorSoftwareProductDao.listComponents(vspId, VERSION01);
121 Collection<NetworkEntity> networkEntitiesBeforeHeal =
122 vendorSoftwareProductDao.listNetworks(vspId, VERSION01);
124 deleteCompositionData(vspId, VERSION01);
126 vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
128 Collection<ComponentEntity> componentEntitiesAfterHeal =
129 vendorSoftwareProductDao.listComponents(vspId, VERSION01);
130 Collection<NetworkEntity> networkEntitiesAfterHeal =
131 vendorSoftwareProductDao.listNetworks(vspId, VERSION01);
133 checkCompositionDataIsHealed(componentEntitiesBeforeHeal, networkEntitiesBeforeHeal,
134 componentEntitiesAfterHeal, networkEntitiesAfterHeal);
137 @Test(dependsOnMethods = {"shouldHealNullCompositionData"})
138 public void shouldChangeComponentDisplayName() {
139 uploadAndProcessOrchestrationTemplate(vspId, USER, "/vspmanager/zips/vCDN.zip");
141 List<ComponentEntity> componentEntitiesBeforeHeal =
142 (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, VERSION01);
143 Collection<ComponentEntity> componentsToHeal = new ArrayList<>();
145 for (ComponentEntity component : componentEntitiesBeforeHeal) {
146 changeComponentDisplayNameToOldVersion(component);
149 vendorSoftwareProductManager.heal(vspId, VERSION01, USER);
151 List<ComponentEntity> componentEntitiesAfterHeal =
152 (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, VERSION01);
154 assertComponentdisplayNameAsExpected(componentEntitiesBeforeHeal, componentEntitiesAfterHeal);
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);
164 ComponentData componsitionDataBefore = componentBefore.getComponentCompositionData();
165 ComponentData compositionDataAfter = componentAfter.getComponentCompositionData();
167 componsitionDataBefore.getDisplayName().contains(compositionDataAfter.getDisplayName()));
169 compositionDataExtractor.getComponentDisplayName(componsitionDataBefore.getName()),
170 compositionDataAfter.getDisplayName());
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);
182 private void uploadAndProcessOrchestrationTemplate(String vspId, String user,
185 candidateManager.upload(vspId, VERSION01,
186 vendorSoftwareProductManagerTest
187 .getFileInputStream(filePath), user);
188 candidateManager.process(vspId, VERSION01, user);
191 private void deleteCompositionData(String vspId, Version version) {
192 componentDao.deleteAll(vspId, version);
193 networkDao.deleteAll(vspId, version);
194 nicDao.deleteByVspId(vspId, version);
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);
204 Assert.assertEquals(componentEntitiesBeforeHeal.size(), componentEntitiesAfterHeal.size());
205 Assert.assertEquals(networkEntitiesBeforeHeal.size(), networkEntitiesAfterHeal.size());
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);