Upgrade testing frameworks to latest not-vulnerable versions
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / impl / LicenseKeyGroupTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 package org.openecomp.sdc.vendorlicense.impl;
19
20 import org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.mockito.Spy;
28 import org.openecomp.sdc.common.errors.CoreException;
29 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
30 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
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.MultiChoiceOrOther;
34 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
35 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
36 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
37 import org.openecomp.sdc.versioning.dao.types.Version;
38 import java.time.LocalDate;
39 import java.time.format.DateTimeFormatter;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.HashSet;
43 import java.util.Set;
44
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.Mockito.*;
47
48 public class LicenseKeyGroupTest {
49
50   //JUnit Test Cases using Mockito
51   private final String USER = "lkgTestUser";
52   private final String LKG_NAME = "LKG name";
53   private final String LKG2_NAME = "LKG2 name";
54   private final String LT_NAME = "LT name";
55   private final String LKG1_NAME = "LKG1 name";
56   private final String USER1 = "user1";
57   private static String lkg1_id = "lkg1_id";
58   private static String lkg2_id = "lkg2_id";
59   private static String vlm1_id = "vlm1_id";
60   public static final Version VERSION01 = new Version(0, 1);
61
62
63   @Mock
64   private VendorLicenseFacade vendorLicenseFacade;
65
66   @Mock
67   private LicenseKeyGroupDao licenseKeyGroupDao;
68   @Mock
69   private LimitDao limitDao;
70
71   @InjectMocks
72   @Spy
73   private VendorLicenseManagerImpl vendorLicenseManagerImpl;
74
75   @Before
76   public void setUp() throws Exception {
77     MockitoAnnotations.openMocks(this);
78   }
79
80   @After
81   public void tearDown(){
82     vendorLicenseManagerImpl = null;
83   }
84
85   private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type,
86                                                       Set<OperationalScope> operationalScopeChoices,
87                                                       String operationalScopeOther) {
88     LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
89     licenseKeyGroupEntity.setType(type);
90     licenseKeyGroupEntity.setOperationalScope(
91         new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
92     return licenseKeyGroupEntity;
93   }
94
95   /*
96       @Test
97       public void deleteLicenseKeyGroupTest() {
98           Set<OperationalScope> opScopeChoices;
99           opScopeChoices = new HashSet<>();
100           opScopeChoices.add(OperationalScope.Core);
101           opScopeChoices.add(OperationalScope.CPU);
102           opScopeChoices.add(OperationalScope.Network_Wide);
103
104           LicenseKeyGroupEntity licenseKeyGroup =
105                   createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
106
107           VersionInfo info = new VersionInfo();
108           Version version = new Version();
109           info.getViewableVersions().add(version);
110           info.setActiveVersion(version);
111           doReturn(info).when(vendorLicenseFacade).getVersionInfo(any(),any(),any());
112
113           LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
114                   "Core",AggregationFunction.Average,10,"Hour");
115
116           ArrayList<LimitEntity> limitEntityList = new ArrayList();
117           limitEntityList.add(limitEntity);
118
119           doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(any());
120           doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(any(), any(), any(), any());
121           doReturn(true).when(limitDao).isLimitPresent(any());
122           doReturn(limitEntity).when(limitDao).get(any());
123           try {
124               Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
125               limitField.setAccessible(true);
126               Field modifiersField = Field.class.getDeclaredField("modifiers");
127               modifiersField.setAccessible(true);
128               modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
129               limitField.set(null, limitDao);
130
131               Field lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao");
132               lkgField.setAccessible(true);
133               modifiersField = Field.class.getDeclaredField("modifiers");
134               modifiersField.setAccessible(true);
135               modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL);
136               lkgField.set(null, licenseKeyGroupDao);
137           } catch(NoSuchFieldException | IllegalAccessException e)
138           {
139               Assert.fail();
140           }
141
142           vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
143
144           verify(limitDao).delete(any());
145       }
146
147       @Test
148       public void deleteLicenseKeyGroupInvalidTest() {
149           try {
150               Set<OperationalScope> opScopeChoices;
151               opScopeChoices = new HashSet<>();
152               opScopeChoices.add(OperationalScope.Core);
153               opScopeChoices.add(OperationalScope.CPU);
154               opScopeChoices.add(OperationalScope.Network_Wide);
155
156               LicenseKeyGroupEntity licenseKeyGroup =
157                   createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
158
159               VersionInfo info = new VersionInfo();
160               Version version = new Version();
161               info.getViewableVersions().add(version);
162               info.setActiveVersion(version);
163               doReturn(info).when(vendorLicenseFacade).getVersionInfo(any(),any(),any());
164
165               LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
166                   "Core",AggregationFunction.Average,10,"Hour");
167
168               ArrayList<LimitEntity> limitEntityList = new ArrayList();
169               limitEntityList.add(limitEntity);
170
171               doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(any());
172               doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(any(), any(), any(), any());
173               doReturn(false).when(limitDao).isLimitPresent(any());
174
175               try {
176                   Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
177                   limitField.setAccessible(true);
178                   Field modifiersField = Field.class.getDeclaredField("modifiers");
179                   modifiersField.setAccessible(true);
180                   modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
181                   limitField.set(null, limitDao);
182
183                   Field lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao");
184                   lkgField.setAccessible(true);
185                   modifiersField = Field.class.getDeclaredField("modifiers");
186                   modifiersField.setAccessible(true);
187                   modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL);
188                   lkgField.set(null, licenseKeyGroupDao);
189               } catch(NoSuchFieldException | IllegalAccessException e)
190               {
191                   Assert.fail();
192               }
193
194               vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
195           } catch (CoreException exception) {
196               Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
197           }
198       }
199   */
200   @Test
201   public void createTest() {
202     Set<OperationalScope> opScopeChoices;
203     opScopeChoices = new HashSet<>();
204     opScopeChoices.add(OperationalScope.Core);
205     opScopeChoices.add(OperationalScope.CPU);
206     opScopeChoices.add(OperationalScope.Network_Wide);
207     LicenseKeyGroupEntity lkg =
208         createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec", LicenseKeyType.Unique,
209             new MultiChoiceOrOther<>(opScopeChoices, null));
210     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
211     lkg.setStartDate(LocalDate.now().format(formatter));
212     lkg.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
213
214     vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
215     verify(vendorLicenseFacade).createLicenseKeyGroup(lkg);
216   }
217
218   @Test
219   public void createWithInvalidStartExpiryDateTest() {
220     try {
221
222       Set<OperationalScope> opScopeChoices;
223       opScopeChoices = new HashSet<>();
224       opScopeChoices.add(OperationalScope.Core);
225       opScopeChoices.add(OperationalScope.CPU);
226       opScopeChoices.add(OperationalScope.Network_Wide);
227       LicenseKeyGroupEntity lkg =
228           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
229               LicenseKeyType.Unique,
230               new MultiChoiceOrOther<>(opScopeChoices, null));
231       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
232       lkg.setStartDate(LocalDate.now().format(formatter));
233       lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
234       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
235       Assert.fail();
236     } catch (CoreException exception) {
237       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
238     }
239   }
240
241   @Test
242   public void createWithoutStartDateTest() {
243     try {
244
245       Set<OperationalScope> opScopeChoices;
246       opScopeChoices = new HashSet<>();
247       opScopeChoices.add(OperationalScope.Core);
248       opScopeChoices.add(OperationalScope.CPU);
249       opScopeChoices.add(OperationalScope.Network_Wide);
250       LicenseKeyGroupEntity lkg =
251           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
252               LicenseKeyType.Unique,
253               new MultiChoiceOrOther<>(opScopeChoices, null));
254       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
255       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
256       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg).getId();
257       Assert.fail();
258     } catch (CoreException exception) {
259       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
260     }
261   }
262
263   @Test
264   public void createWithSameStartExpiryDateTest() {
265     try {
266
267       Set<OperationalScope> opScopeChoices;
268       opScopeChoices = new HashSet<>();
269       opScopeChoices.add(OperationalScope.Core);
270       opScopeChoices.add(OperationalScope.CPU);
271       opScopeChoices.add(OperationalScope.Network_Wide);
272       LicenseKeyGroupEntity lkg =
273           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
274               LicenseKeyType.Unique,
275               new MultiChoiceOrOther<>(opScopeChoices, null));
276       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
277       lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
278       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
279       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg).getId();
280       Assert.fail();
281     } catch (CoreException exception) {
282       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
283     }
284   }
285
286   @Test
287   public void testUpdate() {
288     Set<OperationalScope> opScopeChoices;
289     opScopeChoices = new HashSet<>();
290     opScopeChoices.add(OperationalScope.Core);
291     opScopeChoices.add(OperationalScope.CPU);
292     opScopeChoices.add(OperationalScope.Network_Wide);
293     LicenseKeyGroupEntity lkg =
294         createLicenseKeyGroup(vlm1_id, null, lkg1_id, LKG1_NAME, "LKG1 dec", LicenseKeyType.Unique,
295             new MultiChoiceOrOther<>(opScopeChoices, null));
296     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
297     lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
298     lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
299
300     vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
301     verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg);
302   }
303
304   @Test
305   public void updateWithInvalidStartExpiryDateTest() {
306     try {
307
308       Set<OperationalScope> opScopeChoices;
309       opScopeChoices = new HashSet<>();
310       opScopeChoices.add(OperationalScope.Core);
311       opScopeChoices.add(OperationalScope.CPU);
312       opScopeChoices.add(OperationalScope.Network_Wide);
313       LicenseKeyGroupEntity lkg =
314           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
315               LicenseKeyType.Unique,
316               new MultiChoiceOrOther<>(opScopeChoices, null));
317       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
318       lkg.setStartDate(LocalDate.now().format(formatter));
319       lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
320       vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
321       Assert.fail();
322     } catch (CoreException exception) {
323       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
324     }
325   }
326
327   @Test
328   public void updateWithoutStartDateTest() {
329     try {
330
331       Set<OperationalScope> opScopeChoices;
332       opScopeChoices = new HashSet<>();
333       opScopeChoices.add(OperationalScope.Core);
334       opScopeChoices.add(OperationalScope.CPU);
335       opScopeChoices.add(OperationalScope.Network_Wide);
336       LicenseKeyGroupEntity lkg =
337           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
338               LicenseKeyType.Unique,
339               new MultiChoiceOrOther<>(opScopeChoices, null));
340       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
341       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
342       vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
343       Assert.fail();
344     } catch (CoreException exception) {
345       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
346     }
347   }
348
349   @Test
350   public void updateWithSameStartExpiryDateTest() {
351     try {
352
353       Set<OperationalScope> opScopeChoices;
354       opScopeChoices = new HashSet<>();
355       opScopeChoices.add(OperationalScope.Core);
356       opScopeChoices.add(OperationalScope.CPU);
357       opScopeChoices.add(OperationalScope.Network_Wide);
358       LicenseKeyGroupEntity lkg =
359           createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
360               LicenseKeyType.Unique,
361               new MultiChoiceOrOther<>(opScopeChoices, null));
362       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
363       lkg.setStartDate(LocalDate.now().format(formatter));
364       lkg.setExpiryDate(LocalDate.now().format(formatter));
365       vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
366       Assert.fail();
367     } catch (CoreException exception) {
368       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
369     }
370   }
371
372   @Test
373   public void testListlistLicenseKeyGroups() {
374
375     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
376         new MultiChoiceOrOther<OperationalScope>();
377     Set<OperationalScope> opScopeChoices = new HashSet<>();
378     opScopeChoices.add(OperationalScope.Core);
379     opScopeChoices.add(OperationalScope.CPU);
380     opScopeChoices.add(OperationalScope.Network_Wide);
381     multiChoiceOrOther.setChoices(opScopeChoices);
382     multiChoiceOrOther.setOther("Other");
383
384     doReturn(Arrays.asList(
385         createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME, "LKG1 dec",
386             LicenseKeyType.Universal,
387             multiChoiceOrOther),
388         createLicenseKeyGroup(vlm1_id, VERSION01, lkg2_id, LKG2_NAME, "LKG2 dec", LicenseKeyType
389             .Universal, multiChoiceOrOther)))
390         .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
391
392     Collection<LicenseKeyGroupEntity> LKGs =
393         vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01);
394
395     verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
396     Assert.assertEquals(LKGs.size(), 2);
397     LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
398   }
399
400   @Test
401   public void testGetLicenseKeyGroup() {
402     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
403         new MultiChoiceOrOther<OperationalScope>();
404     Set<OperationalScope> opScopeChoices = new HashSet<>();
405     opScopeChoices.add(OperationalScope.Core);
406     opScopeChoices.add(OperationalScope.CPU);
407     opScopeChoices.add(OperationalScope.Network_Wide);
408     multiChoiceOrOther.setChoices(opScopeChoices);
409     multiChoiceOrOther.setOther("Other");
410
411     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
412         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
413
414     doReturn(lkg).when(licenseKeyGroupDao).get(any());
415
416     LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg);
417     verify(licenseKeyGroupDao).get(lkg);
418
419     Assert.assertEquals(lkgRetrived.getId(), lkg.getId());
420     Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(), lkg.getVendorLicenseModelId());
421     Assert.assertEquals(lkgRetrived.getVersion(), lkg.getVersion());
422
423   }
424
425   @Test
426   public void testDeleteLicenseKeyGroup() {
427     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
428         new MultiChoiceOrOther<OperationalScope>();
429     Set<OperationalScope> opScopeChoices = new HashSet<>();
430     opScopeChoices.add(OperationalScope.Core);
431     opScopeChoices.add(OperationalScope.CPU);
432     opScopeChoices.add(OperationalScope.Network_Wide);
433     multiChoiceOrOther.setChoices(opScopeChoices);
434     multiChoiceOrOther.setOther("Other");
435
436     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
437         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
438
439     lkg.setReferencingFeatureGroups(new HashSet<>());
440
441     doReturn(lkg).when(licenseKeyGroupDao).get(any());
442
443     doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id, VERSION01, lkg1_id);
444
445     doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(any(), any(),
446         any(), any());
447
448     vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg);
449
450     verify(licenseKeyGroupDao).delete(lkg);
451
452   }
453
454   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
455                                                             String id,
456                                                             String name, String desc,
457                                                             LicenseKeyType type,
458                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
459     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
460     licenseKeyGroup.setVendorLicenseModelId(vlmId);
461     licenseKeyGroup.setVersion(version);
462     licenseKeyGroup.setId(id);
463     licenseKeyGroup.setName(name);
464     licenseKeyGroup.setDescription(desc);
465     licenseKeyGroup.setType(type);
466     licenseKeyGroup.setOperationalScope(operationalScope);
467     return licenseKeyGroup;
468   }
469
470   /*public static final String LKG1_NAME = "LKG1 name";
471   private static final Version VERSION01 = new Version(0, 1);
472   public static final String LKG1_NAME = "LKG1 name";
473   private static final String USER1 = "user1";
474   public static String vlm1Id;
475   public static String vlm2Id;
476   private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
477   private static LicenseKeyGroupDao licenseKeyGroupDao;
478   private static NoSqlDb noSqlDb;
479   private static String lkg1Id;
480   private static String lkg2Id;
481
482   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
483                                                             String name, String desc,
484                                                             LicenseKeyType type,
485                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
486     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
487     licenseKeyGroup.setVendorLicenseModelId(vlmId);
488     licenseKeyGroup.setVersion(version);
489     licenseKeyGroup.setName(name);
490     licenseKeyGroup.setDescription(desc);
491     licenseKeyGroup.setType(type);
492     licenseKeyGroup.setOperationalScope(operationalScope);
493     return licenseKeyGroup;
494   }
495
496   @BeforeMethod
497   public void setUp() throws Exception {
498     MockitoAnnotations.openMocks(this);
499   }
500
501   /*@BeforeClass
502   private void init() {
503     licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
504     noSqlDb = NoSqlDbFactory.getInstance().createInterface();
505
506     vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
507         .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
508             "icon1")1).getId();
509     vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
510             .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
511         USER1).getId();
512   }
513
514   @Test
515   public void createTest() {
516     lkg1Id = testCreate(vlm1Id, LKG1_NAME);
517   }
518
519   private String testCreate(String vlmId, String name) {
520     Set<OperationalScope> opScopeChoices = new HashSet<>();
521     opScopeChoices.add(OperationalScope.CPU);
522     opScopeChoices.add(OperationalScope.VM);
523     opScopeChoices.add(OperationalScope.Tenant);
524     opScopeChoices.add(OperationalScope.Data_Center);
525     LicenseKeyGroupEntity
526         lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
527         new MultiChoiceOrOther<>(opScopeChoices, null));
528     String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
529     lkg1.setId(lkg1Id);
530
531     LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
532     Assert.assertTrue(loadedLkg1.equals(lkg1));
533     return lkg1Id;
534   }
535
536   @Test(dependsOnMethods = {"createTest"})
537   public void testCreateWithExistingName_negative() {
538     try {
539       LicenseKeyGroupEntity lkg1 =
540           createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
541               new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
542                   "other op scope"));
543       vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
544       Assert.fail();
545     } catch (CoreException exception) {
546       Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
547     }
548   }
549
550   @Test(dependsOnMethods = {"createTest"})
551   public void testCreateWithExistingNameUnderOtherVlm() {
552     testCreate(vlm2Id, LKG1_NAME);
553   }
554
555   @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
556   public void updateAndGetTest() {
557     LicenseKeyGroupEntity lkg1 =
558         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
559     Set<OperationalScope> opScopeChoices = new HashSet<>();
560     opScopeChoices.add(OperationalScope.Other);
561     lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
562     lkg1.setDescription("LKG1 dec updated");
563
564     vendorLicenseManager.updateLicenseKeyGroup(lkg11);
565
566     LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg11);
567     Assert.assertTrue(loadedLkg1.equals(lkg1));
568
569   }
570
571   @Test(dependsOnMethods = {"updateAndGetTest"})
572   public void listTest() {
573     Set<OperationalScope> opScopeChoices = new HashSet<>();
574     opScopeChoices.add(OperationalScope.Network_Wide);
575     LicenseKeyGroupEntity lkg2 =
576         createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
577             new MultiChoiceOrOther<>(opScopeChoices, null));
578     lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg21).getId();
579     lkg2.setId(lkg2Id);
580
581     Collection<LicenseKeyGroupEntity> loadedLkgs =
582         vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null1);
583     Assert.assertEquals(loadedLkgs.size(), 2);
584     for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
585       if (lkg2Id.equals(loadedLkg.getId())) {
586         Assert.assertTrue(loadedLkg.equals(lkg2));
587       }
588     }
589   }
590
591   @Test(dependsOnMethods = {"listTest"})
592   public void deleteTest() {
593     vendorLicenseManager
594         .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)1);
595
596     LicenseKeyGroupEntity loadedLkg1 =
597         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
598     Assert.assertEquals(loadedLkg1, null);
599
600     Collection<LicenseKeyGroupEntity> loadedLkgs =
601         licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
602     Assert.assertEquals(loadedLkgs.size(), 1);
603     Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
604   }
605
606   @Test(dependsOnMethods = "deleteTest")
607   public void testCreateWithRemovedName() {
608     testCreate(vlm1Id, LKG1_NAME);
609   }
610   */
611 }