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