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;
23 import org.openecomp.core.utilities.CommonMethods;
24 import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction;
25 import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther;
26 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
27 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
28 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime;
29 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
30 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
31 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
32 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType;
33 import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm;
34 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
35 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
36 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
37 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
38 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
39 import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl;
40 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
41 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
42 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
43 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
44 import org.openecomp.sdc.versioning.VersioningManager;
45 import org.openecomp.sdc.versioning.VersioningManagerFactory;
46 import org.openecomp.sdc.versioning.dao.types.Version;
47 import org.openecomp.sdc.versioning.types.VersionInfo;
48 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
49 import org.testng.annotations.BeforeMethod;
51 import java.util.ArrayList;
52 import java.util.HashSet;
53 import java.util.List;
56 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE;
59 * Created by Katyr on 29-May-16
61 public class ArtifactTestUtils {
64 protected static final Version VERSION01 = new Version(0, 1);
65 protected static final String USER1 = "baseTest_TestUser1";
66 private static final VersioningManager versioningManager =
67 VersioningManagerFactory.getInstance().createInterface();
68 protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
69 protected static VendorSoftwareProductManager vendorSoftwareProductManager =
70 new VendorSoftwareProductManagerImpl();
71 protected static VendorLicenseFacade vendorLicenseFacade =
72 VendorLicenseFacadeFactory.getInstance().createInterface();
73 protected static VendorLicenseArtifactsService vendorLicenseArtifactsService =
74 VendorLicenseArtifactServiceFactory.getInstance().createInterface();
75 protected static Version currVersion;
77 protected String vlm1Id;
78 protected String vlm2Id;
80 protected String vlm3Id;
81 protected EntitlementPoolEntity ep3_1;
82 protected String ep3_1Id;
83 protected LicenseKeyGroupEntity lkg3_1;
84 protected String lkg3_1Id;
87 protected String ep11Id;
88 protected String ep12Id;
89 protected String lkg11Id;
90 protected String lkg12Id;
91 protected String lkg13Id;
92 protected String fg11Id;
93 protected String fg12Id;
94 protected String la11Id;
96 protected String ep21Id;
97 protected String ep22Id;
98 protected String lkg21Id;
99 protected String lkg22Id;
100 protected String fg21Id;
101 protected String fg22Id;
102 protected String la21Id;
103 protected String la22Id;
105 protected FeatureGroupEntity fg11;
106 protected FeatureGroupEntity fg12;
107 protected EntitlementPoolEntity ep11;
108 protected EntitlementPoolEntity ep12;
109 protected LicenseKeyGroupEntity lkg11;
110 protected LicenseKeyGroupEntity lkg12;
111 protected LicenseKeyGroupEntity lkg13;
113 protected FeatureGroupEntity fg21;
114 protected FeatureGroupEntity fg22;
115 protected EntitlementPoolEntity ep21;
116 protected EntitlementPoolEntity ep22;
117 protected LicenseKeyGroupEntity lkg21;
118 protected LicenseKeyGroupEntity lkg22;
120 protected VspDetails vspDetails;
121 protected VspDetails vsp2;
122 protected VspDetails vspDetailsVsp3;
123 private Set opScopeChoices;
124 private Set opScopeChoicesLKG;
125 private String la3_1Id;
126 protected List featureGroupsforVlm3;
127 protected LicenseAgreementEntity licenseAgreementVlm3;
130 protected static VspDetails createVspDetails(String id, Version version, String name, String desc,
131 String vendorName, String vlm, String icon,
132 String category, String subCategory,
133 String licenseAgreement,
134 List<String> featureGroups) {
135 VspDetails vspDetails = new VspDetails(id, version);
136 vspDetails.setName(name);
137 vspDetails.setDescription(desc);
138 vspDetails.setIcon(icon);
139 vspDetails.setCategory(category);
140 vspDetails.setSubCategory(subCategory);
141 vspDetails.setVendorName(vendorName);
142 vspDetails.setVendorId(vlm);
143 vspDetails.setLicenseAgreement(licenseAgreement);
144 vspDetails.setFeatureGroups(featureGroups);
149 public void setUp() {
151 opScopeChoices = new HashSet<>();
152 opScopeChoices.add(OperationalScope.Other);
153 opScopeChoices.add(OperationalScope.Data_Center);
154 opScopeChoices.add(OperationalScope.Network_Wide);
156 opScopeChoicesLKG = new HashSet<>();
157 opScopeChoicesLKG.add(OperationalScope.CPU);
158 opScopeChoicesLKG.add(OperationalScope.VM);
159 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
160 opScopeChoicesLKG.add(OperationalScope.Data_Center);
162 vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
163 .createVendorLicenseModel("vlm1 name_" + CommonMethods.nextUuId(), "vlm1Id desc",
166 vlm2Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
167 .createVendorLicenseModel("vlm2 name_" + CommonMethods.nextUuId(), "vlm2Id desc",
170 // vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
171 // .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
176 Set<OperationalScope> opScopeChoices = new HashSet<>();
177 opScopeChoices.add(OperationalScope.Other);
178 opScopeChoices.add(OperationalScope.Data_Center);
179 opScopeChoices.add(OperationalScope.Network_Wide);
181 ep11 = EntitlementPoolTest
182 .createEntitlementPool(vlm1Id, VERSION01, "EP1_" + CommonMethods.nextUuId(), "EP1 dec", 80,
183 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
184 "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
185 ep11Id = vendorLicenseManager.createEntitlementPool(ep11, USER1).getId();
186 ep12 = EntitlementPoolTest
187 .createEntitlementPool(vlm1Id, VERSION01, "EP2_" + CommonMethods.nextUuId(), "EP2 dec", 70,
188 ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2", "inc2",
189 AggregationFunction.Average, null, opScopeChoices, "op scope2", EntitlementTime.Other,
191 ep12Id = vendorLicenseManager.createEntitlementPool(ep12, USER1).getId();
193 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
194 opScopeChoicesLKG.add(OperationalScope.CPU);
195 opScopeChoicesLKG.add(OperationalScope.VM);
196 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
197 opScopeChoicesLKG.add(OperationalScope.Data_Center);
199 lkg11 = LicenseKeyGroupTest
200 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG1", "LKG1 dec", LicenseKeyType.One_Time,
201 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
202 lkg11Id = vendorLicenseManager.createLicenseKeyGroup(lkg11, USER1).getId();
203 lkg11.setId(lkg11Id);
205 lkg12 = LicenseKeyGroupTest
206 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Unique,
207 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
208 lkg12Id = vendorLicenseManager.createLicenseKeyGroup(lkg12, USER1).getId();
209 lkg12.setId(lkg11Id);
211 lkg13 = LicenseKeyGroupTest
212 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG3", "LKG3 dec", LicenseKeyType.Universal,
213 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
214 lkg13Id = vendorLicenseManager.createLicenseKeyGroup(lkg13, USER1).getId();
215 lkg13.setId(lkg13Id);
217 fg11 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc",
218 CommonMethods.toSingleElementSet(ep11Id), CommonMethods.toSingleElementSet(lkg11Id));
219 fg11Id = vendorLicenseManager.createFeatureGroup(fg11, USER1).getId();
221 fg12 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc",
222 CommonMethods.toSingleElementSet(ep12Id), CommonMethods.toSingleElementSet(lkg12Id));
223 fg12Id = vendorLicenseManager.createFeatureGroup(fg12, USER1).getId();
226 String requirementsAndConstrains1 = "Requirements And Constraints1";
227 LicenseAgreementEntity
228 la1 = LicenseAgreementTest
229 .createLicenseAgreement(vlm1Id, VERSION01, null, "LA1", "LA1 desc",
230 requirementsAndConstrains1, new ChoiceOrOther<>(
231 LicenseTerm.Unlimited, null), fg11Id);
232 la11Id = vendorLicenseManager.createLicenseAgreement(la1, USER1).getId();
234 List<String> fgs = new ArrayList<>();
236 createTwoFinalVersionsForVLM(vlm1Id);
237 VersionInfo versionInfo =
238 vendorLicenseFacade.getVersionInfo(vlm1Id, VersionableEntityAction.Read, "");
240 createVspDetails(null, null, "VSP1_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
241 vlm1Id, "icon", "category", "subCategory", la11Id, fgs);
243 List<Version> finalVersions = versionInfo.getFinalVersions();
244 Version finalVersion = finalVersions.get(1);
246 vspDetails.setVlmVersion(finalVersion);
248 vspDetails = vendorSoftwareProductManager.createVsp(vspDetails, USER1);
252 private void createTwoFinalVersionsForVLM(String vlm1Id) {
253 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
254 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
255 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
256 vendorLicenseFacade.submit(vlm1Id, USER1);
257 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
258 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc2");
259 vendorLicenseFacade.submit(vlm1Id, USER1);
263 protected VspDetails createVspWithSpecifiedVlmVersion(String vlmToUse, Version vlmVersionToUse,
264 List<String> fgs, String
265 licenceAgreementId) {
267 createVspDetails(null, null, "VSP3_" + CommonMethods.nextUuId(), "VSP3",
269 vlm3Id, "icon", "category", "subCategory", licenceAgreementId, fgs);
270 VersionInfo versionInfo =
271 vendorLicenseFacade.getVersionInfo(vlmToUse, VersionableEntityAction.Read, "");
274 vspDetailsVsp3.setVlmVersion(vlmVersionToUse);
276 return vendorSoftwareProductManager.createVsp(vspDetailsVsp3, USER1);
279 protected void createAndSetupVlm3() {
280 vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
281 .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
284 ep3_1 = EntitlementPoolTest
285 .createEntitlementPool(vlm3Id, VERSION01, "EP3_" + CommonMethods.nextUuId(), "EP3 dec",
287 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
288 "agg func1", opScopeChoices, null, EntitlementTime.Quarter, null, "sku1");
289 ep3_1Id = vendorLicenseManager.createEntitlementPool(ep3_1, USER1).getId();
290 lkg3_1 = LicenseKeyGroupTest
291 .createLicenseKeyGroup(vlm3Id, VERSION01, "LKG3_" + CommonMethods.nextUuId(), "LKG3 dec",
292 LicenseKeyType.Unique,
293 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
294 lkg3_1Id = vendorLicenseManager.createLicenseKeyGroup(lkg3_1, USER1).getId();
295 lkg3_1.setId(lkg3_1Id);
297 FeatureGroupEntity fg3 = LicenseAgreementTest.createFeatureGroup(vlm3Id, VERSION01,
298 "fg3" + CommonMethods.nextUuId(),
301 CommonMethods.toSingleElementSet(ep3_1Id), CommonMethods.toSingleElementSet(lkg3_1Id));
302 String fg3Id = vendorLicenseManager.createFeatureGroup(fg3, USER1).getId();
303 String requirementsAndConstrains1 = "Requirements And Constraints1";
304 licenseAgreementVlm3 = LicenseAgreementTest
305 .createLicenseAgreement(vlm3Id, VERSION01, null, "LA3", "LA1 desc",
306 requirementsAndConstrains1, new ChoiceOrOther<>(
307 LicenseTerm.Unlimited, null), fg3Id);
309 vendorLicenseManager.createLicenseAgreement(licenseAgreementVlm3, USER1).getId();
311 featureGroupsforVlm3 = new ArrayList<>();
312 featureGroupsforVlm3.add(fg3Id);
316 protected void addEpToVLM(String vlmToAddEP) {
317 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
318 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
319 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
320 vendorLicenseFacade.submit(vlmToAddEP, USER1);
323 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
325 EntitlementPoolEntity addedEp = EntitlementPoolTest
326 .createEntitlementPool(vlmToAddEP, VERSION01, "EP_ADDED" + CommonMethods.nextUuId(),
328 " desc" + CommonMethods.nextUuId(), 99,
331 EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
332 opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
333 String addedEpId = vendorLicenseManager.createEntitlementPool(addedEp, USER1).getId();
334 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
335 vendorLicenseFacade.submit(vlmToAddEP, USER1);
336 VersionInfo versionInfo =
337 vendorLicenseFacade.getVersionInfo(vlm3Id, VersionableEntityAction.Read, "");
340 protected void createThirdFinalVersionForVLMChangeEpLKGInSome(String vlm1Id,
341 EntitlementPoolEntity ep,
342 LicenseKeyGroupEntity lkg) {
343 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
344 vendorLicenseManager.updateEntitlementPool(ep, USER1);
345 vendorLicenseManager.updateLicenseKeyGroup(lkg, USER1);
346 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
347 vendorLicenseFacade.submit(vlm1Id, USER1);
351 protected void setVlm2FirstVersion() {
354 ep21 = EntitlementPoolTest
355 .createEntitlementPool(vlm2Id, VERSION01, "EP21", "EP21 dec", 80, ThresholdUnit.Absolute,
356 EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
357 opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
358 ep21Id = vendorLicenseManager.createEntitlementPool(ep21, USER1).getId();
360 lkg21 = LicenseKeyGroupTest
361 .createLicenseKeyGroup(vlm2Id, VERSION01, "LKG21", "LKG21 dec", LicenseKeyType.One_Time,
362 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
363 lkg21Id = vendorLicenseManager.createLicenseKeyGroup(lkg21, USER1).getId();
364 lkg21.setId(lkg21Id);
366 fg21 = LicenseAgreementTest.createFeatureGroup(vlm2Id, VERSION01, "fg21", "FG21", "FG21 desc",
367 CommonMethods.toSingleElementSet(ep21Id), CommonMethods.toSingleElementSet(lkg21Id));
368 fg21Id = vendorLicenseManager.createFeatureGroup(fg21, USER1).getId();
370 String requirementsAndConstrains1 = "Requirements And Constraints21";
371 LicenseAgreementEntity la2 = LicenseAgreementTest
372 .createLicenseAgreement(vlm2Id, VERSION01, null, "LA21", "LA21 desc",
373 requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg21Id);
374 la21Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
376 // setValuesForVlm(VERSION01, ep21, ep21Id, lkg21, lkg21Id, fg21, fg21Id, la21Id, 1);
378 vendorLicenseManager.checkin(vlm2Id, USER1);
380 versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
382 List<String> fgs = new ArrayList<>();
385 createVspDetails(null, null, "VSP2_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
386 vlm2Id, "icon", "category", "subCategory", la21Id, fgs);
387 vsp2 = vendorSoftwareProductManager.createVsp(vsp2, USER1);
390 protected void setVlm2SecondVersion() {
391 vendorLicenseManager.checkout(vlm2Id, USER1);
393 Set<OperationalScope> opScopeChoices = new HashSet<>();
394 opScopeChoices.add(OperationalScope.Other);
395 opScopeChoices.add(OperationalScope.Data_Center);
396 opScopeChoices.add(OperationalScope.Network_Wide);
398 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
399 opScopeChoicesLKG.add(OperationalScope.CPU);
400 opScopeChoicesLKG.add(OperationalScope.VM);
401 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
402 opScopeChoicesLKG.add(OperationalScope.Data_Center);
404 ep22 = EntitlementPoolTest
405 .createEntitlementPool(vlm2Id, currVersion, "EP22", "EP22 dec", 80, ThresholdUnit.Absolute,
406 EntitlementMetric.Core, null, "inc22", AggregationFunction.Other, "agg func22",
407 opScopeChoices, null, EntitlementTime.Hour, null, "sku22");
408 ep22Id = vendorLicenseManager.createEntitlementPool(ep22, USER1).getId();
410 lkg22 = LicenseKeyGroupTest
411 .createLicenseKeyGroup(vlm2Id, currVersion, "LKG22", "LKG22 dec", LicenseKeyType.One_Time,
412 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
413 lkg22Id = vendorLicenseManager.createLicenseKeyGroup(lkg22, USER1).getId();
414 lkg22.setId(lkg22Id);
416 fg22 = LicenseAgreementTest.createFeatureGroup(vlm2Id, currVersion, "fg22", "FG22", "FG22 desc",
417 CommonMethods.toSingleElementSet(ep22Id), CommonMethods.toSingleElementSet(lkg22Id));
418 fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId();
420 String requirementsAndConstrains1 = "Requirements And Constraints22";
421 LicenseAgreementEntity la2 = LicenseAgreementTest
422 .createLicenseAgreement(vlm2Id, currVersion, null, "LA22", "LA22 desc",
423 requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg22Id);
424 la22Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
426 // setValuesForVlm(currVersion, ep22, ep22Id, lkg22, lkg22Id, fg22, fg22Id, la22Id, 2);
428 vendorLicenseManager.checkin(vlm2Id, USER1);
430 versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);