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.upload.HeatCleanup;
23 public class HeatCleanupOnNewUploadTest {/*
24 private static final String USER1 = "vspTestUser1";
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();
34 private static String vspId = null;
35 private static Version vspActiveVersion = null;
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
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);
57 private static InputStream getFileInputStream(String fileName) {
58 URL url = HeatCleanupOnNewUploadTest.class.getResource(fileName);
60 return url.openStream();
61 } catch (IOException exception) {
62 exception.printStackTrace();
70 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
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();
81 public void testUploadWithComposition() {
82 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
84 vendorSoftwareProductManager.upload(vspId, zis, USER1);
85 OrchestrationTemplateActionResponse orchestrationTemplateActionResponse =
86 vendorSoftwareProductManager.process(vspId, USER1);
88 Assert.assertEquals(orchestrationTemplateActionResponse.getStatus(), UploadFileStatus.Success);
89 Assert.assertTrue(MapUtils.isEmpty(MessageContainerUtil
90 .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.getErrors())));
92 validateUploadContentExistence(true);
93 validateCompositionDataExistence(true);
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");
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();
108 vendorSoftwareProductManager
109 .upload(mib, "vDNS.zip", vspId, componentId, ArtifactType.SNMP_TRAP, USER1);
110 vendorSoftwareProductManager
111 .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);
113 vendorSoftwareProductManager.upload(vspId, zis2, USER1);
114 vendorSoftwareProductManager.process(vspId, USER1);
116 vendorSoftwareProductManager.listFilenames(vspId, componentId, USER1).getSnmpTrap() ==
118 Assert.assertTrue(CollectionUtils
119 .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
122 @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
123 public void testInvalidUploadAfterFullComposition() {
124 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
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())));
133 validateUploadContentExistence(true);
134 //TODO: talio - check upload cleanup
135 // validateCompositionDataExistence(false);
138 @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
139 public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
140 testUploadWithComposition();
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())));
150 validateUploadContentExistence(true);
151 validateCompositionDataExistence(false);