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.vendorlicense.licenseartifacts.impl;
23 import org.apache.commons.io.IOUtils;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openecomp.core.utilities.file.FileContentHandler;
26 import org.openecomp.sdc.vendorlicense.ArtifactTestUtils;
27 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
28 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
29 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
30 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
31 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33 import org.testng.Assert;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 import java.io.IOException;
38 import java.nio.charset.StandardCharsets;
41 public class VendorLicenseArtifactsServiceTest extends ArtifactTestUtils {
42 private FileContentHandler licenseArtifacts;
47 public void createVNFArtifact() throws Exception {
48 Version vlmVersion = vspDetails.getVlmVersion();
49 licenseArtifacts = vendorLicenseArtifactsService
50 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
51 vspDetails.getFeatureGroups(), USER1);
52 String actual = IOUtils.toString(
53 licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
54 StandardCharsets.UTF_8);
55 System.out.println("createVNFArtifact = " + actual);
57 Assert.assertTrue(actual.contains("type"));
58 Assert.assertFalse(actual.contains(lkg13Id));
59 Assert.assertTrue(actual.contains(OperationalScope.Availability_Zone.toString()));
60 Assert.assertTrue(actual.contains("vf-id"));
62 actual.contains(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
63 Assert.assertFalse(actual.contains("80.0"));
64 Assert.assertTrue(actual.contains("80"));
65 Assert.assertFalse(actual.contains("versionForArtifact"));
69 public void createVendorLicenseArtifact() throws Exception {
70 Version vlmVersion = vspDetails.getVlmVersion();
72 licenseArtifacts = vendorLicenseArtifactsService
73 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
74 vspDetails.getFeatureGroups(), USER1);
75 String actual = IOUtils.toString(licenseArtifacts
76 .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
77 StandardCharsets.UTF_8);
79 //System.out.println("createVendorLicenseArtifact = " + actual);
80 Assert.assertTrue(actual.contains(lkg11Id));
81 Assert.assertTrue(actual.contains(ep11Id));
82 Assert.assertTrue(actual.contains("type"));
83 Assert.assertTrue(actual.contains(EntitlementMetric.Core.toString()));
84 Assert.assertTrue(actual.contains("entitlement-pool-list"));
86 actual.contains(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
88 Assert.assertTrue(actual.contains("vendor-license-model"));
89 Assert.assertFalse(actual.contains("80.0"));
90 Assert.assertTrue(actual.contains("80"));
94 public void vNFArtifactContainsCurrentVLMVersion() throws IOException {
95 super.setVlm2FirstVersion();
96 licenseArtifacts = vendorLicenseArtifactsService
97 .createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(),
98 vsp2.getFeatureGroups(), USER1);
99 String actual = IOUtils.toString(
100 licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
101 StandardCharsets.UTF_8);
103 // Assert.assertTrue(actual.contains(lkg21Id));
104 Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
108 public void vnfArtifactContainsSameIdAsVLMArtifact() throws IOException {
109 Version vlmVersion = vspDetails.getVlmVersion();
110 licenseArtifacts = vendorLicenseArtifactsService
111 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
112 vspDetails.getFeatureGroups(), USER1);
113 String actualVnfArtifact = IOUtils.toString(
114 licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
115 StandardCharsets.UTF_8);
116 String actualVendorLicenseArtifact = IOUtils.toString(licenseArtifacts
117 .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
118 StandardCharsets.UTF_8);
120 String firstLKGUUID = actualVnfArtifact
121 .substring(actualVnfArtifact.indexOf("<license-key-group-uuid>") + 24,
122 actualVnfArtifact.indexOf("<license-key-group-uuid>") + 60);
123 Assert.assertTrue(actualVendorLicenseArtifact.contains(firstLKGUUID));
125 String firstEPUUID = actualVnfArtifact
126 .substring(actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 23,
127 actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 60);
128 Assert.assertTrue(actualVendorLicenseArtifact.contains(firstEPUUID));
133 public void vNFArtifactContainsPreviousVLMVersionAndNotLatest() throws IOException {
134 super.setVlm2SecondVersion();
135 licenseArtifacts = vendorLicenseArtifactsService
136 .createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(),
137 vsp2.getFeatureGroups(), USER1);
138 String actual = IOUtils.toString(
139 licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
140 StandardCharsets.UTF_8);
142 Assert.assertTrue(actual.contains(lkg21.getVersionUuId()));
143 Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
144 Assert.assertFalse(actual.contains(lkg22Id));
145 Assert.assertFalse(actual.contains(ep22Id));
148 Assert.assertTrue(actual.contains("80"));
153 public void vlmVersionTwoThenUpdatingLKGAndEpInThird() throws IOException {
154 Version vlmVersion = vspDetails.getVlmVersion();
156 EntitlementPoolEntity updatedEP = ep11;
157 String updatedNameEP = "updatedNameEP";
158 updatedEP.setName(updatedNameEP);
159 LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity();
160 updatedLKG.setId(lkg11Id);
161 updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId());
162 String updateDescLKG = "UpdateDescLKG";
163 updatedLKG.setName(lkg11.getName());
164 updatedLKG.setDescription(updateDescLKG);
166 createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP,
168 licenseArtifacts = vendorLicenseArtifactsService
169 .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
170 vspDetails.getFeatureGroups(), USER1);
171 String actual = IOUtils.toString(licenseArtifacts
172 .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
173 StandardCharsets.UTF_8);
174 System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual);
176 int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG);
177 Assert.assertEquals(countUpdatedLKG, 1);
179 int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP);
180 Assert.assertEquals(countUpdatedEp, 1);
182 int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>");
183 Assert.assertEquals(epOccurrences, 3);
187 @Test(invocationCount = 5)
188 public void vlmVersionOneThenAddEp_bug2629() throws IOException {
189 createAndSetupVlm3();
191 createVspWithSpecifiedVlmVersion(vlm3Id,new Version(2,0),featureGroupsforVlm3,
192 licenseAgreementVlm3.getId());
194 Version vlmVersion = vspDetailsVsp3.getVlmVersion();
196 licenseArtifacts = vendorLicenseArtifactsService
197 .createLicenseArtifacts(vspDetailsVsp3.getId(), vspDetailsVsp3.getVendorId(),
199 vspDetailsVsp3.getFeatureGroups(), USER1);
200 String actual = IOUtils.toString(licenseArtifacts
201 .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
202 StandardCharsets.UTF_8);
203 System.out.println("vlmVersionOneThenAddEp_bug2629 = " + actual);
205 int countVersion2appearances = StringUtils.countMatches(actual, "<version>2.0</version>");
206 int countVersion1appearances = StringUtils.countMatches(actual, "<version>1.0</version>");
207 Assert.assertEquals(countVersion2appearances, 1);
208 Assert.assertEquals(countVersion1appearances, 2);
213 public void setUp() {