2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.openecomp.sdc.vendorlicense.impl;
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;
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;
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;
50 public class LicenseKeyGroupTest {
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);
66 private VendorLicenseFacade vendorLicenseFacade;
69 private LicenseKeyGroupDao licenseKeyGroupDao;
71 private LimitDao limitDao;
75 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
78 public void setUp() throws Exception {
79 MockitoAnnotations.initMocks(this);
83 public void tearDown(){
84 vendorLicenseManagerImpl = null;
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;
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);
106 LicenseKeyGroupEntity licenseKeyGroup =
107 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
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());
115 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
116 "Core",AggregationFunction.Average,10,"Hour");
118 ArrayList<LimitEntity> limitEntityList = new ArrayList();
119 limitEntityList.add(limitEntity);
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());
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);
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)
144 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
146 verify(limitDao).delete(anyObject());
150 public void deleteLicenseKeyGroupInvalidTest() {
152 Set<OperationalScope> opScopeChoices;
153 opScopeChoices = new HashSet<>();
154 opScopeChoices.add(OperationalScope.Core);
155 opScopeChoices.add(OperationalScope.CPU);
156 opScopeChoices.add(OperationalScope.Network_Wide);
158 LicenseKeyGroupEntity licenseKeyGroup =
159 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
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());
167 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
168 "Core",AggregationFunction.Average,10,"Hour");
170 ArrayList<LimitEntity> limitEntityList = new ArrayList();
171 limitEntityList.add(limitEntity);
173 doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(anyObject());
174 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
175 doReturn(false).when(limitDao).isLimitPresent(anyObject());
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);
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)
196 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
197 } catch (CoreException exception) {
198 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
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));
216 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
217 verify(vendorLicenseFacade).createLicenseKeyGroup(lkg);
221 public void createWithInvalidStartExpiryDateTest() {
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);
238 } catch (CoreException exception) {
239 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
244 public void createWithoutStartDateTest() {
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();
260 } catch (CoreException exception) {
261 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
266 public void createWithSameStartExpiryDateTest() {
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();
283 } catch (CoreException exception) {
284 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
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));
302 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
303 verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg);
307 public void updateWithInvalidStartExpiryDateTest() {
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);
324 } catch (CoreException exception) {
325 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
330 public void updateWithoutStartDateTest() {
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);
346 } catch (CoreException exception) {
347 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
352 public void updateWithSameStartExpiryDateTest() {
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);
369 } catch (CoreException exception) {
370 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
375 public void testListlistLicenseKeyGroups() {
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");
386 doReturn(Arrays.asList(
387 createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME, "LKG1 dec",
388 LicenseKeyType.Universal,
390 createLicenseKeyGroup(vlm1_id, VERSION01, lkg2_id, LKG2_NAME, "LKG2 dec", LicenseKeyType
391 .Universal, multiChoiceOrOther)))
392 .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
394 Collection<LicenseKeyGroupEntity> LKGs =
395 vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01);
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)));
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");
413 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
414 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
416 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
418 LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg);
419 verify(licenseKeyGroupDao).get(lkg);
421 Assert.assertEquals(lkgRetrived.getId(), lkg.getId());
422 Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(), lkg.getVendorLicenseModelId());
423 Assert.assertEquals(lkgRetrived.getVersion(), lkg.getVersion());
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");
438 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
439 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
441 lkg.setReferencingFeatureGroups(new HashSet<>());
443 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
445 doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id, VERSION01, lkg1_id);
447 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(), anyObject(),
448 anyObject(), anyObject());
450 vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg);
452 verify(licenseKeyGroupDao).delete(lkg);
456 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
458 String name, String desc,
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;
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;
484 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
485 String name, String desc,
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;
499 public void setUp() throws Exception {
500 MockitoAnnotations.initMocks(this);
504 private void init() {
505 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
506 noSqlDb = NoSqlDbFactory.getInstance().createInterface();
508 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
509 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
511 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
512 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
517 public void createTest() {
518 lkg1Id = testCreate(vlm1Id, LKG1_NAME);
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();
533 LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
534 Assert.assertTrue(loadedLkg1.equals(lkg1));
538 @Test(dependsOnMethods = {"createTest"})
539 public void testCreateWithExistingName_negative() {
541 LicenseKeyGroupEntity lkg1 =
542 createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
543 new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
545 vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
547 } catch (CoreException exception) {
548 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
552 @Test(dependsOnMethods = {"createTest"})
553 public void testCreateWithExistingNameUnderOtherVlm() {
554 testCreate(vlm2Id, LKG1_NAME);
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");
566 vendorLicenseManager.updateLicenseKeyGroup(lkg11);
568 LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg11);
569 Assert.assertTrue(loadedLkg1.equals(lkg1));
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();
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));
593 @Test(dependsOnMethods = {"listTest"})
594 public void deleteTest() {
596 .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)1);
598 LicenseKeyGroupEntity loadedLkg1 =
599 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
600 Assert.assertEquals(loadedLkg1, null);
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);
608 @Test(dependsOnMethods = "deleteTest")
609 public void testCreateWithRemovedName() {
610 testCreate(vlm1Id, LKG1_NAME);