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.mockito.InjectMocks;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.mockito.Spy;
24 import org.openecomp.sdc.common.errors.CoreException;
25 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
26 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
27 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
28 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType;
29 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
30 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
31 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
32 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34 import org.testng.Assert;
35 import org.testng.annotations.AfterMethod;
36 import org.testng.annotations.BeforeMethod;
37 import org.testng.annotations.Test;
39 import java.time.LocalDate;
40 import java.time.format.DateTimeFormatter;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.HashSet;
46 import static org.mockito.Matchers.anyObject;
47 import static org.mockito.Mockito.*;
49 public class LicenseKeyGroupTest {
51 //JUnit Test Cases using Mockito
52 private final String USER = "lkgTestUser";
53 private final String LKG_NAME = "LKG name";
54 private final String LKG2_NAME = "LKG2 name";
55 private final String LT_NAME = "LT name";
56 private final String LKG1_NAME = "LKG1 name";
57 private final String USER1 = "user1";
58 private static String lkg1_id = "lkg1_id";
59 private static String lkg2_id = "lkg2_id";
60 private static String vlm1_id = "vlm1_id";
61 public static final Version VERSION01 = new Version(0, 1);
65 private VendorLicenseFacade vendorLicenseFacade;
68 private LicenseKeyGroupDao licenseKeyGroupDao;
70 private LimitDao limitDao;
74 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
77 public void setUp() throws Exception {
78 MockitoAnnotations.initMocks(this);
82 public void tearDown(){
83 vendorLicenseManagerImpl = null;
86 private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type,
87 Set<OperationalScope> operationalScopeChoices,
88 String operationalScopeOther) {
89 LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
90 licenseKeyGroupEntity.setType(type);
91 licenseKeyGroupEntity.setOperationalScope(
92 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
93 return licenseKeyGroupEntity;
98 public void deleteLicenseKeyGroupTest() {
99 Set<OperationalScope> opScopeChoices;
100 opScopeChoices = new HashSet<>();
101 opScopeChoices.add(OperationalScope.Core);
102 opScopeChoices.add(OperationalScope.CPU);
103 opScopeChoices.add(OperationalScope.Network_Wide);
105 LicenseKeyGroupEntity licenseKeyGroup =
106 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
108 VersionInfo info = new VersionInfo();
109 Version version = new Version();
110 info.getViewableVersions().add(version);
111 info.setActiveVersion(version);
112 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
114 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
115 "Core",AggregationFunction.Average,10,"Hour");
117 ArrayList<LimitEntity> limitEntityList = new ArrayList();
118 limitEntityList.add(limitEntity);
120 doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(anyObject());
121 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
122 doReturn(true).when(limitDao).isLimitPresent(anyObject());
123 doReturn(limitEntity).when(limitDao).get(anyObject());
125 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
126 limitField.setAccessible(true);
127 Field modifiersField = Field.class.getDeclaredField("modifiers");
128 modifiersField.setAccessible(true);
129 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
130 limitField.set(null, limitDao);
132 Field lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao");
133 lkgField.setAccessible(true);
134 modifiersField = Field.class.getDeclaredField("modifiers");
135 modifiersField.setAccessible(true);
136 modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL);
137 lkgField.set(null, licenseKeyGroupDao);
138 } catch(NoSuchFieldException | IllegalAccessException e)
143 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
145 verify(limitDao).delete(anyObject());
149 public void deleteLicenseKeyGroupInvalidTest() {
151 Set<OperationalScope> opScopeChoices;
152 opScopeChoices = new HashSet<>();
153 opScopeChoices.add(OperationalScope.Core);
154 opScopeChoices.add(OperationalScope.CPU);
155 opScopeChoices.add(OperationalScope.Network_Wide);
157 LicenseKeyGroupEntity licenseKeyGroup =
158 createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null);
160 VersionInfo info = new VersionInfo();
161 Version version = new Version();
162 info.getViewableVersions().add(version);
163 info.setActiveVersion(version);
164 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
166 LimitEntity limitEntity = LimitTest.createLimitEntity(LT_NAME,LimitType.Vendor,"string",version,
167 "Core",AggregationFunction.Average,10,"Hour");
169 ArrayList<LimitEntity> limitEntityList = new ArrayList();
170 limitEntityList.add(limitEntity);
172 doReturn(licenseKeyGroup).when(licenseKeyGroupDao).get(anyObject());
173 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
174 doReturn(false).when(limitDao).isLimitPresent(anyObject());
177 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
178 limitField.setAccessible(true);
179 Field modifiersField = Field.class.getDeclaredField("modifiers");
180 modifiersField.setAccessible(true);
181 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
182 limitField.set(null, limitDao);
184 Field lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao");
185 lkgField.setAccessible(true);
186 modifiersField = Field.class.getDeclaredField("modifiers");
187 modifiersField.setAccessible(true);
188 modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL);
189 lkgField.set(null, licenseKeyGroupDao);
190 } catch(NoSuchFieldException | IllegalAccessException e)
195 vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER);
196 } catch (CoreException exception) {
197 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
202 public void createTest() {
203 Set<OperationalScope> opScopeChoices;
204 opScopeChoices = new HashSet<>();
205 opScopeChoices.add(OperationalScope.Core);
206 opScopeChoices.add(OperationalScope.CPU);
207 opScopeChoices.add(OperationalScope.Network_Wide);
208 LicenseKeyGroupEntity lkg =
209 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec", LicenseKeyType.Unique,
210 new MultiChoiceOrOther<>(opScopeChoices, null));
211 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
212 lkg.setStartDate(LocalDate.now().format(formatter));
213 lkg.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
215 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
216 verify(vendorLicenseFacade).createLicenseKeyGroup(lkg);
220 public void createWithInvalidStartExpiryDateTest() {
223 Set<OperationalScope> opScopeChoices;
224 opScopeChoices = new HashSet<>();
225 opScopeChoices.add(OperationalScope.Core);
226 opScopeChoices.add(OperationalScope.CPU);
227 opScopeChoices.add(OperationalScope.Network_Wide);
228 LicenseKeyGroupEntity lkg =
229 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
230 LicenseKeyType.Unique,
231 new MultiChoiceOrOther<>(opScopeChoices, null));
232 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
233 lkg.setStartDate(LocalDate.now().format(formatter));
234 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
235 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg);
237 } catch (CoreException exception) {
238 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
243 public void createWithoutStartDateTest() {
246 Set<OperationalScope> opScopeChoices;
247 opScopeChoices = new HashSet<>();
248 opScopeChoices.add(OperationalScope.Core);
249 opScopeChoices.add(OperationalScope.CPU);
250 opScopeChoices.add(OperationalScope.Network_Wide);
251 LicenseKeyGroupEntity lkg =
252 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
253 LicenseKeyType.Unique,
254 new MultiChoiceOrOther<>(opScopeChoices, null));
255 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
256 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
257 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg).getId();
259 } catch (CoreException exception) {
260 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
265 public void createWithSameStartExpiryDateTest() {
268 Set<OperationalScope> opScopeChoices;
269 opScopeChoices = new HashSet<>();
270 opScopeChoices.add(OperationalScope.Core);
271 opScopeChoices.add(OperationalScope.CPU);
272 opScopeChoices.add(OperationalScope.Network_Wide);
273 LicenseKeyGroupEntity lkg =
274 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
275 LicenseKeyType.Unique,
276 new MultiChoiceOrOther<>(opScopeChoices, null));
277 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
278 lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
279 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
280 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg).getId();
282 } catch (CoreException exception) {
283 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
288 public void testUpdate() {
289 Set<OperationalScope> opScopeChoices;
290 opScopeChoices = new HashSet<>();
291 opScopeChoices.add(OperationalScope.Core);
292 opScopeChoices.add(OperationalScope.CPU);
293 opScopeChoices.add(OperationalScope.Network_Wide);
294 LicenseKeyGroupEntity lkg =
295 createLicenseKeyGroup(vlm1_id, null, lkg1_id, LKG1_NAME, "LKG1 dec", LicenseKeyType.Unique,
296 new MultiChoiceOrOther<>(opScopeChoices, null));
297 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
298 lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
299 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
301 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
302 verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg);
306 public void updateWithInvalidStartExpiryDateTest() {
309 Set<OperationalScope> opScopeChoices;
310 opScopeChoices = new HashSet<>();
311 opScopeChoices.add(OperationalScope.Core);
312 opScopeChoices.add(OperationalScope.CPU);
313 opScopeChoices.add(OperationalScope.Network_Wide);
314 LicenseKeyGroupEntity lkg =
315 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
316 LicenseKeyType.Unique,
317 new MultiChoiceOrOther<>(opScopeChoices, null));
318 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
319 lkg.setStartDate(LocalDate.now().format(formatter));
320 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
321 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
323 } catch (CoreException exception) {
324 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
329 public void updateWithoutStartDateTest() {
332 Set<OperationalScope> opScopeChoices;
333 opScopeChoices = new HashSet<>();
334 opScopeChoices.add(OperationalScope.Core);
335 opScopeChoices.add(OperationalScope.CPU);
336 opScopeChoices.add(OperationalScope.Network_Wide);
337 LicenseKeyGroupEntity lkg =
338 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
339 LicenseKeyType.Unique,
340 new MultiChoiceOrOther<>(opScopeChoices, null));
341 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
342 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
343 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
345 } catch (CoreException exception) {
346 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
351 public void updateWithSameStartExpiryDateTest() {
354 Set<OperationalScope> opScopeChoices;
355 opScopeChoices = new HashSet<>();
356 opScopeChoices.add(OperationalScope.Core);
357 opScopeChoices.add(OperationalScope.CPU);
358 opScopeChoices.add(OperationalScope.Network_Wide);
359 LicenseKeyGroupEntity lkg =
360 createLicenseKeyGroup("vlm1Id", null, lkg1_id, LKG1_NAME, "LKG1 dec",
361 LicenseKeyType.Unique,
362 new MultiChoiceOrOther<>(opScopeChoices, null));
363 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
364 lkg.setStartDate(LocalDate.now().format(formatter));
365 lkg.setExpiryDate(LocalDate.now().format(formatter));
366 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg);
368 } catch (CoreException exception) {
369 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
374 public void testListlistLicenseKeyGroups() {
376 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
377 new MultiChoiceOrOther<OperationalScope>();
378 Set<OperationalScope> opScopeChoices = new HashSet<>();
379 opScopeChoices.add(OperationalScope.Core);
380 opScopeChoices.add(OperationalScope.CPU);
381 opScopeChoices.add(OperationalScope.Network_Wide);
382 multiChoiceOrOther.setChoices(opScopeChoices);
383 multiChoiceOrOther.setOther("Other");
385 doReturn(Arrays.asList(
386 createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME, "LKG1 dec",
387 LicenseKeyType.Universal,
389 createLicenseKeyGroup(vlm1_id, VERSION01, lkg2_id, LKG2_NAME, "LKG2 dec", LicenseKeyType
390 .Universal, multiChoiceOrOther)))
391 .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
393 Collection<LicenseKeyGroupEntity> LKGs =
394 vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01);
396 verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01);
397 Assert.assertEquals(LKGs.size(), 2);
398 LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
402 public void testGetLicenseKeyGroup() {
403 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
404 new MultiChoiceOrOther<OperationalScope>();
405 Set<OperationalScope> opScopeChoices = new HashSet<>();
406 opScopeChoices.add(OperationalScope.Core);
407 opScopeChoices.add(OperationalScope.CPU);
408 opScopeChoices.add(OperationalScope.Network_Wide);
409 multiChoiceOrOther.setChoices(opScopeChoices);
410 multiChoiceOrOther.setOther("Other");
412 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
413 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
415 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
417 LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg);
418 verify(licenseKeyGroupDao).get(lkg);
420 Assert.assertEquals(lkgRetrived.getId(), lkg.getId());
421 Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(), lkg.getVendorLicenseModelId());
422 Assert.assertEquals(lkgRetrived.getVersion(), lkg.getVersion());
427 public void testDeleteLicenseKeyGroup() {
428 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther =
429 new MultiChoiceOrOther<OperationalScope>();
430 Set<OperationalScope> opScopeChoices = new HashSet<>();
431 opScopeChoices.add(OperationalScope.Core);
432 opScopeChoices.add(OperationalScope.CPU);
433 opScopeChoices.add(OperationalScope.Network_Wide);
434 multiChoiceOrOther.setChoices(opScopeChoices);
435 multiChoiceOrOther.setOther("Other");
437 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id, VERSION01, lkg1_id, LKG1_NAME,
438 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
440 lkg.setReferencingFeatureGroups(new HashSet<>());
442 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
444 doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id, VERSION01, lkg1_id);
446 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(), anyObject(),
447 anyObject(), anyObject());
449 vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg);
451 verify(licenseKeyGroupDao).delete(lkg);
455 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
457 String name, String desc,
459 MultiChoiceOrOther<OperationalScope> operationalScope) {
460 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
461 licenseKeyGroup.setVendorLicenseModelId(vlmId);
462 licenseKeyGroup.setVersion(version);
463 licenseKeyGroup.setId(id);
464 licenseKeyGroup.setName(name);
465 licenseKeyGroup.setDescription(desc);
466 licenseKeyGroup.setType(type);
467 licenseKeyGroup.setOperationalScope(operationalScope);
468 return licenseKeyGroup;
471 /*public static final String LKG1_NAME = "LKG1 name";
472 private static final Version VERSION01 = new Version(0, 1);
473 public static final String LKG1_NAME = "LKG1 name";
474 private static final String USER1 = "user1";
475 public static String vlm1Id;
476 public static String vlm2Id;
477 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
478 private static LicenseKeyGroupDao licenseKeyGroupDao;
479 private static NoSqlDb noSqlDb;
480 private static String lkg1Id;
481 private static String lkg2Id;
483 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
484 String name, String desc,
486 MultiChoiceOrOther<OperationalScope> operationalScope) {
487 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
488 licenseKeyGroup.setVendorLicenseModelId(vlmId);
489 licenseKeyGroup.setVersion(version);
490 licenseKeyGroup.setName(name);
491 licenseKeyGroup.setDescription(desc);
492 licenseKeyGroup.setType(type);
493 licenseKeyGroup.setOperationalScope(operationalScope);
494 return licenseKeyGroup;
498 public void setUp() throws Exception {
499 MockitoAnnotations.initMocks(this);
503 private void init() {
504 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
505 noSqlDb = NoSqlDbFactory.getInstance().createInterface();
507 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
508 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
510 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
511 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
516 public void createTest() {
517 lkg1Id = testCreate(vlm1Id, LKG1_NAME);
520 private String testCreate(String vlmId, String name) {
521 Set<OperationalScope> opScopeChoices = new HashSet<>();
522 opScopeChoices.add(OperationalScope.CPU);
523 opScopeChoices.add(OperationalScope.VM);
524 opScopeChoices.add(OperationalScope.Tenant);
525 opScopeChoices.add(OperationalScope.Data_Center);
526 LicenseKeyGroupEntity
527 lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
528 new MultiChoiceOrOther<>(opScopeChoices, null));
529 String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
532 LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
533 Assert.assertTrue(loadedLkg1.equals(lkg1));
537 @Test(dependsOnMethods = {"createTest"})
538 public void testCreateWithExistingName_negative() {
540 LicenseKeyGroupEntity lkg1 =
541 createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
542 new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
544 vendorLicenseManager.createLicenseKeyGroup(lkg11).getId();
546 } catch (CoreException exception) {
547 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
551 @Test(dependsOnMethods = {"createTest"})
552 public void testCreateWithExistingNameUnderOtherVlm() {
553 testCreate(vlm2Id, LKG1_NAME);
556 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
557 public void updateAndGetTest() {
558 LicenseKeyGroupEntity lkg1 =
559 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
560 Set<OperationalScope> opScopeChoices = new HashSet<>();
561 opScopeChoices.add(OperationalScope.Other);
562 lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
563 lkg1.setDescription("LKG1 dec updated");
565 vendorLicenseManager.updateLicenseKeyGroup(lkg11);
567 LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg11);
568 Assert.assertTrue(loadedLkg1.equals(lkg1));
572 @Test(dependsOnMethods = {"updateAndGetTest"})
573 public void listTest() {
574 Set<OperationalScope> opScopeChoices = new HashSet<>();
575 opScopeChoices.add(OperationalScope.Network_Wide);
576 LicenseKeyGroupEntity lkg2 =
577 createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
578 new MultiChoiceOrOther<>(opScopeChoices, null));
579 lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg21).getId();
582 Collection<LicenseKeyGroupEntity> loadedLkgs =
583 vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null1);
584 Assert.assertEquals(loadedLkgs.size(), 2);
585 for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
586 if (lkg2Id.equals(loadedLkg.getId())) {
587 Assert.assertTrue(loadedLkg.equals(lkg2));
592 @Test(dependsOnMethods = {"listTest"})
593 public void deleteTest() {
595 .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)1);
597 LicenseKeyGroupEntity loadedLkg1 =
598 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
599 Assert.assertEquals(loadedLkg1, null);
601 Collection<LicenseKeyGroupEntity> loadedLkgs =
602 licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
603 Assert.assertEquals(loadedLkgs.size(), 1);
604 Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
607 @Test(dependsOnMethods = "deleteTest")
608 public void testCreateWithRemovedName() {
609 testCreate(vlm1Id, LKG1_NAME);