[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / upload / HeatCleanup / HeatCleanupOnNewUploadTest.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.upload.HeatCleanup;
22
23 public class HeatCleanupOnNewUploadTest {/*
24   private static final String USER1 = "vspTestUser1";
25
26   private static final VendorSoftwareProductManager
27       vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
28   private static final VendorSoftwareProductDao vendorSoftwareProductDao =
29       VendorSoftwareProductDaoFactory
30           .getInstance().createInterface();
31   private static final ServiceModelDao serviceModelDao =
32       ServiceModelDaoFactory.getInstance().createInterface();
33
34   private static String vspId = null;
35   private static Version vspActiveVersion = null;
36
37   private static void validateUploadContentExistence(boolean exist) {
38     UploadDataEntity uploadDataEntity =
39         vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, vspActiveVersion));
40     Assert.assertTrue((uploadDataEntity.getContentData() != null) == exist);
41     Assert.assertTrue((uploadDataEntity.getValidationData() != null) == exist);
42     Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist);
43     Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist);
44     //TODO: talio - delete enrich data on new upload
45     //Assert.assertTrue((serviceModelDao.getServiceModel(vspId, vspActiveVersion) != null) == ex
46   }
47
48   private static void validateCompositionDataExistence(boolean exist) {
49     Assert.assertTrue(CollectionUtils
50         .isNotEmpty(vendorSoftwareProductDao.listNetworks(vspId, vspActiveVersion)) == exist);
51     Assert.assertTrue(CollectionUtils
52         .isNotEmpty(vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion)) == exist);
53     Assert.assertTrue(CollectionUtils
54         .isNotEmpty(vendorSoftwareProductDao.listNicsByVsp(vspId, vspActiveVersion)) == exist);
55   }
56
57   private static InputStream getFileInputStream(String fileName) {
58     URL url = HeatCleanupOnNewUploadTest.class.getResource(fileName);
59     try {
60       return url.openStream();
61     } catch (IOException exception) {
62       exception.printStackTrace();
63       return null;
64     }
65   }
66
67   @BeforeClass
68   private void init() {
69     UniqueValueUtil
70         .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
71             "VSPTestEmpty");
72
73     VspDetails vspDetails = vendorSoftwareProductManager.createVsp(VSPCommon
74         .createVspDetails(null, null, "VSPTestEmpty", "Test-vsp-empty", "vendorName", "vlm1Id",
75             "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.HEAT.name()),
76         USER1);
77     vspId = vspDetails.getId();
78     vspActiveVersion = vspDetails.getVersion();
79   }
80
81   @Test
82   public void testUploadWithComposition() {
83     InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
84
85     vendorSoftwareProductManager.upload(vspId, zis, USER1);
86     OrchestrationTemplateActionResponse orchestrationTemplateActionResponse =
87         vendorSoftwareProductManager.process(vspId, USER1);
88
89     Assert.assertEquals(orchestrationTemplateActionResponse.getStatus(), UploadFileStatus.Success);
90     Assert.assertTrue(MapUtils.isEmpty(MessageContainerUtil
91         .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.getErrors())));
92
93     validateUploadContentExistence(true);
94     validateCompositionDataExistence(true);
95   }
96
97   @Test(dependsOnMethods = {"testUploadWithComposition"})
98   public void testProccesesMIBsDeletionAfterNewUpload() {
99     InputStream zis1 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
100     InputStream zis2 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
101     InputStream mib = getFileInputStream("/vspmanager/zips/vDNS.zip");
102
103     vendorSoftwareProductManager.upload(vspId, zis1, USER1);
104     vendorSoftwareProductManager.process(vspId, USER1);
105     List<ComponentEntity> components =
106         (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion);
107     String componentId = components.get(0).getId();
108
109     vendorSoftwareProductManager
110         .upload(mib, "vDNS.zip", vspId, componentId, MonitoringUploadType.SNMP_TRAP, USER1);
111     vendorSoftwareProductManager
112         .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);
113
114     vendorSoftwareProductManager.upload(vspId, zis2, USER1);
115     vendorSoftwareProductManager.process(vspId, USER1);
116     Assert.assertTrue(
117         vendorSoftwareProductManager.listFilenames(vspId, componentId, USER1).getSnmpTrap() ==
118             null);
119     Assert.assertTrue(CollectionUtils
120         .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
121   }
122
123   @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
124   public void testInvalidUploadAfterFullComposition() {
125     InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
126
127     vendorSoftwareProductManager.upload(vspId, zis, USER1);
128     OrchestrationTemplateActionResponse uploadFileResponse =
129         vendorSoftwareProductManager.process(vspId, USER1);
130     Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Failure);
131     Assert.assertTrue(MapUtils.isNotEmpty(
132         MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
133
134     validateUploadContentExistence(true);
135     //TODO: talio - check upload cleanup
136 //    validateCompositionDataExistence(false);
137   }
138
139   @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
140   public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
141     testUploadWithComposition();
142
143     InputStream zis = getFileInputStream("/vspmanager/zips/emptyComposition.zip");
144     vendorSoftwareProductManager.upload(vspId, zis, USER1);
145     OrchestrationTemplateActionResponse uploadFileResponse =
146         vendorSoftwareProductManager.process(vspId, USER1);
147     Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
148     Assert.assertTrue(MapUtils.isEmpty(
149         MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
150
151     validateUploadContentExistence(true);
152     validateCompositionDataExistence(false);
153   }
154 */}