aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java
blob: 13f3859c0cc1e7a00722718672d085a88f3c1914 (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
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.vendorsoftwareproduct.upload.HeatCleanup;

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.getInfo() != null) == exist);
    Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist);
    Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist);
    //TODO: talio - delete enrich data on new upload
    //Assert.assertTrue((serviceModelDao.getServiceModel(vspId, vspActiveVersion) != null) == ex
  }

  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 exception) {
      exception.printStackTrace();
      return null;
    }
  }

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

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

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

    vendorSoftwareProductManager.upload(vspId, zis, USER1);
    OrchestrationTemplateActionResponse orchestrationTemplateActionResponse =
        vendorSoftwareProductManager.process(vspId, USER1);

    Assert.assertEquals(orchestrationTemplateActionResponse.getStatus(), UploadFileStatus.Success);
    Assert.assertTrue(MapUtils.isEmpty(MessageContainerUtil
        .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.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.upload(vspId, zis1, USER1);
    vendorSoftwareProductManager.process(vspId, USER1);
    List<ComponentEntity> components =
        (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion);
    String componentId = components.get(0).getId();

    vendorSoftwareProductManager
        .upload(mib, "vDNS.zip", vspId, componentId, MonitoringUploadType.SNMP_TRAP, USER1);
    vendorSoftwareProductManager
        .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);

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

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

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

    validateUploadContentExistence(true);
    //TODO: talio - check upload cleanup
//    validateCompositionDataExistence(false);
  }

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

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

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