1 package org.openecomp.sdc.vendorlicense.licenseartifacts.impl;
3 import org.apache.commons.io.IOUtils;
4 import org.apache.commons.lang3.StringUtils;
5 import org.openecomp.sdc.vendorlicense.ArtifactTestUtils;
6 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
7 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
8 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
9 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
10 import org.openecomp.sdc.versioning.dao.types.Version;
11 import org.openecomp.core.utilities.file.FileContentHandler;
12 import org.testng.Assert;
13 import org.testng.annotations.BeforeClass;
14 import org.testng.annotations.Test;
16 import java.io.IOException;
17 import java.nio.charset.StandardCharsets;
19 public class VendorLicenseArtifactsServiceTest extends ArtifactTestUtils {
20 private FileContentHandler licenseArtifacts;
24 public void createVNFArtifact() throws Exception {
25 Version vlmVersion = vspDetails.getVlmVersion();
26 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
27 String actual = IOUtils.toString(licenseArtifacts.getFileContent(
28 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
29 // System.out.println("createVnfArtifact = " + actual);
31 Assert.assertTrue(actual.contains("type"));
32 Assert.assertFalse(actual.contains(lkg13Id));
33 Assert.assertTrue(actual.contains(OperationalScope.Availability_Zone.toString()));
34 Assert.assertTrue(actual.contains("vf-id"));
35 Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
36 Assert.assertFalse(actual.contains("80.0"));
37 Assert.assertTrue(actual.contains("80"));
42 public void createVendorLicenseArtifact() throws Exception {
43 Version vlmVersion = vspDetails.getVlmVersion();
45 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
46 String actual = IOUtils.toString(licenseArtifacts.getFileContent(
47 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
49 // System.out.println("createVendorLicenseArtifact = " + actual);
50 Assert.assertFalse(actual.contains(lkg11Id));
51 Assert.assertFalse(actual.contains(ep11Id));
52 Assert.assertTrue(actual.contains("type"));
53 Assert.assertTrue(actual.contains(EntitlementMetric.Core.toString()));
54 Assert.assertTrue(actual.contains("entitlement-pool-list"));
55 Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
57 Assert.assertTrue(actual.contains("vendor-license-model"));
58 Assert.assertFalse(actual.contains("80.0"));
59 Assert.assertTrue(actual.contains("80"));
63 public void vNFArtifactContainsCurrentVLMVersion() throws IOException {
64 super.setVlm2FirstVersion();
65 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1);
66 String actual = IOUtils.toString(licenseArtifacts.getFileContent(
67 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
69 Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
73 public void vnfArtifactContainsSameIdAsVLMArtifact() throws IOException {
74 Version vlmVersion = vspDetails.getVlmVersion();
75 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
76 String actualVnfArtifact = IOUtils.toString(licenseArtifacts.getFileContent(
77 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
78 String actualVendorLicenseArtifact = IOUtils.toString(licenseArtifacts.getFileContent(
79 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
81 String firstLKGUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<license-key-group-uuid>") + 24, actualVnfArtifact.indexOf("<license-key-group-uuid>") + 60);
82 Assert.assertTrue(actualVendorLicenseArtifact.contains(firstLKGUUID));
84 String firstEPUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 23, actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 60);
85 Assert.assertTrue(actualVendorLicenseArtifact.contains(firstEPUUID));
90 public void vNFArtifactContainsPreviousVLMVersionAndNotLatest() throws IOException {
91 super.setVlm2SecondVersion();
92 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1);
93 String actual = IOUtils.toString(licenseArtifacts.getFileContent(
94 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
96 Assert.assertTrue(actual.contains(lkg21.getVersionUuId()));
97 Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
98 Assert.assertFalse(actual.contains(lkg22Id));
99 Assert.assertFalse(actual.contains(ep22Id));
102 Assert.assertTrue(actual.contains("80"));
107 public void onlyAddChangedEntitiesToVendorArtifact() throws IOException {
108 Version vlmVersion = vspDetails.getVlmVersion();
110 EntitlementPoolEntity updatedEP = ep11;
111 String updatedNameEP = "updatedNameEP";
112 updatedEP.setName(updatedNameEP);
113 LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity();
114 updatedLKG.setId(lkg11Id);
115 updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId());
116 String updateDescLKG = "UpdateDescLKG";
117 updatedLKG.setName(lkg11.getName());
118 updatedLKG.setDescription(updateDescLKG);
120 createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP, updatedLKG);
121 licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
122 String actual = IOUtils.toString(licenseArtifacts.getFileContent(
123 org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
124 // System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual);
126 int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG);
127 Assert.assertEquals(countUpdatedLKG, 1);
129 int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP);
130 Assert.assertEquals(countUpdatedEp, 1);
132 int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>");
133 Assert.assertEquals(epOccurrences, 3);
137 public void setUp() {