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.getInfo() != 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, VSPCommon.OnboardingMethod.HEAT.name()),
77 vspId = vspDetails.getId();
78 vspActiveVersion = vspDetails.getVersion();
82 public void testUploadWithComposition() {
83 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
85 vendorSoftwareProductManager.upload(vspId, zis, USER1);
86 OrchestrationTemplateActionResponse orchestrationTemplateActionResponse =
87 vendorSoftwareProductManager.process(vspId, USER1);
89 Assert.assertEquals(orchestrationTemplateActionResponse.getStatus(), UploadFileStatus.Success);
90 Assert.assertTrue(MapUtils.isEmpty(MessageContainerUtil
91 .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.getErrors())));
93 validateUploadContentExistence(true);
94 validateCompositionDataExistence(true);
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");
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();
109 vendorSoftwareProductManager
110 .upload(mib, "vDNS.zip", vspId, componentId, MonitoringUploadType.SNMP_TRAP, USER1);
111 vendorSoftwareProductManager
112 .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);
114 vendorSoftwareProductManager.upload(vspId, zis2, USER1);
115 vendorSoftwareProductManager.process(vspId, USER1);
117 vendorSoftwareProductManager.listFilenames(vspId, componentId, USER1).getSnmpTrap() ==
119 Assert.assertTrue(CollectionUtils
120 .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
123 @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
124 public void testInvalidUploadAfterFullComposition() {
125 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
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())));
134 validateUploadContentExistence(true);
135 //TODO: talio - check upload cleanup
136 // validateCompositionDataExistence(false);
139 @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
140 public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
141 testUploadWithComposition();
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())));
151 validateUploadContentExistence(true);
152 validateCompositionDataExistence(false);