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);
93 .setEntitlementMetric(new ChoiceOrOther<>(entitlementMetricChoice, entitlementMetricOther));
94 entitlementPool.setIncrements(increments);
95 entitlementPool.setAggregationFunction(
96 new ChoiceOrOther<>(aggregationFunctionChoice, aggregationFunctionOther));
97 entitlementPool.setOperationalScope(
98 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
99 entitlementPool.setTime(new ChoiceOrOther<>(timeChoice, timeOther));
100 entitlementPool.setManufacturerReferenceNumber(sku);
101 return entitlementPool;
105 public void setUp() throws Exception {
106 MockitoAnnotations.initMocks(this);
110 public void createTest() {
111 Set<OperationalScope> opScopeChoices;
112 opScopeChoices = new HashSet<>();
113 opScopeChoices.add(OperationalScope.Core);
114 opScopeChoices.add(OperationalScope.CPU);
115 opScopeChoices.add(OperationalScope.Network_Wide);
116 EntitlementPoolEntity ep2 =
117 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
118 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
119 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
120 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
121 ep2.setStartDate(LocalDate.now().format(formatter));
122 ep2.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
124 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1);
128 public void createWithInvalidStartExpiryDateTest() {
131 Set<OperationalScope> opScopeChoices;
132 opScopeChoices = new HashSet<>();
133 opScopeChoices.add(OperationalScope.Core);
134 opScopeChoices.add(OperationalScope.CPU);
135 opScopeChoices.add(OperationalScope.Network_Wide);
136 EntitlementPoolEntity ep2 =
137 createEntitlementPool("vlm2Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
138 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
139 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
140 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
141 ep2.setStartDate(LocalDate.now().format(formatter));
142 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
143 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
145 } catch (CoreException exception) {
146 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
151 public void createWithoutStartDateTest() {
154 Set<OperationalScope> opScopeChoices;
155 opScopeChoices = new HashSet<>();
156 opScopeChoices.add(OperationalScope.Core);
157 opScopeChoices.add(OperationalScope.CPU);
158 opScopeChoices.add(OperationalScope.Network_Wide);
159 EntitlementPoolEntity ep2 =
160 createEntitlementPool("vlm3Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
161 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
162 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
163 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
164 ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
165 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
167 } catch (CoreException exception) {
168 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
173 public void createWithSameStartExpiryDateTest() {
176 Set<OperationalScope> opScopeChoices;
177 opScopeChoices = new HashSet<>();
178 opScopeChoices.add(OperationalScope.Core);
179 opScopeChoices.add(OperationalScope.CPU);
180 opScopeChoices.add(OperationalScope.Network_Wide);
181 EntitlementPoolEntity ep2 =
182 createEntitlementPool("vlm4Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
183 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
184 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
185 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
186 ep2.setStartDate(LocalDate.now().format(formatter));
187 ep2.setExpiryDate(LocalDate.now().format(formatter));
188 vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId();
190 } catch (CoreException exception) {
191 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
196 public void createUpdate() {
197 Set<OperationalScope> opScopeChoices;
198 opScopeChoices = new HashSet<>();
199 opScopeChoices.add(OperationalScope.Core);
200 opScopeChoices.add(OperationalScope.CPU);
201 opScopeChoices.add(OperationalScope.Network_Wide);
202 EntitlementPoolEntity ep2 =
203 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
204 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
205 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
206 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
207 ep2.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
208 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
209 VersionInfo info = new VersionInfo();
210 Version version = new Version();
211 info.getViewableVersions().add(version);
212 info.setActiveVersion(version);
213 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
215 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
219 public void updateWithInvalidStartExpiryDateTest() {
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 EntitlementPoolEntity ep2 =
228 createEntitlementPool("vlm2Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
229 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
230 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
231 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
232 ep2.setStartDate(LocalDate.now().format(formatter));
233 ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
234 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
236 } catch (CoreException exception) {
237 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
242 public void updateWithoutStartDateTest() {
245 Set<OperationalScope> opScopeChoices;
246 opScopeChoices = new HashSet<>();
247 opScopeChoices.add(OperationalScope.Core);
248 opScopeChoices.add(OperationalScope.CPU);
249 opScopeChoices.add(OperationalScope.Network_Wide);
250 EntitlementPoolEntity ep2 =
251 createEntitlementPool("vlm3Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
252 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
253 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
254 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
255 ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
256 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
258 } catch (CoreException exception) {
259 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
264 public void updateWithSameStartExpiryDateTest() {
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 EntitlementPoolEntity ep2 =
273 createEntitlementPool("vlm4Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
274 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
275 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
276 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
277 ep2.setStartDate(LocalDate.now().format(formatter));
278 ep2.setExpiryDate(LocalDate.now().format(formatter));
279 vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1);
281 } catch (CoreException exception) {
282 Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
287 public void deleteEntitlementPoolTest() {
288 Set<OperationalScope> opScopeChoices;
289 opScopeChoices = new HashSet<>();
290 opScopeChoices.add(OperationalScope.Core);
291 opScopeChoices.add(OperationalScope.CPU);
292 opScopeChoices.add(OperationalScope.Network_Wide);
294 EntitlementPoolEntity entitlementPool =
295 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
296 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
297 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
298 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
299 entitlementPool.setStartDate(LocalDate.now().format(formatter));
300 entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
302 VersionInfo info = new VersionInfo();
303 Version version = new Version();
304 info.getViewableVersions().add(version);
305 info.setActiveVersion(version);
306 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
308 LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
309 EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour);
311 ArrayList<LimitEntity> limitEntityList = new ArrayList();
312 limitEntityList.add(limitEntity);
314 doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
315 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
316 doReturn(true).when(limitDao).isLimitPresent(anyObject());
317 doReturn(limitEntity).when(limitDao).get(anyObject());
319 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
320 limitField.setAccessible(true);
321 Field modifiersField = Field.class.getDeclaredField("modifiers");
322 modifiersField.setAccessible(true);
323 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
324 limitField.set(null, limitDao);
326 Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
327 epField.setAccessible(true);
328 modifiersField = Field.class.getDeclaredField("modifiers");
329 modifiersField.setAccessible(true);
330 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
331 epField.set(null, entitlementPoolDao);
332 } catch(NoSuchFieldException | IllegalAccessException e)
337 vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);
339 verify(limitDao).delete(anyObject());
343 public void deleteEntitlementPoolInvalidTest() {
345 Set<OperationalScope> opScopeChoices;
346 opScopeChoices = new HashSet<>();
347 opScopeChoices.add(OperationalScope.Core);
348 opScopeChoices.add(OperationalScope.CPU);
349 opScopeChoices.add(OperationalScope.Network_Wide);
351 EntitlementPoolEntity entitlementPool =
352 createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
353 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
354 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
355 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
356 entitlementPool.setStartDate(LocalDate.now().format(formatter));
357 entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));
359 VersionInfo info = new VersionInfo();
360 Version version = new Version();
361 info.getViewableVersions().add(version);
362 info.setActiveVersion(version);
363 doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());
365 LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
366 EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour);
368 ArrayList<LimitEntity> limitEntityList = new ArrayList();
369 limitEntityList.add(limitEntity);
371 doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
372 doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
373 doReturn(false).when(limitDao).isLimitPresent(anyObject());
376 Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
377 limitField.setAccessible(true);
378 Field modifiersField = Field.class.getDeclaredField("modifiers");
379 modifiersField.setAccessible(true);
380 modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
381 limitField.set(null, limitDao);
383 Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
384 epField.setAccessible(true);
385 modifiersField = Field.class.getDeclaredField("modifiers");
386 modifiersField.setAccessible(true);
387 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
388 epField.set(null, entitlementPoolDao);
389 } catch(NoSuchFieldException | IllegalAccessException e)
394 vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);
395 } catch (CoreException exception) {
396 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
400 /* private static final String USER1 = "epTestUser1";
401 private static final String USER2 = "epTestUser2";
402 private static final String EP1_V01_DESC = "EP1 desc";
403 private static final Version VERSION01 = new Version(0, 1);
404 private static final Version VERSION03 = new Version(0, 3);
405 private static final String EP1_NAME = "EP1 name";
406 private static final String EP2_NAME = "EP2 name";
408 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
409 private static EntitlementPoolDao entitlementPoolDao;
411 private static String vlm1Id;
412 private static String vlm2Id;
413 private static String ep1Id;
414 private static String ep2Id;
416 public static EntitlementPoolEntity createEntitlementPool(String vlmId, Version version,
417 String name, String desc, int threshold,
418 ThresholdUnit thresholdUnit,
419 EntitlementMetric entitlementMetricChoice,
420 String entitlementMetricOther,
422 AggregationFunction aggregationFunctionChoice,
423 String aggregationFunctionOther,
424 Set<OperationalScope> operationalScopeChoices,
425 String operationalScopeOther,
426 EntitlementTime timeChoice,
427 String timeOther, String sku) {
428 EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity();
429 entitlementPool.setVendorLicenseModelId(vlmId);
430 entitlementPool.setVersion(version);
431 entitlementPool.setName(name);
432 entitlementPool.setDescription(desc);
433 entitlementPool.setThresholdValue(threshold);
434 entitlementPool.setThresholdUnit(thresholdUnit);
436 .setEntitlementMetric(new ChoiceOrOther<>(entitlementMetricChoice, entitlementMetricOther));
437 entitlementPool.setIncrements(increments);
438 entitlementPool.setAggregationFunction(
439 new ChoiceOrOther<>(aggregationFunctionChoice, aggregationFunctionOther));
440 entitlementPool.setOperationalScope(
441 new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
442 entitlementPool.setTime(new ChoiceOrOther<>(timeChoice, timeOther));
443 return entitlementPool;
446 private static void assertEntitlementPoolsEquals(EntitlementPoolEntity actual,
447 EntitlementPoolEntity expected) {
448 Assert.assertEquals(actual.getVendorLicenseModelId(), expected.getVendorLicenseModelId());
449 Assert.assertEquals(actual.getVersion(), expected.getVersion());
450 Assert.assertEquals(actual.getId(), expected.getId());
451 Assert.assertEquals(actual.getName(), expected.getName());
452 Assert.assertEquals(actual.getDescription(), expected.getDescription());
453 Assert.assertEquals(actual.getThresholdValue(), expected.getThresholdValue());
454 Assert.assertEquals(actual.getThresholdUnit(), expected.getThresholdUnit());
455 Assert.assertEquals(actual.getEntitlementMetric(), expected.getEntitlementMetric());
456 Assert.assertEquals(actual.getIncrements(), expected.getIncrements());
457 Assert.assertEquals(actual.getAggregationFunction(), expected.getAggregationFunction());
458 Assert.assertEquals(actual.getOperationalScope(), expected.getOperationalScope());
459 Assert.assertEquals(actual.getTime(), expected.getTime());
463 private void init() {
464 entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
465 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
466 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1 dec", "icon1"),
468 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
469 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
474 public void emptyListTest() {
475 Collection<EntitlementPoolEntity> entitlementPools =
476 vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
477 Assert.assertEquals(entitlementPools.size(), 0);
480 @Test(dependsOnMethods = "emptyListTest")
481 public void createTest() {
482 ep1Id = testCreate(vlm1Id, EP1_NAME);
484 Set<OperationalScope> opScopeChoices;
485 opScopeChoices = new HashSet<>();
486 opScopeChoices.add(OperationalScope.Core);
487 opScopeChoices.add(OperationalScope.CPU);
488 opScopeChoices.add(OperationalScope.Network_Wide);
489 EntitlementPoolEntity ep2 =
490 createEntitlementPool(vlm1Id, null, EP2_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
491 EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
492 opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
493 ep2Id = vendorLicenseManager.createEntitlementPool(ep2, USER1).getId();
497 private String testCreate(String vlmId, String name) {
498 Set<OperationalScope> opScopeChoices = new HashSet<>();
499 opScopeChoices.add(OperationalScope.Other);
500 EntitlementPoolEntity ep1 =
501 createEntitlementPool(vlmId, null, name, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
502 EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
503 opScopeChoices, "op scope1", EntitlementTime.Other, "time1", "sku1");
504 String ep1Id = vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
507 EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(ep1);
508 Assert.assertTrue(loadedEp1.equals(ep1));
512 @Test(dependsOnMethods = {"createTest"})
513 public void testCreateWithExistingName_negative() {
514 testCreateWithExistingName_negative(vlm1Id, EP1_NAME);
517 @Test(dependsOnMethods = {"createTest"})
518 public void testCreateWithExistingNameUnderOtherVlm() {
519 testCreate(vlm2Id, EP1_NAME);
522 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
523 public void updateAndGetTest() {
524 EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, VERSION01, ep1Id);
526 EntitlementPoolEntity ep1 = entitlementPoolDao.get(emptyEp1);
527 ep1.setEntitlementMetric(new ChoiceOrOther<>(EntitlementMetric.Other, "exception metric1 updated"));
528 ep1.setAggregationFunction(new ChoiceOrOther<>(AggregationFunction.Other, "agg func1 updated"));
530 vendorLicenseManager.updateEntitlementPool(ep1, USER1);
532 EntitlementPoolEntity loadedEp1 = vendorLicenseManager.getEntitlementPool(emptyEp1, USER1);
533 assertEntitlementPoolsEquals(loadedEp1, ep1);
536 @Test(dependsOnMethods = {"updateAndGetTest"})
537 public void testGetNonExistingVersion_negative() {
540 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(48, 83), ep1Id), USER1);
541 Assert.assertTrue(false);
542 } catch (CoreException exception) {
543 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
547 @Test(dependsOnMethods = {"updateAndGetTest"})
548 public void testGetOtherUserCandidateVersion_negative() {
549 vendorLicenseManager.checkin(vlm1Id, USER1);
550 vendorLicenseManager.checkout(vlm1Id, USER2);
553 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id), USER1);
554 Assert.assertTrue(false);
555 } catch (CoreException exception) {
556 Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
560 @Test(dependsOnMethods = {"testGetOtherUserCandidateVersion_negative"})
561 public void testGetCandidateVersion() {
562 EntitlementPoolEntity ep = new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id);
563 ep.setDescription("updated!");
564 vendorLicenseManager.updateEntitlementPool(ep, USER2);
566 EntitlementPoolEntity actualEp = vendorLicenseManager.getEntitlementPool(ep, USER2);
567 EntitlementPoolEntity expectedEp = entitlementPoolDao.get(ep);
569 Assert.assertEquals(actualEp.getDescription(), ep.getDescription());
570 assertEntitlementPoolsEquals(actualEp, expectedEp);
573 @Test(dependsOnMethods = {"testGetCandidateVersion"})
574 public void testGetOldVersion() {
575 vendorLicenseManager.checkin(vlm1Id, USER2);
576 EntitlementPoolEntity actualEp = vendorLicenseManager
577 .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 1), ep1Id), USER2);
578 Assert.assertEquals(actualEp.getDescription(), EP1_V01_DESC);
581 @Test(dependsOnMethods = {"testGetOldVersion"})
582 public void listTest() {
583 Collection<EntitlementPoolEntity> loadedEps =
584 vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
585 Assert.assertEquals(loadedEps.size(), 2);
587 int existingCounter = 0;
588 for (EntitlementPoolEntity loadedEp : loadedEps) {
589 if (ep2Id.equals(loadedEp.getId()) || ep1Id.equals(loadedEp.getId())) {
594 Assert.assertEquals(existingCounter, 2);
597 @Test(dependsOnMethods = {"listTest"})
598 public void deleteTest() {
599 vendorLicenseManager.checkout(vlm1Id, USER1);
600 EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, null, ep1Id);
601 vendorLicenseManager.deleteEntitlementPool(emptyEp1, USER1);
603 emptyEp1.setVersion(VERSION03);
604 EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(emptyEp1);
605 Assert.assertEquals(loadedEp1, null);
607 Collection<EntitlementPoolEntity> loadedEps =
608 entitlementPoolDao.list(new EntitlementPoolEntity(vlm1Id, VERSION03, null));
609 Assert.assertEquals(loadedEps.size(), 1);
610 Assert.assertEquals(loadedEps.iterator().next().getId(), ep2Id);
613 @Test(dependsOnMethods = "deleteTest")
614 public void listOldVersionTest() {
615 Collection<EntitlementPoolEntity> loadedEps =
616 vendorLicenseManager.listEntitlementPools(vlm1Id, VERSION01, USER1);
617 Assert.assertEquals(loadedEps.size(), 2);
620 @Test(dependsOnMethods = "deleteTest")
621 public void testCreateWithRemovedName() {
622 testCreate(vlm1Id, EP1_NAME);
625 @Test(dependsOnMethods = "deleteTest")
626 public void testCreateWithExistingNameAfterCheckout_negative() {
627 testCreateWithExistingName_negative(vlm1Id, EP2_NAME);
630 private void testCreateWithExistingName_negative(String vlmId, String epName) {
632 EntitlementPoolEntity ep1 =
633 createEntitlementPool(vlmId, null, epName, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
634 EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
635 Collections.singleton(OperationalScope.Other), "op scope1", EntitlementTime.Other,
637 vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
639 } catch (CoreException exception) {
640 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);