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.logging.api.Logger;
30 import org.openecomp.sdc.logging.api.LoggerFactory;
31 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
32 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
33 import org.openecomp.sdc.vendorlicense.dao.types.*;
34 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
35 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
36 import org.openecomp.sdc.versioning.dao.types.Version;
37 import org.openecomp.sdc.versioning.types.VersionInfo;
38 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
39 import org.testng.Assert;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
43 import java.util.ArrayList;
44 import java.time.LocalDate;
45 import java.time.format.DateTimeFormatter;
46 import java.util.Arrays;
47 import java.util.Collection;
48 import java.util.HashSet;
51 import static org.mockito.Matchers.anyObject;
52 import static org.mockito.Mockito.doNothing;
53 import static org.mockito.Mockito.doReturn;
54 import static org.mockito.Mockito.verify;
56 public class LicenseKeyGroupTest {
58 //JUnit Test Cases using Mockito
59 private final String USER = "lkgTestUser";
60 private final String LKG_NAME = "LKG name";
61 private final String LKG2_NAME = "LKG2 name";
62 private final String LT_NAME = "LT name";
63 private final String LKG1_NAME = "LKG1 name";
64 private final String USER1 = "user1";
65 private static String lkg1_id = "lkg1_id";
66 private static String lkg2_id = "lkg2_id";
67 private static String vlm1_id = "vlm1_id";
68 public static final Version VERSION01 = new Version(0, 1);
72 private VendorLicenseFacade vendorLicenseFacade;
75 private LicenseKeyGroupDao licenseKeyGroupDao;
77 private LimitDao limitDao;
81 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
84 public void setUp() throws Exception {
85 MockitoAnnotations.initMocks(this);
88 private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set<OperationalScope> operationalScopeChoices,
89 String operationalScopeOther)
91 LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity();
92 licenseKeyGroupEntity.setType(type);
93 licenseKeyGroupEntity.setOperationalScope(
94 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
95 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, USER1);
217 verify(vendorLicenseFacade).createLicenseKeyGroup(lkg,USER1);
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",LicenseKeyType.Unique,
231 new MultiChoiceOrOther<>(opScopeChoices, null));
232 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
233 lkg.setStartDate(LocalDate.now().format(formatter));
234 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
235 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1);
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",LicenseKeyType.Unique,
253 new MultiChoiceOrOther<>(opScopeChoices, null));
254 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
255 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
256 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
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",LicenseKeyType.Unique,
274 new MultiChoiceOrOther<>(opScopeChoices, null));
275 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
276 lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter));
277 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
278 vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId();
280 } catch (CoreException exception) {
281 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
286 public void testUpdate() {
287 Set<OperationalScope> opScopeChoices;
288 opScopeChoices = new HashSet<>();
289 opScopeChoices.add(OperationalScope.Core);
290 opScopeChoices.add(OperationalScope.CPU);
291 opScopeChoices.add(OperationalScope.Network_Wide);
292 LicenseKeyGroupEntity lkg =
293 createLicenseKeyGroup(vlm1_id, null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
294 new MultiChoiceOrOther<>(opScopeChoices, null));
295 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
296 lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
297 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
298 VersionInfo info = new VersionInfo();
299 info.getViewableVersions().add(VERSION01);
300 info.setActiveVersion(VERSION01);
301 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
303 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
304 verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg,USER1);
305 verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
309 public void updateWithInvalidStartExpiryDateTest() {
312 Set<OperationalScope> opScopeChoices;
313 opScopeChoices = new HashSet<>();
314 opScopeChoices.add(OperationalScope.Core);
315 opScopeChoices.add(OperationalScope.CPU);
316 opScopeChoices.add(OperationalScope.Network_Wide);
317 LicenseKeyGroupEntity lkg =
318 createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
319 new MultiChoiceOrOther<>(opScopeChoices, null));
320 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
321 lkg.setStartDate(LocalDate.now().format(formatter));
322 lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
323 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
325 } catch (CoreException exception) {
326 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
331 public void updateWithoutStartDateTest() {
334 Set<OperationalScope> opScopeChoices;
335 opScopeChoices = new HashSet<>();
336 opScopeChoices.add(OperationalScope.Core);
337 opScopeChoices.add(OperationalScope.CPU);
338 opScopeChoices.add(OperationalScope.Network_Wide);
339 LicenseKeyGroupEntity lkg =
340 createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique,
341 new MultiChoiceOrOther<>(opScopeChoices, null));
342 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
343 lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
344 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
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",LicenseKeyType.Unique,
362 new MultiChoiceOrOther<>(opScopeChoices, null));
363 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
364 lkg.setStartDate(LocalDate.now().format(formatter));
365 lkg.setExpiryDate(LocalDate.now().format(formatter));
366 vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1);
368 } catch (CoreException exception) {
369 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
374 public void testListlistLicenseKeyGroups(){
376 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
377 Set<OperationalScope> opScopeChoices = new HashSet<>();
378 opScopeChoices.add(OperationalScope.Core);
379 opScopeChoices.add(OperationalScope.CPU);
380 opScopeChoices.add(OperationalScope.Network_Wide);
381 multiChoiceOrOther.setChoices(opScopeChoices);
382 multiChoiceOrOther.setOther("Other");
384 doReturn(Arrays.asList(
385 createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,"LKG1 dec", LicenseKeyType.Universal,
387 createLicenseKeyGroup(vlm1_id,VERSION01, lkg2_id, LKG2_NAME,"LKG2 dec", LicenseKeyType
388 .Universal, multiChoiceOrOther)))
389 .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
391 Collection<LicenseKeyGroupEntity> LKGs =
392 vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
394 verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1);
395 Assert.assertEquals(LKGs.size(), 2);
396 LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id)));
400 public void testGetLicenseKeyGroup(){
401 VersionInfo versionInfo = new VersionInfo();
402 versionInfo.setActiveVersion(VERSION01);
403 versionInfo.setLockingUser(USER1);
404 ArrayList<Version> viewable = new ArrayList<Version>();
405 viewable.add(VERSION01);
406 versionInfo.setViewableVersions(viewable);
407 versionInfo.setActiveVersion(VERSION01);
409 doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
410 VersionableEntityAction.Read, USER1);
412 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
413 Set<OperationalScope> opScopeChoices = new HashSet<>();
414 opScopeChoices.add(OperationalScope.Core);
415 opScopeChoices.add(OperationalScope.CPU);
416 opScopeChoices.add(OperationalScope.Network_Wide);
417 multiChoiceOrOther.setChoices(opScopeChoices);
418 multiChoiceOrOther.setOther("Other");
420 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
421 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
423 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
425 LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg,USER1);
426 verify(licenseKeyGroupDao).get(lkg);
428 Assert.assertEquals(lkgRetrived.getId(),lkg.getId());
429 Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(),lkg.getVendorLicenseModelId());
430 Assert.assertEquals(lkgRetrived.getVersion(),lkg.getVersion());
435 public void testDeleteLicenseKeyGroup() {
437 VersionInfo versionInfo = new VersionInfo();
438 versionInfo.setActiveVersion(VERSION01);
439 versionInfo.setLockingUser(USER1);
440 ArrayList<Version> viewable = new ArrayList<Version>();
441 viewable.add(VERSION01);
442 versionInfo.setViewableVersions(viewable);
444 doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id,
445 VersionableEntityAction.Write, USER1);
448 MultiChoiceOrOther<OperationalScope> multiChoiceOrOther = new MultiChoiceOrOther<OperationalScope>();
449 Set<OperationalScope> opScopeChoices = new HashSet<>();
450 opScopeChoices.add(OperationalScope.Core);
451 opScopeChoices.add(OperationalScope.CPU);
452 opScopeChoices.add(OperationalScope.Network_Wide);
453 multiChoiceOrOther.setChoices(opScopeChoices);
454 multiChoiceOrOther.setOther("Other");
456 LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,
457 "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther);
459 lkg.setReferencingFeatureGroups(new HashSet<>());
461 doReturn(lkg).when(licenseKeyGroupDao).get(anyObject());
463 doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id,VERSION01,lkg1_id,USER1);
465 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(),
466 anyObject(),anyObject());
468 vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg, USER1);
470 verify(licenseKeyGroupDao).delete(lkg);
471 verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01);
475 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,String id,
476 String name, String desc,
478 MultiChoiceOrOther<OperationalScope> operationalScope) {
479 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
480 licenseKeyGroup.setVendorLicenseModelId(vlmId);
481 licenseKeyGroup.setVersion(version);
482 licenseKeyGroup.setId(id);
483 licenseKeyGroup.setName(name);
484 licenseKeyGroup.setDescription(desc);
485 licenseKeyGroup.setType(type);
486 licenseKeyGroup.setOperationalScope(operationalScope);
487 return licenseKeyGroup;
490 /*public static final String LKG1_NAME = "LKG1 name";
491 private static final Version VERSION01 = new Version(0, 1);
492 public static final String LKG1_NAME = "LKG1 name";
493 private static final String USER1 = "user1";
494 public static String vlm1Id;
495 public static String vlm2Id;
496 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
497 private static LicenseKeyGroupDao licenseKeyGroupDao;
498 private static NoSqlDb noSqlDb;
499 private static String lkg1Id;
500 private static String lkg2Id;
502 public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,
503 String name, String desc,
505 MultiChoiceOrOther<OperationalScope> operationalScope) {
506 LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity();
507 licenseKeyGroup.setVendorLicenseModelId(vlmId);
508 licenseKeyGroup.setVersion(version);
509 licenseKeyGroup.setName(name);
510 licenseKeyGroup.setDescription(desc);
511 licenseKeyGroup.setType(type);
512 licenseKeyGroup.setOperationalScope(operationalScope);
513 return licenseKeyGroup;
517 public void setUp() throws Exception {
518 MockitoAnnotations.initMocks(this);
522 private void init() {
523 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
524 noSqlDb = NoSqlDbFactory.getInstance().createInterface();
526 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
527 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec",
528 "icon1"), USER1).getId();
529 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
530 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
535 public void createTest() {
536 lkg1Id = testCreate(vlm1Id, LKG1_NAME);
539 private String testCreate(String vlmId, String name) {
540 Set<OperationalScope> opScopeChoices = new HashSet<>();
541 opScopeChoices.add(OperationalScope.CPU);
542 opScopeChoices.add(OperationalScope.VM);
543 opScopeChoices.add(OperationalScope.Tenant);
544 opScopeChoices.add(OperationalScope.Data_Center);
545 LicenseKeyGroupEntity
546 lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time,
547 new MultiChoiceOrOther<>(opScopeChoices, null));
548 String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
551 LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1);
552 Assert.assertTrue(loadedLkg1.equals(lkg1));
556 @Test(dependsOnMethods = {"createTest"})
557 public void testCreateWithExistingName_negative() {
559 LicenseKeyGroupEntity lkg1 =
560 createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time,
561 new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other),
563 vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId();
565 } catch (CoreException exception) {
566 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
570 @Test(dependsOnMethods = {"createTest"})
571 public void testCreateWithExistingNameUnderOtherVlm() {
572 testCreate(vlm2Id, LKG1_NAME);
575 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
576 public void updateAndGetTest() {
577 LicenseKeyGroupEntity lkg1 =
578 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
579 Set<OperationalScope> opScopeChoices = new HashSet<>();
580 opScopeChoices.add(OperationalScope.Other);
581 lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated"));
582 lkg1.setDescription("LKG1 dec updated");
584 vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1);
586 LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1);
587 Assert.assertTrue(loadedLkg1.equals(lkg1));
591 @Test(dependsOnMethods = {"updateAndGetTest"})
592 public void listTest() {
593 Set<OperationalScope> opScopeChoices = new HashSet<>();
594 opScopeChoices.add(OperationalScope.Network_Wide);
595 LicenseKeyGroupEntity lkg2 =
596 createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal,
597 new MultiChoiceOrOther<>(opScopeChoices, null));
598 lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId();
601 Collection<LicenseKeyGroupEntity> loadedLkgs =
602 vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1);
603 Assert.assertEquals(loadedLkgs.size(), 2);
604 for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) {
605 if (lkg2Id.equals(loadedLkg.getId())) {
606 Assert.assertTrue(loadedLkg.equals(lkg2));
611 @Test(dependsOnMethods = {"listTest"})
612 public void deleteTest() {
614 .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1);
616 LicenseKeyGroupEntity loadedLkg1 =
617 licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id));
618 Assert.assertEquals(loadedLkg1, null);
620 Collection<LicenseKeyGroupEntity> loadedLkgs =
621 licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null));
622 Assert.assertEquals(loadedLkgs.size(), 1);
623 Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id);
626 @Test(dependsOnMethods = "deleteTest")
627 public void testCreateWithRemovedName() {
628 testCreate(vlm1Id, LKG1_NAME);