aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java
blob: 38f0ebff86d7a040504c63cde5930e4dc17d907c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/*
 * Copyright © 2016-2018 European Support Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.openecomp.sdc.vendorlicense.impl;

import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
import org.openecomp.sdc.vendorlicense.dao.LimitDao;
import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime;
import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class EntitlementPoolTest {

  //JUnit Test Cases using Mockito
  private final String USER1 = "epTestUser1";
  private final String EP1_NAME = "EP1 name";
  private final String EP2_NAME = "EP2 name";
  private final String LT1_NAME = "LT1 name";
  private static String vlm1_id = "vlm1_id";
  private static String ep1_id = "ep1_id";
  private static String ep2_id = "ep2_id";
  public static final Version VERSION01 = new Version(0, 1);

  @Mock
  private VendorLicenseFacade vendorLicenseFacade;

  @Mock
  private EntitlementPoolDao entitlementPoolDao;
  @Mock
  private LimitDao limitDao;

  @InjectMocks
  @Spy
  private VendorLicenseManagerImpl vendorLicenseManagerImpl;

  public EntitlementPoolEntity createEntitlementPool(String vlmId, Version version, String id,
                                                     String name, String desc, int threshold,
                                                     ThresholdUnit thresholdUnit,
                                                     EntitlementMetric entitlementMetricChoice,
                                                     String entitlementMetricOther,
                                                     String increments,
                                                     AggregationFunction aggregationFunctionChoice,
                                                     String aggregationFunctionOther,
                                                     Set<OperationalScope> operationalScopeChoices,
                                                     String operationalScopeOther,
                                                     EntitlementTime timeChoice,
                                                     String timeOther, String sku) {
    EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity();
    entitlementPool.setVendorLicenseModelId(vlmId);
    entitlementPool.setId(id);
    entitlementPool.setVersion(version);
    entitlementPool.setName(name);
    entitlementPool.setDescription(desc);
    entitlementPool.setThresholdValue(threshold);
    entitlementPool.setThresholdUnit(thresholdUnit);
    entitlementPool.setIncrements(increments);
    entitlementPool.setOperationalScope(
        new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
    return entitlementPool;
  }

  @BeforeMethod
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
  }


  @AfterMethod
  public void tearDown(){
    vendorLicenseManagerImpl = null;
  }

  @Test
  public void createTest() {
    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool("vlm1Id", null, ep1_id, EP1_NAME, "EP2 dec", 70, ThresholdUnit
                .Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setStartDate(LocalDate.now().format(formatter));
    ep2.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));

    vendorLicenseManagerImpl.createEntitlementPool(ep2);
    verify(vendorLicenseFacade).createEntitlementPool(ep2);

  }


  @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " +
      "license model with id vlm1_id has invalid date range.")
  public void createWithInvalidStartExpiryDateTest() {

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool("vlm2Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setStartDate(LocalDate.now().format(formatter));
    ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
    ep2.setVendorLicenseModelId(vlm1_id);
    vendorLicenseManagerImpl.createEntitlementPool(ep2).getId();
    Assert.fail();

  }

  @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " +
      "license model with id vlm1_id has invalid date range.")
  public void createWithoutStartDateTest() {

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool("vlm3Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
    ep2.setVendorLicenseModelId(vlm1_id);
    vendorLicenseManagerImpl.createEntitlementPool(ep2).getId();
    Assert.fail();

  }

  @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " +
      "license model with id vlm1_id has invalid date range.")
  public void createWithSameStartExpiryDateTest() {

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool("vlm4Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setStartDate(LocalDate.now().format(formatter));
    ep2.setExpiryDate(LocalDate.now().format(formatter));
    ep2.setVendorLicenseModelId(vlm1_id);
    vendorLicenseManagerImpl.createEntitlementPool(ep2).getId();
    Assert.fail();
  }

  @Test
  public void testUpdate() {
    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool(vlm1_id, VERSION01, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit
                .Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setStartDate(LocalDate.now().minusDays(3L).format(formatter));
    ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));

    vendorLicenseManagerImpl.updateEntitlementPool(ep2);
  }

  @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " +
      "license model with id vlm1_id has invalid date range.")
  public void updateWithInvalidStartExpiryDateTest() {

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool("vlm2Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    ep2.setStartDate(LocalDate.now().format(formatter));
    ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter));
    ep2.setVendorLicenseModelId(vlm1_id);
    vendorLicenseManagerImpl.updateEntitlementPool(ep2);
    Assert.fail();

  }

  @Test
  public void updateWithoutStartDateTest() {
    try {

      Set<OperationalScope> opScopeChoices;
      opScopeChoices = new HashSet<>();
      opScopeChoices.add(OperationalScope.Core);
      opScopeChoices.add(OperationalScope.CPU);
      opScopeChoices.add(OperationalScope.Network_Wide);
      EntitlementPoolEntity ep2 =
          createEntitlementPool("vlm3Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
              ThresholdUnit.Absolute,
              EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average,
              null,
              opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
      ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter));
      vendorLicenseManagerImpl.updateEntitlementPool(ep2);
      Assert.fail();
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
    }
  }

  @Test
  public void updateWithSameStartExpiryDateTest() {
    try {

      Set<OperationalScope> opScopeChoices;
      opScopeChoices = new HashSet<>();
      opScopeChoices.add(OperationalScope.Core);
      opScopeChoices.add(OperationalScope.CPU);
      opScopeChoices.add(OperationalScope.Network_Wide);
      EntitlementPoolEntity ep2 =
          createEntitlementPool("vlm4Id", null, ep1_id, EP1_NAME, "EP2 dec", 70,
              ThresholdUnit.Absolute,
              EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average,
              null,
              opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
      ep2.setStartDate(LocalDate.now().format(formatter));
      ep2.setExpiryDate(LocalDate.now().format(formatter));
      vendorLicenseManagerImpl.updateEntitlementPool(ep2);
      Assert.fail();
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID);
    }
  }

  @Test
  public void deleteEntitlementPoolTest() {
    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);

    EntitlementPoolEntity entitlementPool =
        createEntitlementPool(vlm1_id, VERSION01, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2", "inc2",
            AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    entitlementPool.setStartDate(LocalDate.now().format(formatter));
    entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));

    doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());

    doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id, VERSION01, ep1_id);

    doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(), anyObject(),
        anyObject(), anyObject());

    vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool);

    verify(entitlementPoolDao).delete(entitlementPool);
  }

  @Test
  public void testGetEntitlementPool() {
    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);

    EntitlementPoolEntity entitlementPool =
        createEntitlementPool(vlm1_id, VERSION01, ep1_id, EP1_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2", "inc2",
            AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");

    entitlementPool.setStartDate(LocalDateTime.now().format(formatter));
    entitlementPool.setExpiryDate(LocalDateTime.now().plusDays(1L).format(formatter));

    doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());

    EntitlementPoolEntity retrived = vendorLicenseManagerImpl.getEntitlementPool(entitlementPool);

    Assert.assertEquals(retrived.getId(), entitlementPool.getId());
    Assert.assertEquals(retrived.getVendorLicenseModelId(),
        entitlementPool.getVendorLicenseModelId());
    Assert.assertEquals(retrived.getVersion(), entitlementPool.getVersion());
  }

  @Test
  public void testListEntitlmentPool() {

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);

    doReturn(Arrays.asList(
        createEntitlementPool(vlm1_id, VERSION01, ep1_id, EP1_NAME, "EP1 dec", 70,
            ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric1",
            "inc1", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time1", "sku1"),
        createEntitlementPool(vlm1_id, VERSION01, ep2_id, EP2_NAME, "EP2 dec", 70,
            ThresholdUnit.Absolute, EntitlementMetric.Other, "exception metric2",
            "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2")))
        .when(vendorLicenseFacade).listEntitlementPools(vlm1_id, VERSION01);

    Collection<EntitlementPoolEntity> EPs =
        vendorLicenseManagerImpl.listEntitlementPools(vlm1_id, VERSION01);

    verify(vendorLicenseFacade).listEntitlementPools(vlm1_id, VERSION01);
    Assert.assertEquals(EPs.size(), 2);
    EPs.forEach(ep -> Assert.assertTrue(ep.getId().matches(ep1_id + "|" + ep2_id)));
  }


  /*  @Test
    public void deleteEntitlementPoolTest() {
        Set<OperationalScope> opScopeChoices;
        opScopeChoices = new HashSet<>();
        opScopeChoices.add(OperationalScope.Core);
        opScopeChoices.add(OperationalScope.CPU);
        opScopeChoices.add(OperationalScope.Network_Wide);

        EntitlementPoolEntity entitlementPool =
                createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
                        EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
                        opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
        entitlementPool.setStartDate(LocalDate.now().format(formatter));
        entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));

        VersionInfo info = new VersionInfo();
        Version version = new Version();
        info.getViewableVersions().add(version);
        info.setActiveVersion(version);
        doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());

        LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
                "Core",AggregationFunction.Average,10,"Hour");

        ArrayList<LimitEntity> limitEntityList = new ArrayList();
        limitEntityList.add(limitEntity);

        doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
        doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
        doReturn(true).when(limitDao).isLimitPresent(anyObject());
        doReturn(limitEntity).when(limitDao).get(anyObject());
        try {
            Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
            limitField.setAccessible(true);
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
            limitField.set(null, limitDao);

            Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
            epField.setAccessible(true);
            modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
            epField.set(null, entitlementPoolDao);
        } catch(NoSuchFieldException | IllegalAccessException e)
        {
            Assert.fail();
        }

        vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);

        verify(limitDao).delete(anyObject());
    }

    @Test
    public void deleteEntitlementPoolInvalidTest() {
        try {
            Set<OperationalScope> opScopeChoices;
            opScopeChoices = new HashSet<>();
            opScopeChoices.add(OperationalScope.Core);
            opScopeChoices.add(OperationalScope.CPU);
            opScopeChoices.add(OperationalScope.Network_Wide);

            EntitlementPoolEntity entitlementPool =
                createEntitlementPool("vlm1Id", null, EP1_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
                    EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
                    opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
            entitlementPool.setStartDate(LocalDate.now().format(formatter));
            entitlementPool.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter));

            VersionInfo info = new VersionInfo();
            Version version = new Version();
            info.getViewableVersions().add(version);
            info.setActiveVersion(version);
            doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject());

            LimitEntity limitEntity = LimitTest.createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version,
                "Core",AggregationFunction.Average,10,"Hour");

            ArrayList<LimitEntity> limitEntityList = new ArrayList();
            limitEntityList.add(limitEntity);

            doReturn(entitlementPool).when(entitlementPoolDao).get(anyObject());
            doReturn(limitEntityList).when(vendorLicenseFacade).listLimits(anyObject(), anyObject(), anyObject(), anyObject());
            doReturn(false).when(limitDao).isLimitPresent(anyObject());

            try {
                Field limitField = VendorLicenseManagerImpl.class.getDeclaredField("limitDao");
                limitField.setAccessible(true);
                Field modifiersField = Field.class.getDeclaredField("modifiers");
                modifiersField.setAccessible(true);
                modifiersField.setInt(limitField, limitField.getModifiers() & ~Modifier.FINAL);
                limitField.set(null, limitDao);

                Field epField = VendorLicenseManagerImpl.class.getDeclaredField("entitlementPoolDao");
                epField.setAccessible(true);
                modifiersField = Field.class.getDeclaredField("modifiers");
                modifiersField.setAccessible(true);
                modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
                epField.set(null, entitlementPoolDao);
            } catch(NoSuchFieldException | IllegalAccessException e)
            {
                Assert.fail();
            }

            vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1);
        } catch (CoreException exception) {
            Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
        }
    } */

 /* private static final String USER1 = "epTestUser1";
  private static final String USER2 = "epTestUser2";
  private static final String EP1_V01_DESC = "EP1 desc";
  private static final Version VERSION01 = new Version(0, 1);
  private static final Version VERSION03 = new Version(0, 3);
  private static final String EP1_NAME = "EP1 name";
  private static final String EP2_NAME = "EP2 name";

  private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
  private static EntitlementPoolDao entitlementPoolDao;

  private static String vlm1Id;
  private static String vlm2Id;
  private static String ep1Id;
  private static String ep2Id;

  public static EntitlementPoolEntity createEntitlementPool(String vlmId, Version version,
                                                            String name, String desc, int threshold,
                                                            ThresholdUnit thresholdUnit,
                                                            EntitlementMetric entitlementMetricChoice,
                                                            String entitlementMetricOther,
                                                            String increments,
                                                            AggregationFunction aggregationFunctionChoice,
                                                            String aggregationFunctionOther,
                                                            Set<OperationalScope> operationalScopeChoices,
                                                            String operationalScopeOther,
                                                            EntitlementTime timeChoice,
                                                            String timeOther, String sku) {
    EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity();
    entitlementPool.setVendorLicenseModelId(vlmId);
    entitlementPool.setVersion(version);
    entitlementPool.setName(name);
    entitlementPool.setDescription(desc);
    entitlementPool.setThresholdValue(threshold);
    entitlementPool.setThresholdUnit(thresholdUnit);
    entitlementPool
        .setEntitlementMetric(new ChoiceOrOther<>(entitlementMetricChoice, entitlementMetricOther));
    entitlementPool.setIncrements(increments);
    entitlementPool.setAggregationFunction(
        new ChoiceOrOther<>(aggregationFunctionChoice, aggregationFunctionOther));
    entitlementPool.setOperationalScope(
        new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther));
    entitlementPool.setTime(new ChoiceOrOther<>(timeChoice, timeOther));
    return entitlementPool;
  }

  private static void assertEntitlementPoolsEquals(EntitlementPoolEntity actual,
                                                   EntitlementPoolEntity expected) {
    Assert.assertEquals(actual.getVendorLicenseModelId(), expected.getVendorLicenseModelId());
    Assert.assertEquals(actual.getVersion(), expected.getVersion());
    Assert.assertEquals(actual.getId(), expected.getId());
    Assert.assertEquals(actual.getName(), expected.getName());
    Assert.assertEquals(actual.getDescription(), expected.getDescription());
    Assert.assertEquals(actual.getThresholdValue(), expected.getThresholdValue());
    Assert.assertEquals(actual.getThresholdUnit(), expected.getThresholdUnit());
    Assert.assertEquals(actual.getEntitlementMetric(), expected.getEntitlementMetric());
    Assert.assertEquals(actual.getIncrements(), expected.getIncrements());
    Assert.assertEquals(actual.getAggregationFunction(), expected.getAggregationFunction());
    Assert.assertEquals(actual.getOperationalScope(), expected.getOperationalScope());
    Assert.assertEquals(actual.getTime(), expected.getTime());
  }

  @BeforeClass
  private void init() {
    entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
    vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
            .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1 dec", "icon1"),
        USER1).getId();
    vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
            .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
        USER1).getId();
  }

  @Test
  public void emptyListTest() {
    Collection<EntitlementPoolEntity> entitlementPools =
        vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
    Assert.assertEquals(entitlementPools.size(), 0);
  }

  @Test(dependsOnMethods = "emptyListTest")
  public void createTest() {
    ep1Id = testCreate(vlm1Id, EP1_NAME);

    Set<OperationalScope> opScopeChoices;
    opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Core);
    opScopeChoices.add(OperationalScope.CPU);
    opScopeChoices.add(OperationalScope.Network_Wide);
    EntitlementPoolEntity ep2 =
        createEntitlementPool(vlm1Id, null, EP2_NAME, "EP2 dec", 70, ThresholdUnit.Absolute,
            EntitlementMetric.Other, "exception metric2", "inc2", AggregationFunction.Average, null,
            opScopeChoices, null, EntitlementTime.Other, "time2", "sku2");
    ep2Id = vendorLicenseManager.createEntitlementPool(ep2, USER1).getId();
    ep2.setId(ep2Id);
  }

  private String testCreate(String vlmId, String name) {
    Set<OperationalScope> opScopeChoices = new HashSet<>();
    opScopeChoices.add(OperationalScope.Other);
    EntitlementPoolEntity ep1 =
        createEntitlementPool(vlmId, null, name, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
            EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
            opScopeChoices, "op scope1", EntitlementTime.Other, "time1", "sku1");
    String ep1Id = vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
    ep1.setId(ep1Id);

    EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(ep1);
    Assert.assertTrue(loadedEp1.equals(ep1));
    return ep1Id;
  }

  @Test(dependsOnMethods = {"createTest"})
  public void testCreateWithExistingName_negative() {
    testCreateWithExistingName_negative(vlm1Id, EP1_NAME);
  }

  @Test(dependsOnMethods = {"createTest"})
  public void testCreateWithExistingNameUnderOtherVlm() {
    testCreate(vlm2Id, EP1_NAME);
  }

  @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
  public void updateAndGetTest() {
    EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, VERSION01, ep1Id);

    EntitlementPoolEntity ep1 = entitlementPoolDao.get(emptyEp1);
    ep1.setEntitlementMetric(new ChoiceOrOther<>(EntitlementMetric.Other, "exception metric1 updated"));
    ep1.setAggregationFunction(new ChoiceOrOther<>(AggregationFunction.Other, "agg func1 updated"));

    vendorLicenseManager.updateEntitlementPool(ep1, USER1);

    EntitlementPoolEntity loadedEp1 = vendorLicenseManager.getEntitlementPool(emptyEp1, USER1);
    assertEntitlementPoolsEquals(loadedEp1, ep1);
  }

  @Test(dependsOnMethods = {"updateAndGetTest"})
  public void testGetNonExistingVersion_negative() {
    try {
      vendorLicenseManager
          .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(48, 83), ep1Id), USER1);
      Assert.assertTrue(false);
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
    }
  }

  @Test(dependsOnMethods = {"updateAndGetTest"})
  public void testGetOtherUserCandidateVersion_negative() {
    vendorLicenseManager.checkin(vlm1Id, USER1);
    vendorLicenseManager.checkout(vlm1Id, USER2);
    try {
      vendorLicenseManager
          .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id), USER1);
      Assert.assertTrue(false);
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
    }
  }

  @Test(dependsOnMethods = {"testGetOtherUserCandidateVersion_negative"})
  public void testGetCandidateVersion() {
    EntitlementPoolEntity ep = new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id);
    ep.setDescription("updated!");
    vendorLicenseManager.updateEntitlementPool(ep, USER2);

    EntitlementPoolEntity actualEp = vendorLicenseManager.getEntitlementPool(ep, USER2);
    EntitlementPoolEntity expectedEp = entitlementPoolDao.get(ep);

    Assert.assertEquals(actualEp.getDescription(), ep.getDescription());
    assertEntitlementPoolsEquals(actualEp, expectedEp);
  }

  @Test(dependsOnMethods = {"testGetCandidateVersion"})
  public void testGetOldVersion() {
    vendorLicenseManager.checkin(vlm1Id, USER2);
    EntitlementPoolEntity actualEp = vendorLicenseManager
        .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 1), ep1Id), USER2);
    Assert.assertEquals(actualEp.getDescription(), EP1_V01_DESC);
  }

  @Test(dependsOnMethods = {"testGetOldVersion"})
  public void listTest() {
    Collection<EntitlementPoolEntity> loadedEps =
        vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1);
    Assert.assertEquals(loadedEps.size(), 2);

    int existingCounter = 0;
    for (EntitlementPoolEntity loadedEp : loadedEps) {
      if (ep2Id.equals(loadedEp.getId()) || ep1Id.equals(loadedEp.getId())) {
        existingCounter++;
      }
    }

    Assert.assertEquals(existingCounter, 2);
  }

  @Test(dependsOnMethods = {"listTest"})
  public void deleteTest() {
    vendorLicenseManager.checkout(vlm1Id, USER1);
    EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, null, ep1Id);
    vendorLicenseManager.deleteEntitlementPool(emptyEp1, USER1);

    emptyEp1.setVersion(VERSION03);
    EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(emptyEp1);
    Assert.assertEquals(loadedEp1, null);

    Collection<EntitlementPoolEntity> loadedEps =
        entitlementPoolDao.list(new EntitlementPoolEntity(vlm1Id, VERSION03, null));
    Assert.assertEquals(loadedEps.size(), 1);
    Assert.assertEquals(loadedEps.iterator().next().getId(), ep2Id);
  }

  @Test(dependsOnMethods = "deleteTest")
  public void listOldVersionTest() {
    Collection<EntitlementPoolEntity> loadedEps =
        vendorLicenseManager.listEntitlementPools(vlm1Id, VERSION01, USER1);
    Assert.assertEquals(loadedEps.size(), 2);
  }

  @Test(dependsOnMethods = "deleteTest")
  public void testCreateWithRemovedName() {
    testCreate(vlm1Id, EP1_NAME);
  }

  @Test(dependsOnMethods = "deleteTest")
  public void testCreateWithExistingNameAfterCheckout_negative() {
    testCreateWithExistingName_negative(vlm1Id, EP2_NAME);
  }

  private void testCreateWithExistingName_negative(String vlmId, String epName) {
    try {
      EntitlementPoolEntity ep1 =
          createEntitlementPool(vlmId, null, epName, EP1_V01_DESC, 80, ThresholdUnit.Percentage,
              EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, "agg func1",
              Collections.singleton(OperationalScope.Other), "op scope1", EntitlementTime.Other,
              "time1", "sku1");
      vendorLicenseManager.createEntitlementPool(ep1, USER1).getId();
      Assert.fail();
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
    }
  }
*/
}