aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java
blob: f1bf5682e03a3c71b85560b503f2ad1752e8b5e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package org.openecomp.sdc.vendorsoftwareproduct.upload.HeatCleanup;

import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.vendorsoftwareproduct.VSPCommon;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.core.model.dao.ServiceModelDao;
import org.openecomp.core.model.dao.ServiceModelDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.core.validation.types.MessageContainerUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;

public class HeatCleanupOnNewUploadTest {
  private static final String USER1 = "vspTestUser1";

  private static final VendorSoftwareProductManager vendorSoftwareProductManager =
      new VendorSoftwareProductManagerImpl();
  private static final VendorSoftwareProductDao vendorSoftwareProductDao =
      VendorSoftwareProductDaoFactory.getInstance().createInterface();
  private static final ServiceModelDao serviceModelDao =
      ServiceModelDaoFactory.getInstance().createInterface();

  private static String vspId = null;
  private static Version vspActiveVersion = null;

  private static void validateUploadContentExistence(boolean exist) {
    UploadDataEntity uploadDataEntity =
        vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, vspActiveVersion));
    Assert.assertTrue((uploadDataEntity.getContentData() != null) == exist);
    Assert.assertTrue((uploadDataEntity.getValidationData() != null) == exist);
    Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist);
    Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist);
    Assert.assertTrue((serviceModelDao.getServiceModel(vspId, vspActiveVersion) != null) == exist);
  }

  private static void validateCompositionDataExistence(boolean exist) {
    Assert.assertTrue(CollectionUtils
        .isNotEmpty(vendorSoftwareProductDao.listNetworks(vspId, vspActiveVersion)) == exist);
    Assert.assertTrue(CollectionUtils
        .isNotEmpty(vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion)) == exist);
    Assert.assertTrue(CollectionUtils
        .isNotEmpty(vendorSoftwareProductDao.listNicsByVsp(vspId, vspActiveVersion)) == exist);
  }

  private static InputStream getFileInputStream(String fileName) {
    URL url = HeatCleanupOnNewUploadTest.class.getResource(fileName);
    try {
      return url.openStream();
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
  }

  @BeforeClass
  private void init() {
    UniqueValueUtil
        .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
            "VSPTestEmpty");

    VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSPTestEmpty", "Test-vsp-empty", "vendorName", "vlm1Id",
            "icon", "category", "subCategory", "123", null), USER1);
    vspId = vspDetails.getId();
    vspActiveVersion = vspDetails.getVersion();
  }

  @Test
  public void testUploadWithComposition() {
    InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");

    UploadFileResponse uploadFileResponse =
        vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);

    Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
    Assert.assertTrue(MapUtils.isEmpty(
        MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));

    validateUploadContentExistence(true);
    validateCompositionDataExistence(true);
  }

  @Test(dependsOnMethods = {"testUploadWithComposition"})
  public void testProccesesMIBsDeletionAfterNewUpload() {
    InputStream zis1 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
    InputStream zis2 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
    InputStream mib = getFileInputStream("/vspmanager/zips/vDNS.zip");

    vendorSoftwareProductManager.uploadFile(vspId, zis1, USER1);
    List<ComponentEntity> components =
        (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion);
    String componentId = components.get(0).getId();

    vendorSoftwareProductManager
        .uploadComponentMib(mib, "vDNS.zip", vspId, componentId, true, USER1);
    vendorSoftwareProductManager
        .createProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);

    vendorSoftwareProductManager.uploadFile(vspId, zis2, USER1);
    Assert.assertTrue(
        vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1).getSnmpTrap() ==
            null);
    Assert.assertTrue(CollectionUtils
        .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
  }

  @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
  public void testInvalidStructureUploadAfterFullComposition() {
    InputStream zis = getFileInputStream("/vspmanager/zips/withoutManifest.zip");

    UploadFileResponse uploadFileResponse =
        vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
    Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Failure);
    Assert.assertTrue(MapUtils.isNotEmpty(
        MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));

    validateUploadContentExistence(true);
    validateCompositionDataExistence(true);
  }

  @Test(dependsOnMethods = {"testInvalidStructureUploadAfterFullComposition"})
  public void testInvalidUploadAfterFullComposition() {
    InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");

    UploadFileResponse uploadFileResponse =
        vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
    Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
    Assert.assertTrue(MapUtils.isNotEmpty(
        MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));

    validateUploadContentExistence(true);
    validateCompositionDataExistence(false);
  }

  @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
  public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
    testUploadWithComposition();

    InputStream zis = getFileInputStream("/vspmanager/zips/emptyComposition.zip");
    UploadFileResponse uploadFileResponse =
        vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
    Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
    Assert.assertTrue(MapUtils.isEmpty(
        MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));

    validateUploadContentExistence(true);
    validateCompositionDataExistence(false);
  }
}