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;
129 public enum OnboardingMethod {
134 OnboardingMethod(String method) {
135 this.method = method;
138 private String method;
142 protected static VspDetails createVspDetails(String id, Version version, String name, String desc,
143 String vendorName, String vlm, String icon,
144 String category, String subCategory,
145 String licenseAgreement,
146 List<String> featureGroups,
147 String onboardingMethod) {
148 VspDetails vspDetails = new VspDetails(id, version);
149 vspDetails.setName(name);
150 vspDetails.setDescription(desc);
151 vspDetails.setIcon(icon);
152 vspDetails.setCategory(category);
153 vspDetails.setSubCategory(subCategory);
154 vspDetails.setVendorName(vendorName);
155 vspDetails.setVendorId(vlm);
156 vspDetails.setLicenseAgreement(licenseAgreement);
157 vspDetails.setFeatureGroups(featureGroups);
158 vspDetails.setOnboardingMethod(onboardingMethod);
163 public void setUp() {
165 opScopeChoices = new HashSet<>();
166 opScopeChoices.add(OperationalScope.Other);
167 opScopeChoices.add(OperationalScope.Data_Center);
168 opScopeChoices.add(OperationalScope.Network_Wide);
170 opScopeChoicesLKG = new HashSet<>();
171 opScopeChoicesLKG.add(OperationalScope.CPU);
172 opScopeChoicesLKG.add(OperationalScope.VM);
173 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
174 opScopeChoicesLKG.add(OperationalScope.Data_Center);
176 vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
177 .createVendorLicenseModel("vlm1 name_" + CommonMethods.nextUuId(), "vlm1Id desc",
180 vlm2Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
181 .createVendorLicenseModel("vlm2 name_" + CommonMethods.nextUuId(), "vlm2Id desc",
184 // vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
185 // .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
190 Set<OperationalScope> opScopeChoices = new HashSet<>();
191 opScopeChoices.add(OperationalScope.Other);
192 opScopeChoices.add(OperationalScope.Data_Center);
193 opScopeChoices.add(OperationalScope.Network_Wide);
195 ep11 = EntitlementPoolTest
196 .createEntitlementPool(vlm1Id, VERSION01, "EP1_" + CommonMethods.nextUuId(), "EP1 dec", 80,
197 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
198 "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
199 ep11Id = vendorLicenseManager.createEntitlementPool(ep11, USER1).getId();
200 ep12 = EntitlementPoolTest
201 .createEntitlementPool(vlm1Id, VERSION01, "EP2_" + CommonMethods.nextUuId(), "EP2 dec", 70,
202 ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2", "inc2",
203 AggregationFunction.Average, null, opScopeChoices, "op scope2", EntitlementTime.Other,
205 ep12Id = vendorLicenseManager.createEntitlementPool(ep12, USER1).getId();
207 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
208 opScopeChoicesLKG.add(OperationalScope.CPU);
209 opScopeChoicesLKG.add(OperationalScope.VM);
210 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
211 opScopeChoicesLKG.add(OperationalScope.Data_Center);
213 lkg11 = LicenseKeyGroupTest
214 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG1", "LKG1 dec", LicenseKeyType.One_Time,
215 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
216 lkg11Id = vendorLicenseManager.createLicenseKeyGroup(lkg11, USER1).getId();
217 lkg11.setId(lkg11Id);
219 lkg12 = LicenseKeyGroupTest
220 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Unique,
221 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
222 lkg12Id = vendorLicenseManager.createLicenseKeyGroup(lkg12, USER1).getId();
223 lkg12.setId(lkg11Id);
225 lkg13 = LicenseKeyGroupTest
226 .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG3", "LKG3 dec", LicenseKeyType.Universal,
227 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
228 lkg13Id = vendorLicenseManager.createLicenseKeyGroup(lkg13, USER1).getId();
229 lkg13.setId(lkg13Id);
231 fg11 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc",
232 CommonMethods.toSingleElementSet(ep11Id), CommonMethods.toSingleElementSet(lkg11Id));
233 fg11Id = vendorLicenseManager.createFeatureGroup(fg11, USER1).getId();
235 fg12 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc",
236 CommonMethods.toSingleElementSet(ep12Id), CommonMethods.toSingleElementSet(lkg12Id));
237 fg12Id = vendorLicenseManager.createFeatureGroup(fg12, USER1).getId();
240 String requirementsAndConstrains1 = "Requirements And Constraints1";
241 LicenseAgreementEntity
242 la1 = LicenseAgreementTest
243 .createLicenseAgreement(vlm1Id, VERSION01, null, "LA1", "LA1 desc",
244 requirementsAndConstrains1, new ChoiceOrOther<>(
245 LicenseTerm.Unlimited, null), fg11Id);
246 la11Id = vendorLicenseManager.createLicenseAgreement(la1, USER1).getId();
248 List<String> fgs = new ArrayList<>();
250 createTwoFinalVersionsForVLM(vlm1Id);
251 VersionInfo versionInfo =
252 vendorLicenseFacade.getVersionInfo(vlm1Id, VersionableEntityAction.Read, "");
254 createVspDetails(null, null, "VSP1_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
255 vlm1Id, "icon", "category", "subCategory", la11Id, fgs, ArtifactTestUtils
256 .OnboardingMethod.HEAT.name());
258 List<Version> finalVersions = versionInfo.getFinalVersions();
259 Version finalVersion = finalVersions.get(1);
261 vspDetails.setVlmVersion(finalVersion);
263 vspDetails = vendorSoftwareProductManager.createVsp(vspDetails, USER1);
267 private void createTwoFinalVersionsForVLM(String vlm1Id) {
268 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
269 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
270 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
271 vendorLicenseFacade.submit(vlm1Id, USER1);
272 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
273 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc2");
274 vendorLicenseFacade.submit(vlm1Id, USER1);
278 protected VspDetails createVspWithSpecifiedVlmVersion(String vlmToUse, Version vlmVersionToUse,
279 List<String> fgs, String
280 licenceAgreementId) {
282 createVspDetails(null, null, "VSP3_" + CommonMethods.nextUuId(), "VSP3",
284 vlm3Id, "icon", "category", "subCategory", licenceAgreementId, fgs, OnboardingMethod
286 VersionInfo versionInfo =
287 vendorLicenseFacade.getVersionInfo(vlmToUse, VersionableEntityAction.Read, "");
290 vspDetailsVsp3.setVlmVersion(vlmVersionToUse);
292 return vendorSoftwareProductManager.createVsp(vspDetailsVsp3, USER1);
295 protected void createAndSetupVlm3() {
296 vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
297 .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
300 ep3_1 = EntitlementPoolTest
301 .createEntitlementPool(vlm3Id, VERSION01, "EP3_" + CommonMethods.nextUuId(), "EP3 dec",
303 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
304 "agg func1", opScopeChoices, null, EntitlementTime.Quarter, null, "sku1");
305 ep3_1Id = vendorLicenseManager.createEntitlementPool(ep3_1, USER1).getId();
306 lkg3_1 = LicenseKeyGroupTest
307 .createLicenseKeyGroup(vlm3Id, VERSION01, "LKG3_" + CommonMethods.nextUuId(), "LKG3 dec",
308 LicenseKeyType.Unique,
309 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
310 lkg3_1Id = vendorLicenseManager.createLicenseKeyGroup(lkg3_1, USER1).getId();
311 lkg3_1.setId(lkg3_1Id);
313 FeatureGroupEntity fg3 = LicenseAgreementTest.createFeatureGroup(vlm3Id, VERSION01,
314 "fg3" + CommonMethods.nextUuId(),
317 CommonMethods.toSingleElementSet(ep3_1Id), CommonMethods.toSingleElementSet(lkg3_1Id));
318 String fg3Id = vendorLicenseManager.createFeatureGroup(fg3, USER1).getId();
319 String requirementsAndConstrains1 = "Requirements And Constraints1";
320 licenseAgreementVlm3 = LicenseAgreementTest
321 .createLicenseAgreement(vlm3Id, VERSION01, null, "LA3", "LA1 desc",
322 requirementsAndConstrains1, new ChoiceOrOther<>(
323 LicenseTerm.Unlimited, null), fg3Id);
325 vendorLicenseManager.createLicenseAgreement(licenseAgreementVlm3, USER1).getId();
327 featureGroupsforVlm3 = new ArrayList<>();
328 featureGroupsforVlm3.add(fg3Id);
332 protected void addEpToVLM(String vlmToAddEP) {
333 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
334 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
335 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
336 vendorLicenseFacade.submit(vlmToAddEP, USER1);
339 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
341 EntitlementPoolEntity addedEp = EntitlementPoolTest
342 .createEntitlementPool(vlmToAddEP, VERSION01, "EP_ADDED" + CommonMethods.nextUuId(),
344 " desc" + CommonMethods.nextUuId(), 99,
347 EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
348 opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
349 String addedEpId = vendorLicenseManager.createEntitlementPool(addedEp, USER1).getId();
350 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
351 vendorLicenseFacade.submit(vlmToAddEP, USER1);
352 VersionInfo versionInfo =
353 vendorLicenseFacade.getVersionInfo(vlm3Id, VersionableEntityAction.Read, "");
356 protected void createThirdFinalVersionForVLMChangeEpLKGInSome(String vlm1Id,
357 EntitlementPoolEntity ep,
358 LicenseKeyGroupEntity lkg) {
359 versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
360 vendorLicenseManager.updateEntitlementPool(ep, USER1);
361 vendorLicenseManager.updateLicenseKeyGroup(lkg, USER1);
362 versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
363 vendorLicenseFacade.submit(vlm1Id, USER1);
367 protected void setVlm2FirstVersion() {
370 ep21 = EntitlementPoolTest
371 .createEntitlementPool(vlm2Id, VERSION01, "EP21", "EP21 dec", 80, ThresholdUnit.Absolute,
372 EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
373 opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
374 ep21Id = vendorLicenseManager.createEntitlementPool(ep21, USER1).getId();
376 lkg21 = LicenseKeyGroupTest
377 .createLicenseKeyGroup(vlm2Id, VERSION01, "LKG21", "LKG21 dec", LicenseKeyType.One_Time,
378 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
379 lkg21Id = vendorLicenseManager.createLicenseKeyGroup(lkg21, USER1).getId();
380 lkg21.setId(lkg21Id);
382 fg21 = LicenseAgreementTest.createFeatureGroup(vlm2Id, VERSION01, "fg21", "FG21", "FG21 desc",
383 CommonMethods.toSingleElementSet(ep21Id), CommonMethods.toSingleElementSet(lkg21Id));
384 fg21Id = vendorLicenseManager.createFeatureGroup(fg21, USER1).getId();
386 String requirementsAndConstrains1 = "Requirements And Constraints21";
387 LicenseAgreementEntity la2 = LicenseAgreementTest
388 .createLicenseAgreement(vlm2Id, VERSION01, null, "LA21", "LA21 desc",
389 requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg21Id);
390 la21Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
392 // setValuesForVlm(VERSION01, ep21, ep21Id, lkg21, lkg21Id, fg21, fg21Id, la21Id, 1);
394 vendorLicenseManager.checkin(vlm2Id, USER1);
396 versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
398 List<String> fgs = new ArrayList<>();
401 createVspDetails(null, null, "VSP2_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
402 vlm2Id, "icon", "category", "subCategory", la21Id, fgs, OnboardingMethod.HEAT.name());
403 vsp2 = vendorSoftwareProductManager.createVsp(vsp2, USER1);
406 protected void setVlm2SecondVersion() {
407 vendorLicenseManager.checkout(vlm2Id, USER1);
409 Set<OperationalScope> opScopeChoices = new HashSet<>();
410 opScopeChoices.add(OperationalScope.Other);
411 opScopeChoices.add(OperationalScope.Data_Center);
412 opScopeChoices.add(OperationalScope.Network_Wide);
414 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
415 opScopeChoicesLKG.add(OperationalScope.CPU);
416 opScopeChoicesLKG.add(OperationalScope.VM);
417 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
418 opScopeChoicesLKG.add(OperationalScope.Data_Center);
420 ep22 = EntitlementPoolTest
421 .createEntitlementPool(vlm2Id, currVersion, "EP22", "EP22 dec", 80, ThresholdUnit.Absolute,
422 EntitlementMetric.Core, null, "inc22", AggregationFunction.Other, "agg func22",
423 opScopeChoices, null, EntitlementTime.Hour, null, "sku22");
424 ep22Id = vendorLicenseManager.createEntitlementPool(ep22, USER1).getId();
426 lkg22 = LicenseKeyGroupTest
427 .createLicenseKeyGroup(vlm2Id, currVersion, "LKG22", "LKG22 dec", LicenseKeyType.One_Time,
428 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
429 lkg22Id = vendorLicenseManager.createLicenseKeyGroup(lkg22, USER1).getId();
430 lkg22.setId(lkg22Id);
432 fg22 = LicenseAgreementTest.createFeatureGroup(vlm2Id, currVersion, "fg22", "FG22", "FG22 desc",
433 CommonMethods.toSingleElementSet(ep22Id), CommonMethods.toSingleElementSet(lkg22Id));
434 fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId();
436 String requirementsAndConstrains1 = "Requirements And Constraints22";
437 LicenseAgreementEntity la2 = LicenseAgreementTest
438 .createLicenseAgreement(vlm2Id, currVersion, null, "LA22", "LA22 desc",
439 requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg22Id);
440 la22Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
442 // setValuesForVlm(currVersion, ep22, ep22Id, lkg22, lkg22Id, fg22, fg22Id, la22Id, 2);
444 vendorLicenseManager.checkin(vlm2Id, USER1);
446 versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);