f0dd383a1f1a00472c1ca6ee28de704933f82853
[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.logging.api.Logger;
30 import org.openecomp.sdc.logging.api.LoggerFactory;
31 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
32 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
33 import org.openecomp.sdc.vendorlicense.dao.types.*;
34 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
35 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
36 import org.openecomp.sdc.versioning.dao.types.Version;
37 import org.openecomp.sdc.versioning.types.VersionInfo;
38 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
39 import org.testng.Assert;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
42
43 import java.util.ArrayList;
44 import java.time.LocalDate;
45 import java.time.format.DateTimeFormatter;
46 import java.util.Arrays;
47 import java.util.Collection;
48 import java.util.HashSet;
49 import java.util.Set;
50
51 import static org.mockito.Matchers.anyObject;
52 import static org.mockito.Mockito.doNothing;
53 import static org.mockito.Mockito.doReturn;
54 import static org.mockito.Mockito.verify;
55
56 public class LicenseKeyGroupTest {
57
58   //JUnit Test Cases using Mockito
59   private  final String USER = "lkgTestUser";
60   private  final String LKG_NAME = "LKG name";
61   private  final String LKG2_NAME = "LKG2 name";
62   private  final String LT_NAME = "LT name";
63   private final String LKG1_NAME = "LKG1 name";
64   private final String USER1 = "user1";
65   private static String lkg1_id = "lkg1_id";
66   private static String lkg2_id = "lkg2_id";
67   private static String vlm1_id = "vlm1_id";
68   public static final Version VERSION01 = new Version(0, 1);
69
70
71   @Mock
72   private VendorLicenseFacade vendorLicenseFacade;
73
74   @Mock
75   private LicenseKeyGroupDao licenseKeyGroupDao;
76   @Mock
77   private LimitDao limitDao;
78
79   @InjectMocks
80   @Spy
81   private VendorLicenseManagerImpl vendorLicenseManagerImpl;
82
83   @BeforeMethod
84   public void setUp() throws Exception {
85     MockitoAnnotations.initMocks(this);
86   }
87
88   private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set<OperationalScope> operationalScopeChoices,
89                                                       String operationalScopeOther)
90   {
91     LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
92     licenseKeyGroupEntity.setType(type);
93     licenseKeyGroupEntity.setOperationalScope(
94         new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
95     return licenseKeyGroupEntity;
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, USER1);
217     verify(vendorLicenseFacade).createLicenseKeyGroup(lkg,USER1);
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",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, USER1);
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",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, USER1).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",LicenseKeyType.Unique,
274               new MultiChoiceOrOther<>(opScopeChoices, null));
275       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
276       lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
277       lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
278       vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
279       Assert.fail();
280     } catch (CoreException exception) {
281       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
282     }
283   }
284
285   @Test
286   public void testUpdate() {
287     Set<OperationalScope> opScopeChoices;
288     opScopeChoices = new HashSet<>();
289     opScopeChoices.add(OperationalScope.Core);
290     opScopeChoices.add(OperationalScope.CPU);
291     opScopeChoices.add(OperationalScope.Network_Wide);
292     LicenseKeyGroupEntity lkg =
293         createLicenseKeyGroup(vlm1_id, null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
294             new MultiChoiceOrOther<>(opScopeChoices, null));
295     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
296     lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
297     lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
298     VersionInfo info = new VersionInfo();
299     info.getViewableVersions().add(VERSION01);
300     info.setActiveVersion(VERSION01);
301     doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
302
303     vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
304     verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg,USER1);
305     verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
306   }
307
308   @Test
309   public void updateWithInvalidStartExpiryDateTest() {
310     try {
311
312       Set<OperationalScope> opScopeChoices;
313       opScopeChoices = new HashSet<>();
314       opScopeChoices.add(OperationalScope.Core);
315       opScopeChoices.add(OperationalScope.CPU);
316       opScopeChoices.add(OperationalScope.Network_Wide);
317       LicenseKeyGroupEntity lkg =
318           createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
319               new MultiChoiceOrOther<>(opScopeChoices, null));
320       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
321       lkg.setStartDate(LocalDate.now().format(formatter));
322       lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
323       vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
324       Assert.fail();
325     } catch (CoreException exception) {
326       Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
327     }
328   }
329
330   @Test
331   public void updateWithoutStartDateTest() {
332     try {
333
334       Set<OperationalScope> opScopeChoices;
335       opScopeChoices = new HashSet<>();
336       opScopeChoices.add(OperationalScope.Core);
337       opScopeChoices.add(OperationalScope.CPU);
338       opScopeChoices.add(OperationalScope.Network_Wide);
339       LicenseKeyGroupEntity lkg =
340           createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",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, USER1);
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",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, USER1);
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 = 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", LicenseKeyType.Universal,
386             multiChoiceOrOther),
387         createLicenseKeyGroup(vlm1_id,VERSION01, lkg2_id, LKG2_NAME,"LKG2 dec", LicenseKeyType
388             .Universal, multiChoiceOrOther)))
389         .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
390
391     Collection<LicenseKeyGroupEntity> LKGs =
392         vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
393
394     verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
395     Assert.assertEquals(LKGs.size(), 2);
396     LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
397   }
398
399   @Test
400   public void testGetLicenseKeyGroup(){
401     VersionInfo versionInfo = new VersionInfo();
402     versionInfo.setActiveVersion(VERSION01);
403     versionInfo.setLockingUser(USER1);
404     ArrayList<Version> viewable = new ArrayList<Version>();
405     viewable.add(VERSION01);
406     versionInfo.setViewableVersions(viewable);
407     versionInfo.setActiveVersion(VERSION01);
408
409     doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
410         VersionableEntityAction.Read, USER1);
411
412     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
413     Set<OperationalScope> opScopeChoices = new HashSet<>();
414     opScopeChoices.add(OperationalScope.Core);
415     opScopeChoices.add(OperationalScope.CPU);
416     opScopeChoices.add(OperationalScope.Network_Wide);
417     multiChoiceOrOther.setChoices(opScopeChoices);
418     multiChoiceOrOther.setOther("Other");
419
420     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
421         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
422
423     doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
424
425     LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg,USER1);
426     verify(licenseKeyGroupDao).get(lkg);
427
428     Assert.assertEquals(lkgRetrived.getId(),lkg.getId());
429     Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(),lkg.getVendorLicenseModelId());
430     Assert.assertEquals(lkgRetrived.getVersion(),lkg.getVersion());
431
432   }
433
434   @Test
435   public void testDeleteLicenseKeyGroup() {
436
437     VersionInfo versionInfo = new VersionInfo();
438     versionInfo.setActiveVersion(VERSION01);
439     versionInfo.setLockingUser(USER1);
440     ArrayList<Version> viewable = new ArrayList<Version>();
441     viewable.add(VERSION01);
442     versionInfo.setViewableVersions(viewable);
443
444     doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
445         VersionableEntityAction.Write, USER1);
446
447
448     MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
449     Set<OperationalScope> opScopeChoices = new HashSet<>();
450     opScopeChoices.add(OperationalScope.Core);
451     opScopeChoices.add(OperationalScope.CPU);
452     opScopeChoices.add(OperationalScope.Network_Wide);
453     multiChoiceOrOther.setChoices(opScopeChoices);
454     multiChoiceOrOther.setOther("Other");
455
456     LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
457         "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
458
459     lkg.setReferencingFeatureGroups(new HashSet<>());
460
461     doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
462
463     doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id,VERSION01,lkg1_id,USER1);
464
465     doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(),
466         anyObject(),anyObject());
467
468     vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg, USER1);
469
470     verify(licenseKeyGroupDao).delete(lkg);
471     verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
472
473   }
474
475   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,String id,
476                                                             String name, String desc,
477                                                             LicenseKeyType type,
478                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
479     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
480     licenseKeyGroup.setVendorLicenseModelId(vlmId);
481     licenseKeyGroup.setVersion(version);
482     licenseKeyGroup.setId(id);
483     licenseKeyGroup.setName(name);
484     licenseKeyGroup.setDescription(desc);
485     licenseKeyGroup.setType(type);
486     licenseKeyGroup.setOperationalScope(operationalScope);
487     return licenseKeyGroup;
488   }
489
490   /*public static final String LKG1_NAME = "LKG1 name";
491   private static final Version VERSION01 = new Version(0, 1);
492   public static final String LKG1_NAME = "LKG1 name";
493   private static final String USER1 = "user1";
494   public static String vlm1Id;
495   public static String vlm2Id;
496   private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
497   private static LicenseKeyGroupDao licenseKeyGroupDao;
498   private static NoSqlDb noSqlDb;
499   private static String lkg1Id;
500   private static String lkg2Id;
501
502   public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
503                                                             String name, String desc,
504                                                             LicenseKeyType type,
505                                                             MultiChoiceOrOther<OperationalScope> operationalScope) {
506     LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
507     licenseKeyGroup.setVendorLicenseModelId(vlmId);
508     licenseKeyGroup.setVersion(version);
509     licenseKeyGroup.setName(name);
510     licenseKeyGroup.setDescription(desc);
511     licenseKeyGroup.setType(type);
512     licenseKeyGroup.setOperationalScope(operationalScope);
513     return licenseKeyGroup;
514   }
515
516   @BeforeMethod
517   public void setUp() throws Exception {
518     MockitoAnnotations.initMocks(this);
519   }
520
521   /*@BeforeClass
522   private void init() {
523     licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
524     noSqlDb = NoSqlDbFactory.getInstance().createInterface();
525
526     vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
527         .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
528             "icon1"), USER1).getId();
529     vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
530             .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
531         USER1).getId();
532   }
533
534   @Test
535   public void createTest() {
536     lkg1Id = testCreate(vlm1Id, LKG1_NAME);
537   }
538
539   private String testCreate(String vlmId, String name) {
540     Set<OperationalScope> opScopeChoices = new HashSet<>();
541     opScopeChoices.add(OperationalScope.CPU);
542     opScopeChoices.add(OperationalScope.VM);
543     opScopeChoices.add(OperationalScope.Tenant);
544     opScopeChoices.add(OperationalScope.Data_Center);
545     LicenseKeyGroupEntity
546         lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
547         new MultiChoiceOrOther<>(opScopeChoices, null));
548     String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
549     lkg1.setId(lkg1Id);
550
551     LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
552     Assert.assertTrue(loadedLkg1.equals(lkg1));
553     return lkg1Id;
554   }
555
556   @Test(dependsOnMethods = {"createTest"})
557   public void testCreateWithExistingName_negative() {
558     try {
559       LicenseKeyGroupEntity lkg1 =
560           createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
561               new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
562                   "other op scope"));
563       vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
564       Assert.fail();
565     } catch (CoreException exception) {
566       Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
567     }
568   }
569
570   @Test(dependsOnMethods = {"createTest"})
571   public void testCreateWithExistingNameUnderOtherVlm() {
572     testCreate(vlm2Id, LKG1_NAME);
573   }
574
575   @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
576   public void updateAndGetTest() {
577     LicenseKeyGroupEntity lkg1 =
578         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
579     Set<OperationalScope> opScopeChoices = new HashSet<>();
580     opScopeChoices.add(OperationalScope.Other);
581     lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
582     lkg1.setDescription("LKG1 dec updated");
583
584     vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1);
585
586     LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1);
587     Assert.assertTrue(loadedLkg1.equals(lkg1));
588
589   }
590
591   @Test(dependsOnMethods = {"updateAndGetTest"})
592   public void listTest() {
593     Set<OperationalScope> opScopeChoices = new HashSet<>();
594     opScopeChoices.add(OperationalScope.Network_Wide);
595     LicenseKeyGroupEntity lkg2 =
596         createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
597             new MultiChoiceOrOther<>(opScopeChoices, null));
598     lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId();
599     lkg2.setId(lkg2Id);
600
601     Collection<LicenseKeyGroupEntity> loadedLkgs =
602         vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1);
603     Assert.assertEquals(loadedLkgs.size(), 2);
604     for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
605       if (lkg2Id.equals(loadedLkg.getId())) {
606         Assert.assertTrue(loadedLkg.equals(lkg2));
607       }
608     }
609   }
610
611   @Test(dependsOnMethods = {"listTest"})
612   public void deleteTest() {
613     vendorLicenseManager
614         .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1);
615
616     LicenseKeyGroupEntity loadedLkg1 =
617         licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
618     Assert.assertEquals(loadedLkg1, null);
619
620     Collection<LicenseKeyGroupEntity> loadedLkgs =
621         licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
622     Assert.assertEquals(loadedLkgs.size(), 1);
623     Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
624   }
625
626   @Test(dependsOnMethods = "deleteTest")
627   public void testCreateWithRemovedName() {
628     testCreate(vlm1Id, LKG1_NAME);
629   }
630   */
631 }