2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.sdc.vendorlicense.impl;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.mockito.Spy;
28 import org.openecomp.sdc.common.errors.CoreException;
29 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
30 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
31 import org.openecomp.sdc.vendorlicense.dao.types.*;
32 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
33 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
34 import org.openecomp.sdc.versioning.dao.types.Version;
35 import org.openecomp.sdc.versioning.types.VersionInfo;
36 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
37 import org.testng.Assert;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
41 import java.util.ArrayList;
42 import java.time.LocalDate;
43 import java.time.format.DateTimeFormatter;
44 import java.util.Arrays;
45 import java.util.Collection;
46 import java.util.HashSet;
49 import static org.mockito.Matchers.anyObject;
50 import static org.mockito.Mockito.doNothing;
51 import static org.mockito.Mockito.doReturn;
52 import static org.mockito.Mockito.verify;
54 public class LicenseKeyGroupTest {
56 //JUnit Test Cases using Mockito
57 private final String USER = "lkgTestUser";
58 private final String LKG_NAME = "LKG name";
59 private final String LKG2_NAME = "LKG2 name";
60 private final String LT_NAME = "LT name";
61 private final String LKG1_NAME = "LKG1 name";
62 private final String USER1 = "user1";
63 private static String lkg1_id = "lkg1_id";
64 private static String lkg2_id = "lkg2_id";
65 private static String vlm1_id = "vlm1_id";
66 public static final Version VERSION01 = new Version(0, 1);
70 private VendorLicenseFacade vendorLicenseFacade;
73 private LicenseKeyGroupDao licenseKeyGroupDao;
75 private LimitDao limitDao;
79 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
82 public void setUp() throws Exception {
83 MockitoAnnotations.initMocks(this);
86 private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set<OperationalScope> operationalScopeChoices,
87 String operationalScopeOther)
89 LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
90 licenseKeyGroupEntity.setType(type);
91 licenseKeyGroupEntity.setOperationalScope(
92 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
93 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, USER1);
215 verify(vendorLicenseFacade).createLicenseKeyGroup(lkg,USER1);
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",LicenseKeyType.Unique,
229 new MultiChoiceOrOther<>(opScopeChoices, null));
230 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
231 lkg.setStartDate(LocalDate.now().format(formatter));
232 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
233 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1);
235 } catch (CoreException exception) {
236 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
241 public void createWithoutStartDateTest() {
244 Set<OperationalScope> opScopeChoices;
245 opScopeChoices = new HashSet<>();
246 opScopeChoices.add(OperationalScope.Core);
247 opScopeChoices.add(OperationalScope.CPU);
248 opScopeChoices.add(OperationalScope.Network_Wide);
249 LicenseKeyGroupEntity lkg =
250 createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
251 new MultiChoiceOrOther<>(opScopeChoices, null));
252 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
253 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
254 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
256 } catch (CoreException exception) {
257 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
262 public void createWithSameStartExpiryDateTest() {
265 Set<OperationalScope> opScopeChoices;
266 opScopeChoices = new HashSet<>();
267 opScopeChoices.add(OperationalScope.Core);
268 opScopeChoices.add(OperationalScope.CPU);
269 opScopeChoices.add(OperationalScope.Network_Wide);
270 LicenseKeyGroupEntity lkg =
271 createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
272 new MultiChoiceOrOther<>(opScopeChoices, null));
273 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
274 lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
275 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
276 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
278 } catch (CoreException exception) {
279 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
284 public void testUpdate() {
285 Set<OperationalScope> opScopeChoices;
286 opScopeChoices = new HashSet<>();
287 opScopeChoices.add(OperationalScope.Core);
288 opScopeChoices.add(OperationalScope.CPU);
289 opScopeChoices.add(OperationalScope.Network_Wide);
290 LicenseKeyGroupEntity lkg =
291 createLicenseKeyGroup(vlm1_id, null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
292 new MultiChoiceOrOther<>(opScopeChoices, null));
293 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
294 lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
295 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
296 VersionInfo info = new VersionInfo();
297 info.getViewableVersions().add(VERSION01);
298 info.setActiveVersion(VERSION01);
299 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
301 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
302 verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg,USER1);
303 verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
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",LicenseKeyType.Unique,
317 new MultiChoiceOrOther<>(opScopeChoices, null));
318 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
319 lkg.setStartDate(LocalDate.now().format(formatter));
320 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
321 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
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",LicenseKeyType.Unique,
339 new MultiChoiceOrOther<>(opScopeChoices, null));
340 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
341 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
342 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
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",LicenseKeyType.Unique,
360 new MultiChoiceOrOther<>(opScopeChoices, null));
361 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
362 lkg.setStartDate(LocalDate.now().format(formatter));
363 lkg.setExpiryDate(LocalDate.now().format(formatter));
364 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
366 } catch (CoreException exception) {
367 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
372 public void testListlistLicenseKeyGroups(){
374 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
375 Set<OperationalScope> opScopeChoices = new HashSet<>();
376 opScopeChoices.add(OperationalScope.Core);
377 opScopeChoices.add(OperationalScope.CPU);
378 opScopeChoices.add(OperationalScope.Network_Wide);
379 multiChoiceOrOther.setChoices(opScopeChoices);
380 multiChoiceOrOther.setOther("Other");
382 doReturn(Arrays.asList(
383 createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,"LKG1 dec", LicenseKeyType.Universal,
385 createLicenseKeyGroup(vlm1_id,VERSION01, lkg2_id, LKG2_NAME,"LKG2 dec", LicenseKeyType
386 .Universal, multiChoiceOrOther)))
387 .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
389 Collection<LicenseKeyGroupEntity> LKGs =
390 vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
392 verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
393 Assert.assertEquals(LKGs.size(), 2);
394 LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
398 public void testGetLicenseKeyGroup(){
399 VersionInfo versionInfo = new VersionInfo();
400 versionInfo.setActiveVersion(VERSION01);
401 versionInfo.setLockingUser(USER1);
402 ArrayList<Version> viewable = new ArrayList<Version>();
403 viewable.add(VERSION01);
404 versionInfo.setViewableVersions(viewable);
405 versionInfo.setActiveVersion(VERSION01);
407 doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
408 VersionableEntityAction.Read, USER1);
410 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
411 Set<OperationalScope> opScopeChoices = new HashSet<>();
412 opScopeChoices.add(OperationalScope.Core);
413 opScopeChoices.add(OperationalScope.CPU);
414 opScopeChoices.add(OperationalScope.Network_Wide);
415 multiChoiceOrOther.setChoices(opScopeChoices);
416 multiChoiceOrOther.setOther("Other");
418 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
419 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
421 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
423 LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg,USER1);
424 verify(licenseKeyGroupDao).get(lkg);
426 Assert.assertEquals(lkgRetrived.getId(),lkg.getId());
427 Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(),lkg.getVendorLicenseModelId());
428 Assert.assertEquals(lkgRetrived.getVersion(),lkg.getVersion());
433 public void testDeleteLicenseKeyGroup() {
435 VersionInfo versionInfo = new VersionInfo();
436 versionInfo.setActiveVersion(VERSION01);
437 versionInfo.setLockingUser(USER1);
438 ArrayList<Version> viewable = new ArrayList<Version>();
439 viewable.add(VERSION01);
440 versionInfo.setViewableVersions(viewable);
442 doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
443 VersionableEntityAction.Write, USER1);
446 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
447 Set<OperationalScope> opScopeChoices = new HashSet<>();
448 opScopeChoices.add(OperationalScope.Core);
449 opScopeChoices.add(OperationalScope.CPU);
450 opScopeChoices.add(OperationalScope.Network_Wide);
451 multiChoiceOrOther.setChoices(opScopeChoices);
452 multiChoiceOrOther.setOther("Other");
454 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
455 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
457 lkg.setReferencingFeatureGroups(new HashSet<>());
459 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
461 doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id,VERSION01,lkg1_id,USER1);
463 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(),
464 anyObject(),anyObject());
466 vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg, USER1);
468 verify(licenseKeyGroupDao).delete(lkg);
469 verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
473 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,String id,
474 String name, String desc,
476 MultiChoiceOrOther<OperationalScope> operationalScope) {
477 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
478 licenseKeyGroup.setVendorLicenseModelId(vlmId);
479 licenseKeyGroup.setVersion(version);
480 licenseKeyGroup.setId(id);
481 licenseKeyGroup.setName(name);
482 licenseKeyGroup.setDescription(desc);
483 licenseKeyGroup.setType(type);
484 licenseKeyGroup.setOperationalScope(operationalScope);
485 return licenseKeyGroup;
488 /*public static final String LKG1_NAME = "LKG1 name";
489 private static final Version VERSION01 = new Version(0, 1);
490 public static final String LKG1_NAME = "LKG1 name";
491 private static final String USER1 = "user1";
492 public static String vlm1Id;
493 public static String vlm2Id;
494 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
495 private static LicenseKeyGroupDao licenseKeyGroupDao;
496 private static NoSqlDb noSqlDb;
497 private static String lkg1Id;
498 private static String lkg2Id;
500 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
501 String name, String desc,
503 MultiChoiceOrOther<OperationalScope> operationalScope) {
504 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
505 licenseKeyGroup.setVendorLicenseModelId(vlmId);
506 licenseKeyGroup.setVersion(version);
507 licenseKeyGroup.setName(name);
508 licenseKeyGroup.setDescription(desc);
509 licenseKeyGroup.setType(type);
510 licenseKeyGroup.setOperationalScope(operationalScope);
511 return licenseKeyGroup;
515 public void setUp() throws Exception {
516 MockitoAnnotations.initMocks(this);
520 private void init() {
521 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
522 noSqlDb = NoSqlDbFactory.getInstance().createInterface();
524 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
525 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
526 "icon1"), USER1).getId();
527 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
528 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
533 public void createTest() {
534 lkg1Id = testCreate(vlm1Id, LKG1_NAME);
537 private String testCreate(String vlmId, String name) {
538 Set<OperationalScope> opScopeChoices = new HashSet<>();
539 opScopeChoices.add(OperationalScope.CPU);
540 opScopeChoices.add(OperationalScope.VM);
541 opScopeChoices.add(OperationalScope.Tenant);
542 opScopeChoices.add(OperationalScope.Data_Center);
543 LicenseKeyGroupEntity
544 lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
545 new MultiChoiceOrOther<>(opScopeChoices, null));
546 String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
549 LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
550 Assert.assertTrue(loadedLkg1.equals(lkg1));
554 @Test(dependsOnMethods = {"createTest"})
555 public void testCreateWithExistingName_negative() {
557 LicenseKeyGroupEntity lkg1 =
558 createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
559 new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
561 vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
563 } catch (CoreException exception) {
564 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
568 @Test(dependsOnMethods = {"createTest"})
569 public void testCreateWithExistingNameUnderOtherVlm() {
570 testCreate(vlm2Id, LKG1_NAME);
573 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
574 public void updateAndGetTest() {
575 LicenseKeyGroupEntity lkg1 =
576 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
577 Set<OperationalScope> opScopeChoices = new HashSet<>();
578 opScopeChoices.add(OperationalScope.Other);
579 lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
580 lkg1.setDescription("LKG1 dec updated");
582 vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1);
584 LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1);
585 Assert.assertTrue(loadedLkg1.equals(lkg1));
589 @Test(dependsOnMethods = {"updateAndGetTest"})
590 public void listTest() {
591 Set<OperationalScope> opScopeChoices = new HashSet<>();
592 opScopeChoices.add(OperationalScope.Network_Wide);
593 LicenseKeyGroupEntity lkg2 =
594 createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
595 new MultiChoiceOrOther<>(opScopeChoices, null));
596 lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId();
599 Collection<LicenseKeyGroupEntity> loadedLkgs =
600 vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1);
601 Assert.assertEquals(loadedLkgs.size(), 2);
602 for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
603 if (lkg2Id.equals(loadedLkg.getId())) {
604 Assert.assertTrue(loadedLkg.equals(lkg2));
609 @Test(dependsOnMethods = {"listTest"})
610 public void deleteTest() {
612 .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1);
614 LicenseKeyGroupEntity loadedLkg1 =
615 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
616 Assert.assertEquals(loadedLkg1, null);
618 Collection<LicenseKeyGroupEntity> loadedLkgs =
619 licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
620 Assert.assertEquals(loadedLkgs.size(), 1);
621 Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
624 @Test(dependsOnMethods = "deleteTest")
625 public void testCreateWithRemovedName() {
626 testCreate(vlm1Id, LKG1_NAME);