acd1ce8cce1fee1fe03adeabbc3cd37ed0998891
[sdc.git] /
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.*;
32 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
33 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
34 import org.openecomp.sdc.versioning.dao.types.Version;
35 import org.openecomp.sdc.versioning.types.VersionInfo;
36 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
37 import org.testng.Assert;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
40
41 import java.util.ArrayList;
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, Set<OperationalScope> operationalScopeChoices,
87                                                       String operationalScopeOther)
88   {
89     LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
90     licenseKeyGroupEntity.setType(type);
91     licenseKeyGroupEntity.setOperationalScope(
92         new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
93     return licenseKeyGroupEntity;
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(anyObject(),anyObject(),anyObject());
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(anyObject());
120           doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
121           doReturn(true).when(limitDao).isLimitPresent(anyObject());
122           doReturn(limitEntity).when(limitDao).get(anyObject());
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(anyObject());
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(anyObject(),anyObject(),anyObject());
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(anyObject());
172               doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
173               doReturn(false).when(limitDao).isLimitPresent(anyObject());
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, USER1);
215     verify(vendorLicenseFacade).createLicenseKeyGroup(lkg,USER1);
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",LicenseKeyType.Unique,
229               new MultiChoiceOrOther<>(opScopeChoices, null));
230       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
231       lkg.setStartDate(LocalDate.now().format(formatter));
232       lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
233       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1);
234       Assert.fail();
235     } catch (CoreException exception) {
236       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
237     }
238   }
239
240   @Test
241   public void createWithoutStartDateTest() {
242     try {
243
244       Set<OperationalScope> opScopeChoices;
245       opScopeChoices = new HashSet<>();
246       opScopeChoices.add(OperationalScope.Core);
247       opScopeChoices.add(OperationalScope.CPU);
248       opScopeChoices.add(OperationalScope.Network_Wide);
249       LicenseKeyGroupEntity lkg =
250           createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
251               new MultiChoiceOrOther<>(opScopeChoices, null));
252       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
253       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
254       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
255       Assert.fail();
256     } catch (CoreException exception) {
257       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
258     }
259   }
260
261   @Test
262   public void createWithSameStartExpiryDateTest() {
263     try {
264
265       Set<OperationalScope> opScopeChoices;
266       opScopeChoices = new HashSet<>();
267       opScopeChoices.add(OperationalScope.Core);
268       opScopeChoices.add(OperationalScope.CPU);
269       opScopeChoices.add(OperationalScope.Network_Wide);
270       LicenseKeyGroupEntity lkg =
271           createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
272               new MultiChoiceOrOther<>(opScopeChoices, null));
273       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
274       lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
275       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
276       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
277       Assert.fail();
278     } catch (CoreException exception) {
279       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
280     }
281   }
282
283   @Test
284   public void testUpdate() {
285     Set<OperationalScope> opScopeChoices;
286     opScopeChoices = new HashSet<>();
287     opScopeChoices.add(OperationalScope.Core);
288     opScopeChoices.add(OperationalScope.CPU);
289     opScopeChoices.add(OperationalScope.Network_Wide);
290     LicenseKeyGroupEntity lkg =
291         createLicenseKeyGroup(vlm1_id, null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
292             new MultiChoiceOrOther<>(opScopeChoices, null));
293     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
294     lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
295     lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
296     VersionInfo info = new VersionInfo();
297     info.getViewableVersions().add(VERSION01);
298     info.setActiveVersion(VERSION01);
299     doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
300
301     vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
302     verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg,USER1);
303     verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
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",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, USER1);
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",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, USER1);
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",LicenseKeyType.Unique,
360               new MultiChoiceOrOther<>(opScopeChoices, null));
361       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
362       lkg.setStartDate(LocalDate.now().format(formatter));
363       lkg.setExpiryDate(LocalDate.now().format(formatter));
364       vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
365       Assert.fail();
366     } catch (CoreException exception) {
367       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
368     }
369   }
370
371   @Test
372   public void testListlistLicenseKeyGroups(){
373
374     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
375     Set<OperationalScope> opScopeChoices = new HashSet<>();
376     opScopeChoices.add(OperationalScope.Core);
377     opScopeChoices.add(OperationalScope.CPU);
378     opScopeChoices.add(OperationalScope.Network_Wide);
379     multiChoiceOrOther.setChoices(opScopeChoices);
380     multiChoiceOrOther.setOther("Other");
381
382     doReturn(Arrays.asList(
383         createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,"LKG1 dec", LicenseKeyType.Universal,
384             multiChoiceOrOther),
385         createLicenseKeyGroup(vlm1_id,VERSION01, lkg2_id, LKG2_NAME,"LKG2 dec", LicenseKeyType
386             .Universal, multiChoiceOrOther)))
387         .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
388
389     Collection<LicenseKeyGroupEntity> LKGs =
390         vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
391
392     verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
393     Assert.assertEquals(LKGs.size(), 2);
394     LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
395   }
396
397   @Test
398   public void testGetLicenseKeyGroup(){
399     VersionInfo versionInfo = new VersionInfo();
400     versionInfo.setActiveVersion(VERSION01);
401     versionInfo.setLockingUser(USER1);
402     ArrayList<Version> viewable = new ArrayList<Version>();
403     viewable.add(VERSION01);
404     versionInfo.setViewableVersions(viewable);
405     versionInfo.setActiveVersion(VERSION01);
406
407     doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
408         VersionableEntityAction.Read, USER1);
409
410     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
411     Set<OperationalScope> opScopeChoices = new HashSet<>();
412     opScopeChoices.add(OperationalScope.Core);
413     opScopeChoices.add(OperationalScope.CPU);
414     opScopeChoices.add(OperationalScope.Network_Wide);
415     multiChoiceOrOther.setChoices(opScopeChoices);
416     multiChoiceOrOther.setOther("Other");
417
418     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
419         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
420
421     doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
422
423     LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg,USER1);
424     verify(licenseKeyGroupDao).get(lkg);
425
426     Assert.assertEquals(lkgRetrived.getId(),lkg.getId());
427     Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(),lkg.getVendorLicenseModelId());
428     Assert.assertEquals(lkgRetrived.getVersion(),lkg.getVersion());
429
430   }
431
432   @Test
433   public void testDeleteLicenseKeyGroup() {
434
435     VersionInfo versionInfo = new VersionInfo();
436     versionInfo.setActiveVersion(VERSION01);
437     versionInfo.setLockingUser(USER1);
438     ArrayList<Version> viewable = new ArrayList<Version>();
439     viewable.add(VERSION01);
440     versionInfo.setViewableVersions(viewable);
441
442     doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
443         VersionableEntityAction.Write, USER1);
444
445
446     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
447     Set<OperationalScope> opScopeChoices = new HashSet<>();
448     opScopeChoices.add(OperationalScope.Core);
449     opScopeChoices.add(OperationalScope.CPU);
450     opScopeChoices.add(OperationalScope.Network_Wide);
451     multiChoiceOrOther.setChoices(opScopeChoices);
452     multiChoiceOrOther.setOther("Other");
453
454     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
455         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
456
457     lkg.setReferencingFeatureGroups(new HashSet<>());
458
459     doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
460
461     doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id,VERSION01,lkg1_id,USER1);
462
463     doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(),
464         anyObject(),anyObject());
465
466     vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg, USER1);
467
468     verify(licenseKeyGroupDao).delete(lkg);
469     verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
470
471   }
472
473   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,String id,
474                                                             String name, String desc,
475                                                             LicenseKeyType type,
476                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
477     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
478     licenseKeyGroup.setVendorLicenseModelId(vlmId);
479     licenseKeyGroup.setVersion(version);
480     licenseKeyGroup.setId(id);
481     licenseKeyGroup.setName(name);
482     licenseKeyGroup.setDescription(desc);
483     licenseKeyGroup.setType(type);
484     licenseKeyGroup.setOperationalScope(operationalScope);
485     return licenseKeyGroup;
486   }
487
488   /*public static final String LKG1_NAME = "LKG1 name";
489   private static final Version VERSION01 = new Version(0, 1);
490   public static final String LKG1_NAME = "LKG1 name";
491   private static final String USER1 = "user1";
492   public static String vlm1Id;
493   public static String vlm2Id;
494   private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
495   private static LicenseKeyGroupDao licenseKeyGroupDao;
496   private static NoSqlDb noSqlDb;
497   private static String lkg1Id;
498   private static String lkg2Id;
499
500   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
501                                                             String name, String desc,
502                                                             LicenseKeyType type,
503                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
504     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
505     licenseKeyGroup.setVendorLicenseModelId(vlmId);
506     licenseKeyGroup.setVersion(version);
507     licenseKeyGroup.setName(name);
508     licenseKeyGroup.setDescription(desc);
509     licenseKeyGroup.setType(type);
510     licenseKeyGroup.setOperationalScope(operationalScope);
511     return licenseKeyGroup;
512   }
513
514   @BeforeMethod
515   public void setUp() throws Exception {
516     MockitoAnnotations.initMocks(this);
517   }
518
519   /*@BeforeClass
520   private void init() {
521     licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
522     noSqlDb = NoSqlDbFactory.getInstance().createInterface();
523
524     vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
525         .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
526             "icon1"), USER1).getId();
527     vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
528             .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
529         USER1).getId();
530   }
531
532   @Test
533   public void createTest() {
534     lkg1Id = testCreate(vlm1Id, LKG1_NAME);
535   }
536
537   private String testCreate(String vlmId, String name) {
538     Set<OperationalScope> opScopeChoices = new HashSet<>();
539     opScopeChoices.add(OperationalScope.CPU);
540     opScopeChoices.add(OperationalScope.VM);
541     opScopeChoices.add(OperationalScope.Tenant);
542     opScopeChoices.add(OperationalScope.Data_Center);
543     LicenseKeyGroupEntity
544         lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
545         new MultiChoiceOrOther<>(opScopeChoices, null));
546     String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
547     lkg1.setId(lkg1Id);
548
549     LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
550     Assert.assertTrue(loadedLkg1.equals(lkg1));
551     return lkg1Id;
552   }
553
554   @Test(dependsOnMethods = {"createTest"})
555   public void testCreateWithExistingName_negative() {
556     try {
557       LicenseKeyGroupEntity lkg1 =
558           createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
559               new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
560                   "other op scope"));
561       vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
562       Assert.fail();
563     } catch (CoreException exception) {
564       Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
565     }
566   }
567
568   @Test(dependsOnMethods = {"createTest"})
569   public void testCreateWithExistingNameUnderOtherVlm() {
570     testCreate(vlm2Id, LKG1_NAME);
571   }
572
573   @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
574   public void updateAndGetTest() {
575     LicenseKeyGroupEntity lkg1 =
576         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
577     Set<OperationalScope> opScopeChoices = new HashSet<>();
578     opScopeChoices.add(OperationalScope.Other);
579     lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
580     lkg1.setDescription("LKG1 dec updated");
581
582     vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1);
583
584     LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1);
585     Assert.assertTrue(loadedLkg1.equals(lkg1));
586
587   }
588
589   @Test(dependsOnMethods = {"updateAndGetTest"})
590   public void listTest() {
591     Set<OperationalScope> opScopeChoices = new HashSet<>();
592     opScopeChoices.add(OperationalScope.Network_Wide);
593     LicenseKeyGroupEntity lkg2 =
594         createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
595             new MultiChoiceOrOther<>(opScopeChoices, null));
596     lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId();
597     lkg2.setId(lkg2Id);
598
599     Collection<LicenseKeyGroupEntity> loadedLkgs =
600         vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1);
601     Assert.assertEquals(loadedLkgs.size(), 2);
602     for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
603       if (lkg2Id.equals(loadedLkg.getId())) {
604         Assert.assertTrue(loadedLkg.equals(lkg2));
605       }
606     }
607   }
608
609   @Test(dependsOnMethods = {"listTest"})
610   public void deleteTest() {
611     vendorLicenseManager
612         .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1);
613
614     LicenseKeyGroupEntity loadedLkg1 =
615         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
616     Assert.assertEquals(loadedLkg1, null);
617
618     Collection<LicenseKeyGroupEntity> loadedLkgs =
619         licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
620     Assert.assertEquals(loadedLkgs.size(), 1);
621     Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
622   }
623
624   @Test(dependsOnMethods = "deleteTest")
625   public void testCreateWithRemovedName() {
626     testCreate(vlm1Id, LKG1_NAME);
627   }
628   */
629 }