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