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;
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.EntitlementPoolDao;
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.vendorlicense.impl.VendorLicenseManagerImpl;
35 import org.openecomp.sdc.versioning.dao.types.Version;
36 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
37 import org.openecomp.sdc.versioning.types.VersionInfo;
38 import org.testng.Assert;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.Modifier;
44 import java.time.LocalDate;
45 import java.time.format.DateTimeFormatter;
46 import java.util.ArrayList;
47 import java.util.HashSet;
50 import static org.mockito.Matchers.anyObject;
51 import static org.mockito.Mockito.doReturn;
52 import static org.mockito.Mockito.verify;
54 public class EntitlementPoolTest {
56 //JUnit Test Cases using Mockito
57 private final String USER1 = "epTestUser1";
58 private final String EP1_NAME = "EP1 name";
59 private final String LT1_NAME = "LT1 name";
62 private VendorLicenseFacade vendorLicenseFacade;
65 private EntitlementPoolDao entitlementPoolDao;
67 private LimitDao limitDao;
71 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
73 public EntitlementPoolEntity createEntitlementPool(String vlmId, Version version,
74 String name, String desc, int threshold,
75 ThresholdUnit thresholdUnit,
76 EntitlementMetric entitlementMetricChoice,
77 String entitlementMetricOther,
79 AggregationFunction aggregationFunctionChoice,
80 String aggregationFunctionOther,
81 Set<OperationalScope> operationalScopeChoices,
82 String operationalScopeOther,
83 EntitlementTime timeChoice,
84 String timeOther, String sku) {
85 EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity();
86 //entitlementPool.setVendorLicenseModelId(vlmId);
87 entitlementPool.setVersion(version);
88 entitlementPool.setName(name);
89 entitlementPool.setDescription(desc);
90 entitlementPool.setThresholdValue(threshold);
91 entitlementPool.setThresholdUnit(thresholdUnit);
92 entitlementPool.setIncrements(increments);
93 entitlementPool.setOperationalScope(
94 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
95 return entitlementPool;
99 public void setUp() throws Exception {
100 MockitoAnnotations.initMocks(this);
104 public void createTest() {
105 Set<OperationalScope> opScopeChoices;
106 opScopeChoices = new HashSet<>();
107 opScopeChoices.add(OperationalScope.Core);
108 opScopeChoices.add(OperationalScope.CPU);
109 opScopeChoices.add(OperationalScope.Network_Wide);
110 EntitlementPoolEntity ep2 =
111 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
112 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
113 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
114 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
115 ep2.setStartDate(LocalDate.now().format(formatter));
116 ep2.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
118 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1);
122 public void createWithInvalidStartExpiryDateTest() {
125 Set<OperationalScope> opScopeChoices;
126 opScopeChoices = new HashSet<>();
127 opScopeChoices.add(OperationalScope.Core);
128 opScopeChoices.add(OperationalScope.CPU);
129 opScopeChoices.add(OperationalScope.Network_Wide);
130 EntitlementPoolEntity ep2 =
131 createEntitlementPool("vlm2Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
132 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
133 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
134 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
135 ep2.setStartDate(LocalDate.now().format(formatter));
136 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
137 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
139 } catch (CoreException exception) {
140 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
145 public void createWithoutStartDateTest() {
148 Set<OperationalScope> opScopeChoices;
149 opScopeChoices = new HashSet<>();
150 opScopeChoices.add(OperationalScope.Core);
151 opScopeChoices.add(OperationalScope.CPU);
152 opScopeChoices.add(OperationalScope.Network_Wide);
153 EntitlementPoolEntity ep2 =
154 createEntitlementPool("vlm3Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
155 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
156 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
157 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
158 ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
159 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
161 } catch (CoreException exception) {
162 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
167 public void createWithSameStartExpiryDateTest() {
170 Set<OperationalScope> opScopeChoices;
171 opScopeChoices = new HashSet<>();
172 opScopeChoices.add(OperationalScope.Core);
173 opScopeChoices.add(OperationalScope.CPU);
174 opScopeChoices.add(OperationalScope.Network_Wide);
175 EntitlementPoolEntity ep2 =
176 createEntitlementPool("vlm4Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
177 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
178 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
179 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
180 ep2.setStartDate(LocalDate.now().format(formatter));
181 ep2.setExpiryDate(LocalDate.now().format(formatter));
182 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
184 } catch (CoreException exception) {
185 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
190 public void createUpdate() {
191 Set<OperationalScope> opScopeChoices;
192 opScopeChoices = new HashSet<>();
193 opScopeChoices.add(OperationalScope.Core);
194 opScopeChoices.add(OperationalScope.CPU);
195 opScopeChoices.add(OperationalScope.Network_Wide);
196 EntitlementPoolEntity ep2 =
197 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
198 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
199 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
200 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
201 ep2.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
202 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
203 VersionInfo info = new VersionInfo();
204 Version version = new Version();
205 info.getViewableVersions().add(version);
206 info.setActiveVersion(version);
207 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
209 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
213 public void updateWithInvalidStartExpiryDateTest() {
216 Set<OperationalScope> opScopeChoices;
217 opScopeChoices = new HashSet<>();
218 opScopeChoices.add(OperationalScope.Core);
219 opScopeChoices.add(OperationalScope.CPU);
220 opScopeChoices.add(OperationalScope.Network_Wide);
221 EntitlementPoolEntity ep2 =
222 createEntitlementPool("vlm2Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
223 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
224 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
225 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
226 ep2.setStartDate(LocalDate.now().format(formatter));
227 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
228 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
230 } catch (CoreException exception) {
231 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
236 public void updateWithoutStartDateTest() {
239 Set<OperationalScope> opScopeChoices;
240 opScopeChoices = new HashSet<>();
241 opScopeChoices.add(OperationalScope.Core);
242 opScopeChoices.add(OperationalScope.CPU);
243 opScopeChoices.add(OperationalScope.Network_Wide);
244 EntitlementPoolEntity ep2 =
245 createEntitlementPool("vlm3Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
246 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
247 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
248 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
249 ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
250 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
252 } catch (CoreException exception) {
253 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
258 public void updateWithSameStartExpiryDateTest() {
261 Set<OperationalScope> opScopeChoices;
262 opScopeChoices = new HashSet<>();
263 opScopeChoices.add(OperationalScope.Core);
264 opScopeChoices.add(OperationalScope.CPU);
265 opScopeChoices.add(OperationalScope.Network_Wide);
266 EntitlementPoolEntity ep2 =
267 createEntitlementPool("vlm4Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
268 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
269 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
270 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
271 ep2.setStartDate(LocalDate.now().format(formatter));
272 ep2.setExpiryDate(LocalDate.now().format(formatter));
273 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
275 } catch (CoreException exception) {
276 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
281 public void deleteEntitlementPoolTest() {
282 Set<OperationalScope> opScopeChoices;
283 opScopeChoices = new HashSet<>();
284 opScopeChoices.add(OperationalScope.Core);
285 opScopeChoices.add(OperationalScope.CPU);
286 opScopeChoices.add(OperationalScope.Network_Wide);
288 EntitlementPoolEntity entitlementPool =
289 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
290 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
291 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
292 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
293 entitlementPool.setStartDate(LocalDate.now().format(formatter));
294 entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
296 VersionInfo info = new VersionInfo();
297 Version version = new Version();
298 info.getViewableVersions().add(version);
299 info.setActiveVersion(version);
300 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
302 LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
303 EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour);
305 ArrayList<LimitEntity> limitEntityList = new ArrayList();
306 limitEntityList.add(limitEntity);
308 doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
309 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
310 doReturn(true).when(limitDao).isLimitPresent(anyObject());
311 doReturn(limitEntity).when(limitDao).get(anyObject());
313 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
314 limitField.setAccessible(true);
315 Field modifiersField = Field.class.getDeclaredField("modifiers");
316 modifiersField.setAccessible(true);
317 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
318 limitField.set(null, limitDao);
320 Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
321 epField.setAccessible(true);
322 modifiersField = Field.class.getDeclaredField("modifiers");
323 modifiersField.setAccessible(true);
324 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
325 epField.set(null, entitlementPoolDao);
326 } catch(NoSuchFieldException | IllegalAccessException e)
331 vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);
333 verify(limitDao).delete(anyObject());
337 public void deleteEntitlementPoolInvalidTest() {
339 Set<OperationalScope> opScopeChoices;
340 opScopeChoices = new HashSet<>();
341 opScopeChoices.add(OperationalScope.Core);
342 opScopeChoices.add(OperationalScope.CPU);
343 opScopeChoices.add(OperationalScope.Network_Wide);
345 EntitlementPoolEntity entitlementPool =
346 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
347 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
348 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
349 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
350 entitlementPool.setStartDate(LocalDate.now().format(formatter));
351 entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
353 VersionInfo info = new VersionInfo();
354 Version version = new Version();
355 info.getViewableVersions().add(version);
356 info.setActiveVersion(version);
357 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
359 LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
360 EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour);
362 ArrayList<LimitEntity> limitEntityList = new ArrayList();
363 limitEntityList.add(limitEntity);
365 doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
366 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
367 doReturn(false).when(limitDao).isLimitPresent(anyObject());
370 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
371 limitField.setAccessible(true);
372 Field modifiersField = Field.class.getDeclaredField("modifiers");
373 modifiersField.setAccessible(true);
374 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
375 limitField.set(null, limitDao);
377 Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
378 epField.setAccessible(true);
379 modifiersField = Field.class.getDeclaredField("modifiers");
380 modifiersField.setAccessible(true);
381 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
382 epField.set(null, entitlementPoolDao);
383 } catch(NoSuchFieldException | IllegalAccessException e)
388 vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);
389 } catch (CoreException exception) {
390 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
394 /* private static final String USER1 = "epTestUser1";
395 private static final String USER2 = "epTestUser2";
396 private static final String EP1_V01_DESC = "EP1 desc";
397 private static final Version VERSION01 = new Version(0, 1);
398 private static final Version VERSION03 = new Version(0, 3);
399 private static final String EP1_NAME = "EP1 name";
400 private static final String EP2_NAME = "EP2 name";
402 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
403 private static EntitlementPoolDao entitlementPoolDao;
405 private static String vlm1Id;
406 private static String vlm2Id;
407 private static String ep1Id;
408 private static String ep2Id;
410 public static EntitlementPoolEntity createEntitlementPool(String vlmId, Version version,
411 String name, String desc, int threshold,
412 ThresholdUnit thresholdUnit,
413 EntitlementMetric entitlementMetricChoice,
414 String entitlementMetricOther,
416 AggregationFunction aggregationFunctionChoice,
417 String aggregationFunctionOther,
418 Set<OperationalScope> operationalScopeChoices,
419 String operationalScopeOther,
420 EntitlementTime timeChoice,
421 String timeOther, String sku) {
422 EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity();
423 entitlementPool.setVendorLicenseModelId(vlmId);
424 entitlementPool.setVersion(version);
425 entitlementPool.setName(name);
426 entitlementPool.setDescription(desc);
427 entitlementPool.setThresholdValue(threshold);
428 entitlementPool.setThresholdUnit(thresholdUnit);
430 .setEntitlementMetric(new ChoiceOrOther<>(entitlementMetricChoice, entitlementMetricOther));
431 entitlementPool.setIncrements(increments);
432 entitlementPool.setAggregationFunction(
433 new ChoiceOrOther<>(aggregationFunctionChoice, aggregationFunctionOther));
434 entitlementPool.setOperationalScope(
435 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
436 entitlementPool.setTime(new ChoiceOrOther<>(timeChoice, timeOther));
437 return entitlementPool;
440 private static void assertEntitlementPoolsEquals(EntitlementPoolEntity actual,
441 EntitlementPoolEntity expected) {
442 Assert.assertEquals(actual.getVendorLicenseModelId(), expected.getVendorLicenseModelId());
443 Assert.assertEquals(actual.getVersion(), expected.getVersion());
444 Assert.assertEquals(actual.getId(), expected.getId());
445 Assert.assertEquals(actual.getName(), expected.getName());
446 Assert.assertEquals(actual.getDescription(), expected.getDescription());
447 Assert.assertEquals(actual.getThresholdValue(), expected.getThresholdValue());
448 Assert.assertEquals(actual.getThresholdUnit(), expected.getThresholdUnit());
449 Assert.assertEquals(actual.getEntitlementMetric(), expected.getEntitlementMetric());
450 Assert.assertEquals(actual.getIncrements(), expected.getIncrements());
451 Assert.assertEquals(actual.getAggregationFunction(), expected.getAggregationFunction());
452 Assert.assertEquals(actual.getOperationalScope(), expected.getOperationalScope());
453 Assert.assertEquals(actual.getTime(), expected.getTime());
457 private void init() {
458 entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
459 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
460 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1 dec", "icon1"),
462 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
463 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
468 public void emptyListTest() {
469 Collection<EntitlementPoolEntity> entitlementPools =
470 vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
471 Assert.assertEquals(entitlementPools.size(), 0);
474 @Test(dependsOnMethods = "emptyListTest")
475 public void createTest() {
476 ep1Id = testCreate(vlm1Id, EP1_NAME);
478 Set<OperationalScope> opScopeChoices;
479 opScopeChoices = new HashSet<>();
480 opScopeChoices.add(OperationalScope.Core);
481 opScopeChoices.add(OperationalScope.CPU);
482 opScopeChoices.add(OperationalScope.Network_Wide);
483 EntitlementPoolEntity ep2 =
484 createEntitlementPool(vlm1Id, null, EP2_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
485 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
486 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
487 ep2Id = vendorLicenseManager.createEntitlementPool(ep2, USER1).getId();
491 private String testCreate(String vlmId, String name) {
492 Set<OperationalScope> opScopeChoices = new HashSet<>();
493 opScopeChoices.add(OperationalScope.Other);
494 EntitlementPoolEntity ep1 =
495 createEntitlementPool(vlmId, null, name, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
496 EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
497 opScopeChoices, "op scope1", EntitlementTime.Other, "time1", "sku1");
498 String ep1Id = vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
501 EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(ep1);
502 Assert.assertTrue(loadedEp1.equals(ep1));
506 @Test(dependsOnMethods = {"createTest"})
507 public void testCreateWithExistingName_negative() {
508 testCreateWithExistingName_negative(vlm1Id, EP1_NAME);
511 @Test(dependsOnMethods = {"createTest"})
512 public void testCreateWithExistingNameUnderOtherVlm() {
513 testCreate(vlm2Id, EP1_NAME);
516 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
517 public void updateAndGetTest() {
518 EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, VERSION01, ep1Id);
520 EntitlementPoolEntity ep1 = entitlementPoolDao.get(emptyEp1);
521 ep1.setEntitlementMetric(new ChoiceOrOther<>(EntitlementMetric.Other, "exception metric1 updated"));
522 ep1.setAggregationFunction(new ChoiceOrOther<>(AggregationFunction.Other, "agg func1 updated"));
524 vendorLicenseManager.updateEntitlementPool(ep1, USER1);
526 EntitlementPoolEntity loadedEp1 = vendorLicenseManager.getEntitlementPool(emptyEp1, USER1);
527 assertEntitlementPoolsEquals(loadedEp1, ep1);
530 @Test(dependsOnMethods = {"updateAndGetTest"})
531 public void testGetNonExistingVersion_negative() {
534 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(48, 83), ep1Id), USER1);
535 Assert.assertTrue(false);
536 } catch (CoreException exception) {
537 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
541 @Test(dependsOnMethods = {"updateAndGetTest"})
542 public void testGetOtherUserCandidateVersion_negative() {
543 vendorLicenseManager.checkin(vlm1Id, USER1);
544 vendorLicenseManager.checkout(vlm1Id, USER2);
547 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id), USER1);
548 Assert.assertTrue(false);
549 } catch (CoreException exception) {
550 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
554 @Test(dependsOnMethods = {"testGetOtherUserCandidateVersion_negative"})
555 public void testGetCandidateVersion() {
556 EntitlementPoolEntity ep = new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id);
557 ep.setDescription("updated!");
558 vendorLicenseManager.updateEntitlementPool(ep, USER2);
560 EntitlementPoolEntity actualEp = vendorLicenseManager.getEntitlementPool(ep, USER2);
561 EntitlementPoolEntity expectedEp = entitlementPoolDao.get(ep);
563 Assert.assertEquals(actualEp.getDescription(), ep.getDescription());
564 assertEntitlementPoolsEquals(actualEp, expectedEp);
567 @Test(dependsOnMethods = {"testGetCandidateVersion"})
568 public void testGetOldVersion() {
569 vendorLicenseManager.checkin(vlm1Id, USER2);
570 EntitlementPoolEntity actualEp = vendorLicenseManager
571 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 1), ep1Id), USER2);
572 Assert.assertEquals(actualEp.getDescription(), EP1_V01_DESC);
575 @Test(dependsOnMethods = {"testGetOldVersion"})
576 public void listTest() {
577 Collection<EntitlementPoolEntity> loadedEps =
578 vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
579 Assert.assertEquals(loadedEps.size(), 2);
581 int existingCounter = 0;
582 for (EntitlementPoolEntity loadedEp : loadedEps) {
583 if (ep2Id.equals(loadedEp.getId()) || ep1Id.equals(loadedEp.getId())) {
588 Assert.assertEquals(existingCounter, 2);
591 @Test(dependsOnMethods = {"listTest"})
592 public void deleteTest() {
593 vendorLicenseManager.checkout(vlm1Id, USER1);
594 EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, null, ep1Id);
595 vendorLicenseManager.deleteEntitlementPool(emptyEp1, USER1);
597 emptyEp1.setVersion(VERSION03);
598 EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(emptyEp1);
599 Assert.assertEquals(loadedEp1, null);
601 Collection<EntitlementPoolEntity> loadedEps =
602 entitlementPoolDao.list(new EntitlementPoolEntity(vlm1Id, VERSION03, null));
603 Assert.assertEquals(loadedEps.size(), 1);
604 Assert.assertEquals(loadedEps.iterator().next().getId(), ep2Id);
607 @Test(dependsOnMethods = "deleteTest")
608 public void listOldVersionTest() {
609 Collection<EntitlementPoolEntity> loadedEps =
610 vendorLicenseManager.listEntitlementPools(vlm1Id, VERSION01, USER1);
611 Assert.assertEquals(loadedEps.size(), 2);
614 @Test(dependsOnMethods = "deleteTest")
615 public void testCreateWithRemovedName() {
616 testCreate(vlm1Id, EP1_NAME);
619 @Test(dependsOnMethods = "deleteTest")
620 public void testCreateWithExistingNameAfterCheckout_negative() {
621 testCreateWithExistingName_negative(vlm1Id, EP2_NAME);
624 private void testCreateWithExistingName_negative(String vlmId, String epName) {
626 EntitlementPoolEntity ep1 =
627 createEntitlementPool(vlmId, null, epName, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
628 EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
629 Collections.singleton(OperationalScope.Other), "op scope1", EntitlementTime.Other,
631 vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
633 } catch (CoreException exception) {
634 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);