push addional code
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / ArtifactTestUtils.java
1 package org.openecomp.sdc.vendorlicense;
2
3 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
4 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
5 import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl;
6 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
7 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
9 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
10 import org.openecomp.sdc.versioning.VersioningManager;
11 import org.openecomp.sdc.versioning.dao.types.Version;
12 import org.openecomp.sdc.versioning.types.VersionInfo;
13 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
14 import org.openecomp.core.utilities.CommonMethods;
15 import org.testng.annotations.BeforeMethod;
16
17 import java.util.ArrayList;
18 import java.util.HashSet;
19 import java.util.List;
20 import java.util.Set;
21
22 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE;
23
24 public class ArtifactTestUtils {
25
26     protected static final Version VERSION01 = new Version(0, 1);
27     protected static final String USER1 = "baseTest_TestUser1";
28     protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
29     protected static VendorSoftwareProductManager vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl();
30     protected static VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance().createInterface();
31     private static final VersioningManager versioningManager = org.openecomp.sdc.versioning.VersioningManagerFactory
32         .getInstance().createInterface();
33     protected static VendorLicenseArtifactsService vendorLicenseArtifactsService = VendorLicenseArtifactServiceFactory
34         .getInstance().createInterface();
35
36     protected static Version currVersion;
37
38     protected String vlm1Id;
39     protected String vlm2Id;
40
41     protected String ep11Id;
42     protected String ep12Id;
43     protected String lkg11Id;
44     protected String lkg12Id;
45     protected String lkg13Id;
46     protected String fg11Id;
47     protected String fg12Id;
48     protected String la11Id;
49
50     protected String ep21Id;
51     protected String ep22Id;
52     protected String lkg21Id;
53     protected String lkg22Id;
54     protected String fg21Id;
55     protected String fg22Id;
56     protected String la21Id;
57     protected String la22Id;
58
59     protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg11;
60     protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg12;
61     protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep11;
62     protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep12;
63     protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg11;
64     protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg12;
65     protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg13;
66
67     protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg21;
68     protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg22;
69     protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep21;
70     protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep22;
71     protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg21;
72     protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg22;
73
74     protected VspDetails vspDetails;
75     protected VspDetails vsp2;
76
77
78     @BeforeMethod
79     public void setUp() {
80         vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest.createVendorLicenseModel("vlm1 name" + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), USER1).getId();
81         vlm2Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest.createVendorLicenseModel("vlm2 name" + CommonMethods.nextUuId(), "vlm2Id desc", "icon2"), USER1).getId();
82
83
84         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>();
85         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other);
86         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
87         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide);
88
89         ep11 = EntitlementPoolTest.createEntitlementPool(vlm1Id, VERSION01, "EP1_" + CommonMethods.nextUuId(), "EP1 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc1", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func1", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku1");
90         ep11Id = vendorLicenseManager.createEntitlementPool(ep11, USER1).getId();
91         ep12 = EntitlementPoolTest.createEntitlementPool(vlm1Id, VERSION01, "EP2_" + CommonMethods.nextUuId(), "EP2 dec", 70, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Other, "e metric2", "inc2", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Average, null, opScopeChoices, "op scope2", org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Other, "time2", "sku2");
92         ep12Id = vendorLicenseManager.createEntitlementPool(ep12, USER1).getId();
93
94         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>();
95         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU);
96         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM);
97         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone);
98         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
99
100         lkg11 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG1", "LKG1 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null));
101         lkg11Id = vendorLicenseManager.createLicenseKeyGroup(lkg11, USER1).getId();
102         lkg11.setId(lkg11Id);
103
104         lkg12 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Unique, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null));
105         lkg12Id = vendorLicenseManager.createLicenseKeyGroup(lkg12, USER1).getId();
106         lkg12.setId(lkg11Id);
107
108         lkg13 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG3", "LKG3 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Universal, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null));
109         lkg13Id = vendorLicenseManager.createLicenseKeyGroup(lkg13, USER1).getId();
110         lkg13.setId(lkg13Id);
111
112         fg11 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", CommonMethods.toSingleElementSet(ep11Id), CommonMethods.toSingleElementSet(lkg11Id));
113         fg11Id = vendorLicenseManager.createFeatureGroup(fg11, USER1).getId();
114
115         fg12 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc", CommonMethods.toSingleElementSet(ep12Id), CommonMethods.toSingleElementSet(lkg12Id));
116         fg12Id = vendorLicenseManager.createFeatureGroup(fg12, USER1).getId();
117
118
119         String requirementsAndConstrains1 = "Requirements And Constraints1";
120         org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
121             la1 = LicenseAgreementTest.createLicenseAgreement(vlm1Id, VERSION01, null, "LA1", "LA1 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
122             org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg11Id);
123         la11Id = vendorLicenseManager.createLicenseAgreement(la1, USER1).getId();
124
125         List<String> fgs = new ArrayList<>();
126         fgs.add(fg11Id);
127         createTwoFinalVersionsForVLM(vlm1Id);
128         VersionInfo versionInfo = vendorLicenseFacade.getVersionInfo(vlm1Id, VersionableEntityAction.Read, "");
129         vspDetails = createVspDetails(null, null, "VSP1_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName", vlm1Id, "icon", "category", "subCategory", la11Id, fgs);
130
131         List<Version> finalVersions = versionInfo.getFinalVersions();
132         Version finalVersion = finalVersions.get(1);
133
134         vspDetails.setVlmVersion(finalVersion);
135
136         vspDetails = vendorSoftwareProductManager.createNewVsp(vspDetails, USER1);
137
138     }
139
140     private void createTwoFinalVersionsForVLM(String vlm1Id) {
141         versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
142         versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
143         versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
144         vendorLicenseFacade.submit(vlm1Id, USER1);
145         versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
146         versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc2");
147         vendorLicenseFacade.submit(vlm1Id, USER1);
148
149     }
150
151     protected void createThirdFinalVersionForVLMChangeEpLKGInSome(String vlm1Id, org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep, org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg) {
152         versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1);
153         vendorLicenseManager.updateEntitlementPool(ep, USER1);
154         vendorLicenseManager.updateLicenseKeyGroup(lkg, USER1);
155         versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1");
156         vendorLicenseFacade.submit(vlm1Id, USER1);
157
158     }
159
160
161     protected void setVlm2FirstVersion() {
162         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>();
163         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other);
164         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
165         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide);
166
167         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>();
168         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU);
169         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM);
170         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone);
171         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
172
173         ep21 = EntitlementPoolTest.createEntitlementPool(vlm2Id, VERSION01, "EP21", "EP21 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc21", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func21", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku21");
174         ep21Id = vendorLicenseManager.createEntitlementPool(ep21, USER1).getId();
175
176         lkg21 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm2Id, VERSION01, "LKG21", "LKG21 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null));
177         lkg21Id = vendorLicenseManager.createLicenseKeyGroup(lkg21, USER1).getId();
178         lkg21.setId(lkg21Id);
179
180         fg21 = LicenseAgreementTest.createFeatureGroup(vlm2Id, VERSION01, "fg21", "FG21", "FG21 desc", CommonMethods.toSingleElementSet(ep21Id), CommonMethods.toSingleElementSet(lkg21Id));
181         fg21Id = vendorLicenseManager.createFeatureGroup(fg21, USER1).getId();
182
183         String requirementsAndConstrains1 = "Requirements And Constraints21";
184         org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
185             la2 = LicenseAgreementTest.createLicenseAgreement(vlm2Id, VERSION01, null, "LA21", "LA21 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
186             org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg21Id);
187         la21Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
188
189 //        setValuesForVlm(VERSION01, ep21, ep21Id, lkg21, lkg21Id, fg21, fg21Id, la21Id, 1);
190
191         vendorLicenseManager.checkin(vlm2Id, USER1);
192         currVersion = versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
193
194         List<String> fgs = new ArrayList<>();
195         fgs.add(fg21Id);
196         vsp2 = createVspDetails(null, null, "VSP2_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName", vlm2Id, "icon", "category", "subCategory", la21Id, fgs);
197         vsp2 = vendorSoftwareProductManager.createNewVsp(vsp2, USER1);
198     }
199
200     protected void setVlm2SecondVersion() {
201         vendorLicenseManager.checkout(vlm2Id, USER1);
202
203         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>();
204         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other);
205         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
206         opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide);
207
208         Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>();
209         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU);
210         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM);
211         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone);
212         opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center);
213
214         ep22 = EntitlementPoolTest.createEntitlementPool(vlm2Id, currVersion, "EP22", "EP22 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc22", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func22", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku22");
215         ep22Id = vendorLicenseManager.createEntitlementPool(ep22, USER1).getId();
216
217         lkg22 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm2Id, currVersion, "LKG22", "LKG22 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null));
218         lkg22Id = vendorLicenseManager.createLicenseKeyGroup(lkg22, USER1).getId();
219         lkg22.setId(lkg22Id);
220
221         fg22 = LicenseAgreementTest.createFeatureGroup(vlm2Id, currVersion, "fg22", "FG22", "FG22 desc", CommonMethods.toSingleElementSet(ep22Id), CommonMethods.toSingleElementSet(lkg22Id));
222         fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId();
223
224         String requirementsAndConstrains1 = "Requirements And Constraints22";
225         org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
226             la2 = LicenseAgreementTest.createLicenseAgreement(vlm2Id, currVersion, null, "LA22", "LA22 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
227             org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg22Id);
228         la22Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId();
229
230 //        setValuesForVlm(currVersion, ep22, ep22Id, lkg22, lkg22Id, fg22, fg22Id, la22Id, 2);
231
232         vendorLicenseManager.checkin(vlm2Id, USER1);
233         currVersion = versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null);
234     }
235
236     protected static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, String licenseAgreement, List<String> featureGroups) {
237         VspDetails vspDetails = new VspDetails(id, version);
238         vspDetails.setName(name);
239         vspDetails.setDescription(desc);
240         vspDetails.setIcon(icon);
241         vspDetails.setCategory(category);
242         vspDetails.setSubCategory(subCategory);
243         vspDetails.setVendorName(vendorName);
244         vspDetails.setVendorId(vlm);
245         vspDetails.setLicenseAgreement(licenseAgreement);
246         vspDetails.setFeatureGroups(featureGroups);
247         return vspDetails;
248     }
249
250
251 }
252