[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 / 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), USER1);
76     vspId = vspDetails.getId();
77     vspActiveVersion = vspDetails.getVersion();
78   }
79
80   @Test
81   public void testUploadWithComposition() {
82     InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
83
84     vendorSoftwareProductManager.upload(vspId, zis, USER1);
85     OrchestrationTemplateActionResponse orchestrationTemplateActionResponse =
86         vendorSoftwareProductManager.process(vspId, USER1);
87
88     Assert.assertEquals(orchestrationTemplateActionResponse.getStatus(), UploadFileStatus.Success);
89     Assert.assertTrue(MapUtils.isEmpty(MessageContainerUtil
90         .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.getErrors())));
91
92     validateUploadContentExistence(true);
93     validateCompositionDataExistence(true);
94   }
95
96   @Test(dependsOnMethods = {"testUploadWithComposition"})
97   public void testProccesesMIBsDeletionAfterNewUpload() {
98     InputStream zis1 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
99     InputStream zis2 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
100     InputStream mib = getFileInputStream("/vspmanager/zips/vDNS.zip");
101
102     vendorSoftwareProductManager.upload(vspId, zis1, USER1);
103     vendorSoftwareProductManager.process(vspId, USER1);
104     List<ComponentEntity> components =
105         (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion);
106     String componentId = components.get(0).getId();
107
108     vendorSoftwareProductManager
109         .upload(mib, "vDNS.zip", vspId, componentId, ArtifactType.SNMP_TRAP, USER1);
110     vendorSoftwareProductManager
111         .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);
112
113     vendorSoftwareProductManager.upload(vspId, zis2, USER1);
114     vendorSoftwareProductManager.process(vspId, USER1);
115     Assert.assertTrue(
116         vendorSoftwareProductManager.listFilenames(vspId, componentId, USER1).getSnmpTrap() ==
117             null);
118     Assert.assertTrue(CollectionUtils
119         .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
120   }
121
122   @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
123   public void testInvalidUploadAfterFullComposition() {
124     InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
125
126     vendorSoftwareProductManager.upload(vspId, zis, USER1);
127     OrchestrationTemplateActionResponse uploadFileResponse =
128         vendorSoftwareProductManager.process(vspId, USER1);
129     Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Failure);
130     Assert.assertTrue(MapUtils.isNotEmpty(
131         MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
132
133     validateUploadContentExistence(true);
134     //TODO: talio - check upload cleanup
135 //    validateCompositionDataExistence(false);
136   }
137
138   @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
139   public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
140     testUploadWithComposition();
141
142     InputStream zis = getFileInputStream("/vspmanager/zips/emptyComposition.zip");
143     vendorSoftwareProductManager.upload(vspId, zis, USER1);
144     OrchestrationTemplateActionResponse uploadFileResponse =
145         vendorSoftwareProductManager.process(vspId, USER1);
146     Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
147     Assert.assertTrue(MapUtils.isEmpty(
148         MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
149
150     validateUploadContentExistence(true);
151     validateCompositionDataExistence(false);
152   }
153 */}