Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / ArtifactTestUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorlicense;
22
23 /**
24  * Created by  Katyr on 29-May-16
25  */
26 public class ArtifactTestUtils {
27 /*
28
29   protected static final Version VERSION01 = new Version(0, 1);
30   protected static final String USER1 = "baseTest_TestUser1";
31   private static final VersioningManager versioningManager =
32       VersioningManagerFactory.getInstance().createInterface();
33   protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
34   protected static VendorSoftwareProductManager vendorSoftwareProductManager =
35       new VendorSoftwareProductManagerImpl();
36   protected static VendorLicenseFacade vendorLicenseFacade =
37       VendorLicenseFacadeFactory.getInstance().createInterface();
38   protected static VendorLicenseArtifactsService vendorLicenseArtifactsService =
39       VendorLicenseArtifactServiceFactory.getInstance().createInterface();
40   protected static Version currVersion;
41
42   protected String vlm1Id;
43   protected String vlm2Id;
44
45   protected String vlm3Id;
46   protected EntitlementPoolEntity ep3_1;
47   protected String ep3_1Id;
48   protected LicenseKeyGroupEntity lkg3_1;
49   protected String lkg3_1Id;
50
51
52   protected String ep11Id;
53   protected String ep12Id;
54   protected String lkg11Id;
55   protected String lkg12Id;
56   protected String lkg13Id;
57   protected String fg11Id;
58   protected String fg12Id;
59   protected String la11Id;
60
61   protected String ep21Id;
62   protected String ep22Id;
63   protected String lkg21Id;
64   protected String lkg22Id;
65   protected String fg21Id;
66   protected String fg22Id;
67   protected String la21Id;
68   protected String la22Id;
69
70   protected FeatureGroupEntity fg11;
71   protected FeatureGroupEntity fg12;
72   protected EntitlementPoolEntity ep11;
73   protected EntitlementPoolEntity ep12;
74   protected LicenseKeyGroupEntity lkg11;
75   protected LicenseKeyGroupEntity lkg12;
76   protected LicenseKeyGroupEntity lkg13;
77
78   protected FeatureGroupEntity fg21;
79   protected FeatureGroupEntity fg22;
80   protected EntitlementPoolEntity ep21;
81   protected EntitlementPoolEntity ep22;
82   protected LicenseKeyGroupEntity lkg21;
83   protected LicenseKeyGroupEntity lkg22;
84
85   protected VspDetails vspDetails;
86   protected VspDetails vsp2;
87   protected VspDetails vspDetailsVsp3;
88   private Set opScopeChoices;
89   private Set opScopeChoicesLKG;
90   private String la3_1Id;
91   protected List featureGroupsforVlm3;
92   protected LicenseAgreementEntity licenseAgreementVlm3;
93
94   public enum OnboardingMethod {
95     HEAT("HEAT"),
96     Manual("Manual");
97
98
99     OnboardingMethod(String method) {
100       this.method = method;
101     }
102
103     private  String method;
104   }
105
106
107   protected static VspDetails createVspDetails(String id, Version version, String name, String desc,
108                                                String vendorName, String vlm, String icon,
109                                                String category, String subCategory,
110                                                String licenseAgreement,
111                                                List<String> featureGroups,
112                                                String onboardingMethod) {
113     VspDetails vspDetails = new VspDetails(id, version);
114     vspDetails.setName(name);
115     vspDetails.setDescription(desc);
116     vspDetails.setIcon(icon);
117     vspDetails.setCategory(category);
118     vspDetails.setSubCategory(subCategory);
119     vspDetails.setVendorName(vendorName);
120     vspDetails.setVendorId(vlm);
121     vspDetails.setLicenseAgreement(licenseAgreement);
122     vspDetails.setFeatureGroups(featureGroups);
123     vspDetails.setOnboardingMethod(onboardingMethod);
124     return vspDetails;
125   }
126
127   @BeforeMethod
128   public void setUp() {
129
130     opScopeChoices = new HashSet<>();
131     opScopeChoices.add(OperationalScope.Other);
132     opScopeChoices.add(OperationalScope.Data_Center);
133     opScopeChoices.add(OperationalScope.Network_Wide);
134
135     opScopeChoicesLKG = new HashSet<>();
136     opScopeChoicesLKG.add(OperationalScope.CPU);
137     opScopeChoicesLKG.add(OperationalScope.VM);
138     opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
139     opScopeChoicesLKG.add(OperationalScope.Data_Center);
140
141     vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
142             .createVendorLicenseModel("vlm1 name_" + CommonMethods.nextUuId(), "vlm1Id desc",
143                 "icon1"),
144         USER1).getId();
145     vlm2Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
146             .createVendorLicenseModel("vlm2 name_" + CommonMethods.nextUuId(), "vlm2Id desc",
147                 "icon2"),
148         USER1).getId();
149 //    vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
150 //            .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
151 //                "icon2"),
152 //        USER1).getId();
153
154
155     Set<OperationalScope> opScopeChoices = new HashSet<>();
156     opScopeChoices.add(OperationalScope.Other);
157     opScopeChoices.add(OperationalScope.Data_Center);
158     opScopeChoices.add(OperationalScope.Network_Wide);
159
160     ep11 = EntitlementPoolTest
161         .createEntitlementPool(vlm1Id, VERSION01, "EP1_" + CommonMethods.nextUuId(), "EP1 dec", 80,
162             ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
163             "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
164     ep11Id = vendorLicenseManager.createEntitlementPool(ep11, USER1).getId();
165     ep12 = EntitlementPoolTest
166         .createEntitlementPool(vlm1Id, VERSION01, "EP2_" + CommonMethods.nextUuId(), "EP2 dec", 70,
167             ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2", "inc2",
168             AggregationFunction.Average, null, opScopeChoices, "op scope2", EntitlementTime.Other,
169             "time2", "sku2");
170     ep12Id = vendorLicenseManager.createEntitlementPool(ep12, USER1).getId();
171
172     Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
173     opScopeChoicesLKG.add(OperationalScope.CPU);
174     opScopeChoicesLKG.add(OperationalScope.VM);
175     opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
176     opScopeChoicesLKG.add(OperationalScope.Data_Center);
177
178     lkg11 = LicenseKeyGroupTest
179         .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG1", "LKG1 dec", LicenseKeyType.One_Time,
180             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
181     lkg11Id = vendorLicenseManager.createLicenseKeyGroup(lkg11, USER1).getId();
182     lkg11.setId(lkg11Id);
183
184     lkg12 = LicenseKeyGroupTest
185         .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Unique,
186             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
187     lkg12Id = vendorLicenseManager.createLicenseKeyGroup(lkg12, USER1).getId();
188     lkg12.setId(lkg11Id);
189
190     lkg13 = LicenseKeyGroupTest
191         .createLicenseKeyGroup(vlm1Id, VERSION01, "LKG3", "LKG3 dec", LicenseKeyType.Universal,
192             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
193     lkg13Id = vendorLicenseManager.createLicenseKeyGroup(lkg13, USER1).getId();
194     lkg13.setId(lkg13Id);
195
196     fg11 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc",
197         CommonMethods.toSingleElementSet(ep11Id), CommonMethods.toSingleElementSet(lkg11Id));
198     fg11Id = vendorLicenseManager.createFeatureGroup(fg11, USER1).getId();
199
200     fg12 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc",
201         CommonMethods.toSingleElementSet(ep12Id), CommonMethods.toSingleElementSet(lkg12Id));
202     fg12Id = vendorLicenseManager.createFeatureGroup(fg12, USER1).getId();
203
204
205     String requirementsAndConstrains1 = "Requirements And Constraints1";
206     LicenseAgreementEntity
207         la1 = LicenseAgreementTest
208         .createLicenseAgreement(vlm1Id, VERSION01, null, "LA1", "LA1 desc",
209             requirementsAndConstrains1, new ChoiceOrOther<>(
210                 LicenseTerm.Unlimited, null), fg11Id);
211     la11Id = vendorLicenseManager.createLicenseAgreement(la1, USER1).getId();
212
213     List<String> fgs = new ArrayList<>();
214     fgs.add(fg11Id);
215     createTwoFinalVersionsForVLM(vlm1Id);
216     VersionInfo versionInfo =
217         vendorLicenseFacade.getVersionInfo(vlm1Id, VersionableEntityAction.Read, "");
218     vspDetails =
219         createVspDetails(null, null, "VSP1_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
220             vlm1Id, "icon", "category", "subCategory", la11Id, fgs, ArtifactTestUtils
221                 .OnboardingMethod.HEAT.name());
222
223     List<Version> finalVersions = versionInfo.getFinalVersions();
224     Version finalVersion = finalVersions.get(1);
225
226     vspDetails.setVlmVersion(finalVersion);
227
228     vspDetails = vendorSoftwareProductManager.createVsp(vspDetails, USER1);
229
230   }
231
232   private void createTwoFinalVersionsForVLM(String vlm1Id) {
233     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
234     versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
235     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
236     vendorLicenseFacade.submit(vlm1Id, USER1);
237     versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
238     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc2");
239     vendorLicenseFacade.submit(vlm1Id, USER1);
240
241   }
242
243   protected VspDetails createVspWithSpecifiedVlmVersion(String vlmToUse, Version vlmVersionToUse,
244                                                         List<String> fgs, String
245                                                             licenceAgreementId) {
246     vspDetailsVsp3 =
247         createVspDetails(null, null, "VSP3_" + CommonMethods.nextUuId(), "VSP3",
248             "vendorName",
249             vlm3Id, "icon", "category", "subCategory", licenceAgreementId, fgs, OnboardingMethod
250                 .HEAT.name());
251     VersionInfo versionInfo =
252         vendorLicenseFacade.getVersionInfo(vlmToUse, VersionableEntityAction.Read, "");
253
254
255     vspDetailsVsp3.setVlmVersion(vlmVersionToUse);
256
257     return vendorSoftwareProductManager.createVsp(vspDetailsVsp3, USER1);
258   }
259
260   protected void createAndSetupVlm3() {
261     vlm3Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
262             .createVendorLicenseModel("vlm3 name" + CommonMethods.nextUuId(), "vlm3Id desc",
263                 "icon2"),
264         USER1).getId();
265     ep3_1 = EntitlementPoolTest
266         .createEntitlementPool(vlm3Id, VERSION01, "EP3_" + CommonMethods.nextUuId(), "EP3 dec",
267             80,
268             ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
269             "agg func1", opScopeChoices, null, EntitlementTime.Quarter, null, "sku1");
270     ep3_1Id = vendorLicenseManager.createEntitlementPool(ep3_1, USER1).getId();
271     lkg3_1 = LicenseKeyGroupTest
272         .createLicenseKeyGroup(vlm3Id, VERSION01, "LKG3_" + CommonMethods.nextUuId(), "LKG3 dec",
273             LicenseKeyType.Unique,
274             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
275     lkg3_1Id = vendorLicenseManager.createLicenseKeyGroup(lkg3_1, USER1).getId();
276     lkg3_1.setId(lkg3_1Id);
277
278     FeatureGroupEntity fg3 = LicenseAgreementTest.createFeatureGroup(vlm3Id, VERSION01,
279         "fg3" + CommonMethods.nextUuId(),
280         "FG3", "FG3 " +
281             "desc",
282         CommonMethods.toSingleElementSet(ep3_1Id), CommonMethods.toSingleElementSet(lkg3_1Id));
283     String fg3Id = vendorLicenseManager.createFeatureGroup(fg3, USER1).getId();
284     String requirementsAndConstrains1 = "Requirements And Constraints1";
285     licenseAgreementVlm3 = LicenseAgreementTest
286         .createLicenseAgreement(vlm3Id, VERSION01, null, "LA3", "LA1 desc",
287             requirementsAndConstrains1, new ChoiceOrOther<>(
288                 LicenseTerm.Unlimited, null), fg3Id);
289     String la3_1Id =
290         vendorLicenseManager.createLicenseAgreement(licenseAgreementVlm3, USER1).getId();
291
292     featureGroupsforVlm3 = new ArrayList<>();
293     featureGroupsforVlm3.add(fg3Id);
294
295   }
296
297   protected void addEpToVLM(String vlmToAddEP) {
298     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
299     versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
300     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
301     vendorLicenseFacade.submit(vlmToAddEP, USER1);
302
303
304     versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1);
305
306     EntitlementPoolEntity addedEp = EntitlementPoolTest
307         .createEntitlementPool(vlmToAddEP, VERSION01, "EP_ADDED" + CommonMethods.nextUuId(),
308             "EP_ADDED" +
309                 " desc" + CommonMethods.nextUuId(), 99,
310             ThresholdUnit
311                 .Absolute,
312             EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
313             opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
314     String addedEpId = vendorLicenseManager.createEntitlementPool(addedEp, USER1).getId();
315     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlmToAddEP, USER1, "desc1");
316     vendorLicenseFacade.submit(vlmToAddEP, USER1);
317     VersionInfo versionInfo =
318         vendorLicenseFacade.getVersionInfo(vlm3Id, VersionableEntityAction.Read, "");
319   }
320
321   protected void createThirdFinalVersionForVLMChangeEpLKGInSome(String vlm1Id,
322                                                                 EntitlementPoolEntity ep,
323                                                                 LicenseKeyGroupEntity lkg) {
324     versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
325     vendorLicenseManager.updateEntitlementPool(ep, USER1);
326     vendorLicenseManager.updateLicenseKeyGroup(lkg, USER1);
327     versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
328     vendorLicenseFacade.submit(vlm1Id, USER1);
329
330   }
331
332   protected void setVlm2FirstVersion() {
333
334
335     ep21 = EntitlementPoolTest
336         .createEntitlementPool(vlm2Id, VERSION01, "EP21", "EP21 dec", 80, ThresholdUnit.Absolute,
337             EntitlementMetric.Core, null, "inc21", AggregationFunction.Other, "agg func21",
338             opScopeChoices, null, EntitlementTime.Hour, null, "sku21");
339     ep21Id = vendorLicenseManager.createEntitlementPool(ep21, USER1).getId();
340
341     lkg21 = LicenseKeyGroupTest
342         .createLicenseKeyGroup(vlm2Id, VERSION01, "LKG21", "LKG21 dec", LicenseKeyType.One_Time,
343             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
344     lkg21Id = vendorLicenseManager.createLicenseKeyGroup(lkg21, USER1).getId();
345     lkg21.setId(lkg21Id);
346
347     fg21 = LicenseAgreementTest.createFeatureGroup(vlm2Id, VERSION01, "fg21", "FG21", "FG21 desc",
348         CommonMethods.toSingleElementSet(ep21Id), CommonMethods.toSingleElementSet(lkg21Id));
349     fg21Id = vendorLicenseManager.createFeatureGroup(fg21, USER1).getId();
350
351     String requirementsAndConstrains1 = "Requirements And Constraints21";
352     LicenseAgreementEntity la2 = LicenseAgreementTest
353         .createLicenseAgreement(vlm2Id, VERSION01, null, "LA21", "LA21 desc",
354             requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg21Id);
355     la21Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
356
357 //        setValuesForVlm(VERSION01, ep21, ep21Id, lkg21, lkg21Id, fg21, fg21Id, la21Id, 1);
358
359     vendorLicenseManager.checkin(vlm2Id, USER1);
360     currVersion =
361         versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
362
363     List<String> fgs = new ArrayList<>();
364     fgs.add(fg21Id);
365     vsp2 =
366         createVspDetails(null, null, "VSP2_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName",
367             vlm2Id, "icon", "category", "subCategory", la21Id, fgs, OnboardingMethod.HEAT.name());
368     vsp2 = vendorSoftwareProductManager.createVsp(vsp2, USER1);
369   }
370
371   protected void setVlm2SecondVersion() {
372     vendorLicenseManager.checkout(vlm2Id, USER1);
373
374     Set<OperationalScope> opScopeChoices = new HashSet<>();
375     opScopeChoices.add(OperationalScope.Other);
376     opScopeChoices.add(OperationalScope.Data_Center);
377     opScopeChoices.add(OperationalScope.Network_Wide);
378
379     Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
380     opScopeChoicesLKG.add(OperationalScope.CPU);
381     opScopeChoicesLKG.add(OperationalScope.VM);
382     opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
383     opScopeChoicesLKG.add(OperationalScope.Data_Center);
384
385     ep22 = EntitlementPoolTest
386         .createEntitlementPool(vlm2Id, currVersion, "EP22", "EP22 dec", 80, ThresholdUnit.Absolute,
387             EntitlementMetric.Core, null, "inc22", AggregationFunction.Other, "agg func22",
388             opScopeChoices, null, EntitlementTime.Hour, null, "sku22");
389     ep22Id = vendorLicenseManager.createEntitlementPool(ep22, USER1).getId();
390
391     lkg22 = LicenseKeyGroupTest
392         .createLicenseKeyGroup(vlm2Id, currVersion, "LKG22", "LKG22 dec", LicenseKeyType.One_Time,
393             new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
394     lkg22Id = vendorLicenseManager.createLicenseKeyGroup(lkg22, USER1).getId();
395     lkg22.setId(lkg22Id);
396
397     fg22 = LicenseAgreementTest.createFeatureGroup(vlm2Id, currVersion, "fg22", "FG22", "FG22 desc",
398         CommonMethods.toSingleElementSet(ep22Id), CommonMethods.toSingleElementSet(lkg22Id));
399     fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId();
400
401     String requirementsAndConstrains1 = "Requirements And Constraints22";
402     LicenseAgreementEntity la2 = LicenseAgreementTest
403         .createLicenseAgreement(vlm2Id, currVersion, null, "LA22", "LA22 desc",
404             requirementsAndConstrains1, new ChoiceOrOther<>(LicenseTerm.Unlimited, null), fg22Id);
405     la22Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
406
407 //        setValuesForVlm(currVersion, ep22, ep22Id, lkg22, lkg22Id, fg22, fg22Id, la22Id, 2);
408
409     vendorLicenseManager.checkin(vlm2Id, USER1);
410     currVersion =
411         versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
412   }
413
414
415 */
416 }