aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java
blob: d4dea70f2f36edbd0d4297e6f12d91c4d1ae6745 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*-
 * ============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;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils;
import org.openecomp.core.enrichment.types.ArtifactType;
import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
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.NicEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class VSPFullTest {
/*


  public static final Version VERSION01 = new Version(0, 1);
  private static final VendorSoftwareProductDao vendorSoftwareProductDao =
      VendorSoftwareProductDaoFactory
          .getInstance().createInterface();
  private static final String USER1 = "vspTestUser1";
  private static VendorSoftwareProductManager vendorSoftwareProductManager = null;
  //new VendorSoftwareProductManagerImpl();
  private static VendorLicenseFacade vendorLicenseFacade =
      VendorLicenseFacadeFactory.getInstance().createInterface();
  private OrchestrationTemplateCandidateManager candidateManager;
  private MibManager mibManager;
  private NicManager nicManager;

  @Test
  public void testEnrichModelInSubmit() {
    UniqueValueUtil
        .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
            "VSP_FullTest");

    String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
            .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
        USER1).getId();
    String entitlementPoolId = vendorLicenseFacade
        .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();

    FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null);
    featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
    String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();

    LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
    licenseAgreement.getFeatureGroupIds().add(featureGroupId);
    String licenseAgreementId =
        vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();

    vendorLicenseFacade.checkin(vlm1Id, USER1);
    vendorLicenseFacade.submit(vlm1Id, USER1);

    String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());

    Collection<ComponentEntity> components = uploadFullCompositionFile(vspId);

    InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip");
    mibManager
        .upload(zis1, "MMSC.zip", vspId, VERSION01,
            components.iterator().next().getId(),
            ArtifactType.SNMP_TRAP,
            USER1);

    //check in
    vendorSoftwareProductManager.checkin(vspId, USER1);
    //submit
    try {
      ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
      //Assert.assertTrue(result.isValid());
      //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);

    } catch (IOException exception) {
      Assert.fail();
    }
    VersionedVendorSoftwareProductInfo details =
        vendorSoftwareProductManager.getVsp(vspId, null, USER1);


    //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
    // writeFile(csar);


    ToscaServiceModel model =
        (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
            .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());

    Map<String, CapabilityDefinition> capabilities = new HashMap<>();
    for (ComponentEntity component : components) {
      model.getServiceTemplates().
          entrySet().
          stream().
          filter(entryValue -> entryValue.getValue() != null &&
              entryValue.getValue().getNode_types() != null &&
              entryValue.getValue().
                  getNode_types().
                  containsKey(component.getComponentCompositionData().getName())).
          forEach(entryValue -> entryValue.getValue().getNode_types().
              values().
              stream().
              filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
              forEach(type -> type.getCapabilities().
                  entrySet().
                  forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
                      entry.getValue()))));

    }

    Assert.assertNotNull(capabilities);
  }

  private Collection<ComponentEntity> uploadFullCompositionFile(String vspId) {
    candidateManager.upload(vspId, VERSION01,
        getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1);
    candidateManager.process(vspId, VERSION01, USER1);

    Collection<ComponentEntity> components = null;
    //vendorSoftwareProductManager.listComponents(vspId, null, USER1);
    Assert.assertFalse(components.isEmpty());

    for (ComponentEntity component : components) {
*/
/*      Assert.assertNotNull(vendorSoftwareProductManager
          .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//*


      Collection<NicEntity> nics =
          nicManager.listNics(vspId, null, component.getId(), USER1);
      Assert.assertFalse(nics.isEmpty());
      for (NicEntity nic : nics) {
        Assert.assertNotNull(nicManager
            .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData());
      }
    }

    return components;
  }

  private String createVsp(String vlm1Id, String licenseAgreementId, Set<String> featureGroupIds) {
    VspDetails expectedVsp = VSPCommon
        .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id,
            "icon", "category", "subCategory", licenseAgreementId,
            featureGroupIds.stream().collect(Collectors.toList()));
    String vspId = vendorSoftwareProductManager.createVsp(expectedVsp, USER1).getId();

    VspDetails actualVsp =
        vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
    expectedVsp.setId(vspId);
    expectedVsp.setVersion(VERSION01);

    //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp);
    Assert.assertNotNull(
        vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
    return vspId;
  }

  private void writeFile(File csar) {
    try {
      FileInputStream in = new FileInputStream(csar);
      File output = new File("CSAR_vDNS.zip");

      FileOutputStream out = new FileOutputStream(output);

      IOUtils.copy(in, out);
      in.close();
      out.close();
    } catch (IOException exception) {
      throw new RuntimeException(exception);
    }
  }

  private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
                             String key, CapabilityDefinition value) {

    capabilities.put(entryValueKey + "_" + key, value);
  }

  private InputStream getFileInputStream(String fileName) {
    URL url = this.getClass().getResource(fileName);
    try {
      return url.openStream();
    } catch (IOException exception) {
      exception.printStackTrace();
      return null;
    }
  }


*/
}