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 org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
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 java.time.LocalDate;
39 import java.time.format.DateTimeFormatter;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.HashSet;
45 import static org.mockito.Matchers.anyObject;
46 import static org.mockito.Mockito.*;
48 public class LicenseKeyGroupTest {
50 //JUnit Test Cases using Mockito
51 private final String USER = "lkgTestUser";
52 private final String LKG_NAME = "LKG name";
53 private final String LKG2_NAME = "LKG2 name";
54 private final String LT_NAME = "LT name";
55 private final String LKG1_NAME = "LKG1 name";
56 private final String USER1 = "user1";
57 private static String lkg1_id = "lkg1_id";
58 private static String lkg2_id = "lkg2_id";
59 private static String vlm1_id = "vlm1_id";
60 public static final Version VERSION01 = new Version(0, 1);
64 private VendorLicenseFacade vendorLicenseFacade;
67 private LicenseKeyGroupDao licenseKeyGroupDao;
69 private LimitDao limitDao;
73 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
76 public void setUp() throws Exception {
77 MockitoAnnotations.initMocks(this);
81 public void tearDown(){
82 vendorLicenseManagerImpl = null;
85 private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type,
86 Set<OperationalScope> operationalScopeChoices,
87 String operationalScopeOther) {
88 LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
89 licenseKeyGroupEntity.setType(type);
90 licenseKeyGroupEntity.setOperationalScope(
91 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
92 return licenseKeyGroupEntity;
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);
104 LicenseKeyGroupEntity licenseKeyGroup =
105 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
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());
113 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
114 "Core",AggregationFunction.Average,10,"Hour");
116 ArrayList<LimitEntity> limitEntityList = new ArrayList();
117 limitEntityList.add(limitEntity);
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());
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);
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)
142 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
144 verify(limitDao).delete(anyObject());
148 public void deleteLicenseKeyGroupInvalidTest() {
150 Set<OperationalScope> opScopeChoices;
151 opScopeChoices = new HashSet<>();
152 opScopeChoices.add(OperationalScope.Core);
153 opScopeChoices.add(OperationalScope.CPU);
154 opScopeChoices.add(OperationalScope.Network_Wide);
156 LicenseKeyGroupEntity licenseKeyGroup =
157 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
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());
165 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
166 "Core",AggregationFunction.Average,10,"Hour");
168 ArrayList<LimitEntity> limitEntityList = new ArrayList();
169 limitEntityList.add(limitEntity);
171 doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(anyObject());
172 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
173 doReturn(false).when(limitDao).isLimitPresent(anyObject());
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);
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)
194 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
195 } catch (CoreException exception) {
196 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
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));
214 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
215 verify(vendorLicenseFacade).createLicenseKeyGroup(lkg);
219 public void createWithInvalidStartExpiryDateTest() {
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",
229 LicenseKeyType.Unique,
230 new MultiChoiceOrOther<>(opScopeChoices, null));
231 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
232 lkg.setStartDate(LocalDate.now().format(formatter));
233 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
234 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
236 } catch (CoreException exception) {
237 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
242 public void createWithoutStartDateTest() {
245 Set<OperationalScope> opScopeChoices;
246 opScopeChoices = new HashSet<>();
247 opScopeChoices.add(OperationalScope.Core);
248 opScopeChoices.add(OperationalScope.CPU);
249 opScopeChoices.add(OperationalScope.Network_Wide);
250 LicenseKeyGroupEntity lkg =
251 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
252 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).getId();
258 } catch (CoreException exception) {
259 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
264 public void createWithSameStartExpiryDateTest() {
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",
274 LicenseKeyType.Unique,
275 new MultiChoiceOrOther<>(opScopeChoices, null));
276 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
277 lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
278 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
279 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg).getId();
281 } catch (CoreException exception) {
282 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
287 public void testUpdate() {
288 Set<OperationalScope> opScopeChoices;
289 opScopeChoices = new HashSet<>();
290 opScopeChoices.add(OperationalScope.Core);
291 opScopeChoices.add(OperationalScope.CPU);
292 opScopeChoices.add(OperationalScope.Network_Wide);
293 LicenseKeyGroupEntity lkg =
294 createLicenseKeyGroup(vlm1_id, null, lkg1_id, LKG1_NAME, "LKG1 dec", LicenseKeyType.Unique,
295 new MultiChoiceOrOther<>(opScopeChoices, null));
296 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
297 lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
298 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
300 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
301 verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg);
305 public void updateWithInvalidStartExpiryDateTest() {
308 Set<OperationalScope> opScopeChoices;
309 opScopeChoices = new HashSet<>();
310 opScopeChoices.add(OperationalScope.Core);
311 opScopeChoices.add(OperationalScope.CPU);
312 opScopeChoices.add(OperationalScope.Network_Wide);
313 LicenseKeyGroupEntity lkg =
314 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
315 LicenseKeyType.Unique,
316 new MultiChoiceOrOther<>(opScopeChoices, null));
317 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
318 lkg.setStartDate(LocalDate.now().format(formatter));
319 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
320 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
322 } catch (CoreException exception) {
323 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
328 public void updateWithoutStartDateTest() {
331 Set<OperationalScope> opScopeChoices;
332 opScopeChoices = new HashSet<>();
333 opScopeChoices.add(OperationalScope.Core);
334 opScopeChoices.add(OperationalScope.CPU);
335 opScopeChoices.add(OperationalScope.Network_Wide);
336 LicenseKeyGroupEntity lkg =
337 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
338 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);
344 } catch (CoreException exception) {
345 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
350 public void updateWithSameStartExpiryDateTest() {
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",
360 LicenseKeyType.Unique,
361 new MultiChoiceOrOther<>(opScopeChoices, null));
362 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
363 lkg.setStartDate(LocalDate.now().format(formatter));
364 lkg.setExpiryDate(LocalDate.now().format(formatter));
365 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
367 } catch (CoreException exception) {
368 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
373 public void testListlistLicenseKeyGroups() {
375 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
376 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");
384 doReturn(Arrays.asList(
385 createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME, "LKG1 dec",
386 LicenseKeyType.Universal,
388 createLicenseKeyGroup(vlm1_id, VERSION01, lkg2_id, LKG2_NAME, "LKG2 dec", LicenseKeyType
389 .Universal, multiChoiceOrOther)))
390 .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
392 Collection<LicenseKeyGroupEntity> LKGs =
393 vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01);
395 verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
396 Assert.assertEquals(LKGs.size(), 2);
397 LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
401 public void testGetLicenseKeyGroup() {
402 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
403 new MultiChoiceOrOther<OperationalScope>();
404 Set<OperationalScope> opScopeChoices = new HashSet<>();
405 opScopeChoices.add(OperationalScope.Core);
406 opScopeChoices.add(OperationalScope.CPU);
407 opScopeChoices.add(OperationalScope.Network_Wide);
408 multiChoiceOrOther.setChoices(opScopeChoices);
409 multiChoiceOrOther.setOther("Other");
411 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
412 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
414 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
416 LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg);
417 verify(licenseKeyGroupDao).get(lkg);
419 Assert.assertEquals(lkgRetrived.getId(), lkg.getId());
420 Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(), lkg.getVendorLicenseModelId());
421 Assert.assertEquals(lkgRetrived.getVersion(), lkg.getVersion());
426 public void testDeleteLicenseKeyGroup() {
427 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
428 new MultiChoiceOrOther<OperationalScope>();
429 Set<OperationalScope> opScopeChoices = new HashSet<>();
430 opScopeChoices.add(OperationalScope.Core);
431 opScopeChoices.add(OperationalScope.CPU);
432 opScopeChoices.add(OperationalScope.Network_Wide);
433 multiChoiceOrOther.setChoices(opScopeChoices);
434 multiChoiceOrOther.setOther("Other");
436 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
437 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
439 lkg.setReferencingFeatureGroups(new HashSet<>());
441 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
443 doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id, VERSION01, lkg1_id);
445 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(), anyObject(),
446 anyObject(), anyObject());
448 vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg);
450 verify(licenseKeyGroupDao).delete(lkg);
454 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
456 String name, String desc,
458 MultiChoiceOrOther<OperationalScope> operationalScope) {
459 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
460 licenseKeyGroup.setVendorLicenseModelId(vlmId);
461 licenseKeyGroup.setVersion(version);
462 licenseKeyGroup.setId(id);
463 licenseKeyGroup.setName(name);
464 licenseKeyGroup.setDescription(desc);
465 licenseKeyGroup.setType(type);
466 licenseKeyGroup.setOperationalScope(operationalScope);
467 return licenseKeyGroup;
470 /*public static final String LKG1_NAME = "LKG1 name";
471 private static final Version VERSION01 = new Version(0, 1);
472 public static final String LKG1_NAME = "LKG1 name";
473 private static final String USER1 = "user1";
474 public static String vlm1Id;
475 public static String vlm2Id;
476 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
477 private static LicenseKeyGroupDao licenseKeyGroupDao;
478 private static NoSqlDb noSqlDb;
479 private static String lkg1Id;
480 private static String lkg2Id;
482 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
483 String name, String desc,
485 MultiChoiceOrOther<OperationalScope> operationalScope) {
486 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
487 licenseKeyGroup.setVendorLicenseModelId(vlmId);
488 licenseKeyGroup.setVersion(version);
489 licenseKeyGroup.setName(name);
490 licenseKeyGroup.setDescription(desc);
491 licenseKeyGroup.setType(type);
492 licenseKeyGroup.setOperationalScope(operationalScope);
493 return licenseKeyGroup;
497 public void setUp() throws Exception {
498 MockitoAnnotations.initMocks(this);
502 private void init() {
503 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
504 noSqlDb = NoSqlDbFactory.getInstance().createInterface();
506 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
507 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
509 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
510 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
515 public void createTest() {
516 lkg1Id = testCreate(vlm1Id, LKG1_NAME);
519 private String testCreate(String vlmId, String name) {
520 Set<OperationalScope> opScopeChoices = new HashSet<>();
521 opScopeChoices.add(OperationalScope.CPU);
522 opScopeChoices.add(OperationalScope.VM);
523 opScopeChoices.add(OperationalScope.Tenant);
524 opScopeChoices.add(OperationalScope.Data_Center);
525 LicenseKeyGroupEntity
526 lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
527 new MultiChoiceOrOther<>(opScopeChoices, null));
528 String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
531 LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
532 Assert.assertTrue(loadedLkg1.equals(lkg1));
536 @Test(dependsOnMethods = {"createTest"})
537 public void testCreateWithExistingName_negative() {
539 LicenseKeyGroupEntity lkg1 =
540 createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
541 new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
543 vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
545 } catch (CoreException exception) {
546 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
550 @Test(dependsOnMethods = {"createTest"})
551 public void testCreateWithExistingNameUnderOtherVlm() {
552 testCreate(vlm2Id, LKG1_NAME);
555 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
556 public void updateAndGetTest() {
557 LicenseKeyGroupEntity lkg1 =
558 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
559 Set<OperationalScope> opScopeChoices = new HashSet<>();
560 opScopeChoices.add(OperationalScope.Other);
561 lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
562 lkg1.setDescription("LKG1 dec updated");
564 vendorLicenseManager.updateLicenseKeyGroup(lkg11);
566 LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg11);
567 Assert.assertTrue(loadedLkg1.equals(lkg1));
571 @Test(dependsOnMethods = {"updateAndGetTest"})
572 public void listTest() {
573 Set<OperationalScope> opScopeChoices = new HashSet<>();
574 opScopeChoices.add(OperationalScope.Network_Wide);
575 LicenseKeyGroupEntity lkg2 =
576 createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
577 new MultiChoiceOrOther<>(opScopeChoices, null));
578 lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg21).getId();
581 Collection<LicenseKeyGroupEntity> loadedLkgs =
582 vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null1);
583 Assert.assertEquals(loadedLkgs.size(), 2);
584 for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
585 if (lkg2Id.equals(loadedLkg.getId())) {
586 Assert.assertTrue(loadedLkg.equals(lkg2));
591 @Test(dependsOnMethods = {"listTest"})
592 public void deleteTest() {
594 .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)1);
596 LicenseKeyGroupEntity loadedLkg1 =
597 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
598 Assert.assertEquals(loadedLkg1, null);
600 Collection<LicenseKeyGroupEntity> loadedLkgs =
601 licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
602 Assert.assertEquals(loadedLkgs.size(), 1);
603 Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
606 @Test(dependsOnMethods = "deleteTest")
607 public void testCreateWithRemovedName() {
608 testCreate(vlm1Id, LKG1_NAME);