From 644017cb3edd5b7a077a634ffd5daf2fee6bc088 Mon Sep 17 00:00:00 2001 From: az2497 Date: Thu, 10 Aug 2017 17:49:40 +0300 Subject: [SDC] OnBoard with enabled tests and features Change-Id: I4c1bbf6e1c854cf97a3561c736f83da44b58b7c0 Signed-off-by: az2497 [SDC] OnBoard with enabled tests and features. Change-Id: Icd52f039aee4dd393a1404d530bb9fdd0b20e604 Signed-off-by: az2497 --- .../sdc/vendorlicense/EntitlementPoolTest.java | 639 ----------------- .../sdc/vendorlicense/FeatureGroupTest.java | 376 ---------- .../sdc/vendorlicense/LicenseAgreementTest.java | 238 ------- .../sdc/vendorlicense/LicenseKeyGroupTest.java | 521 -------------- .../org/openecomp/sdc/vendorlicense/LimitTest.java | 49 +- .../vendorlicense/VendorLicenseFacadeImplTest.java | 84 ++- .../sdc/vendorlicense/VendorLicenseModelTest.java | 436 ------------ .../vendorlicense/impl/EntitlementPoolTest.java | 765 +++++++++++++++++++++ .../sdc/vendorlicense/impl/FeatureGroupTest.java | 334 +++++++++ .../vendorlicense/impl/LicenseAgreementTest.java | 311 +++++++++ .../vendorlicense/impl/LicenseKeyGroupTest.java | 629 +++++++++++++++++ .../vendorlicense/impl/VendorLicenseModelTest.java | 330 +++++++++ 12 files changed, 2465 insertions(+), 2247 deletions(-) delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/EntitlementPoolTest.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/FeatureGroupTest.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseAgreementTest.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseKeyGroupTest.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/EntitlementPoolTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/EntitlementPoolTest.java deleted file mode 100644 index 620c6fbf91..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/EntitlementPoolTest.java +++ /dev/null @@ -1,639 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - - -package org.openecomp.sdc.vendorlicense; - -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.*; -import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; -import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.openecomp.sdc.versioning.types.VersionInfo; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - -public class EntitlementPoolTest { - - //JUnit Test Cases using Mockito - private final String USER1 = "epTestUser1"; - private final String EP1_NAME = "EP1 name"; - private final String LT1_NAME = "LT1 name"; - - @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 name, String desc, int threshold, - ThresholdUnit thresholdUnit, - EntitlementMetric entitlementMetricChoice, - String entitlementMetricOther, - String increments, - AggregationFunction aggregationFunctionChoice, - String aggregationFunctionOther, - Set 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.setIncrements(increments); - entitlementPool.setOperationalScope( - new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther)); - return entitlementPool; - } - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void createTest() { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - 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"); - ep2.setStartDate(LocalDate.now().format(formatter)); - ep2.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter)); - - vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1); - } - - @Test - public void createWithInvalidStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm2Id", 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"); - ep2.setStartDate(LocalDate.now().format(formatter)); - ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); - vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createWithoutStartDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm3Id", 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"); - ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); - vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createWithSameStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm4Id", 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"); - ep2.setStartDate(LocalDate.now().format(formatter)); - ep2.setExpiryDate(LocalDate.now().format(formatter)); - vendorLicenseManagerImpl.createEntitlementPool(ep2, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createUpdate() { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - 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"); - ep2.setStartDate(LocalDate.now().minusDays(3L).format(formatter)); - ep2.setExpiryDate(LocalDate.now().minusDays(2L).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()); - - vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1); - } - - @Test - public void updateWithInvalidStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm2Id", 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"); - ep2.setStartDate(LocalDate.now().format(formatter)); - ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); - vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void updateWithoutStartDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm3Id", 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"); - ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); - vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void updateWithSameStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep2 = - createEntitlementPool("vlm4Id", 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"); - ep2.setStartDate(LocalDate.now().format(formatter)); - ep2.setExpiryDate(LocalDate.now().format(formatter)); - vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void deleteEntitlementPoolTest() { - Set 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, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); - - ArrayList 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 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, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); - - ArrayList 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 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 entitlementPools = - vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1); - Assert.assertEquals(entitlementPools.size(), 0); - } - - @Test(dependsOnMethods = "emptyListTest") - public void createTest() { - ep1Id = testCreate(vlm1Id, EP1_NAME); - - Set 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 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 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 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 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); - } - } -*/ -} - diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/FeatureGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/FeatureGroupTest.java deleted file mode 100644 index 41c4678b01..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/FeatureGroupTest.java +++ /dev/null @@ -1,376 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - - -package org.openecomp.sdc.vendorlicense; - -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.openecomp.sdc.vendorlicense.dao.*; -import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; -import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; -import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -/** - * Created by KATYR on 4/10/2016 - */ - -public class FeatureGroupTest { - //JUnit Test Cases using Mockito - private static final Version VERSION01 = new Version(0, 1); - private final String FG1_NAME = "FG1 name"; - - @Mock - private VendorLicenseModelDao vendorLicenseModelDao; - - @Mock - private LicenseAgreementDao licenseAgreementDao; - - @Mock - private FeatureGroupDao featureGroupDao; - - @Mock - private EntitlementPoolDao entitlementPoolDao; - - @Mock - private LicenseKeyGroupDao licenseKeyGroupDao; - - @Mock - private VersioningManager versioningManager; - - @InjectMocks - @Spy - private VendorLicenseManagerImpl vendorLicenseManagerImpl; - - public FeatureGroupEntity updateFeatureGroup(String vlmId, Version version, String id, String name, String desc, - String partNumber, String manufacturerReferenceNumber, Set - licenseKeyGroupIds, Set entitlementPoolIds, Set - referencingLicenseAgreements){ - FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlmId, version, id); - featureGroup.setVendorLicenseModelId(vlmId); - featureGroup.setVersion(version); - featureGroup.setId(id); - featureGroup.setName(name); - featureGroup.setDescription(desc); - featureGroup.setPartNumber(partNumber); - //featureGroup.setManufacturerReferenceNumber(manufacturerReferenceNumber); - featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); - featureGroup.setEntitlementPoolIds(entitlementPoolIds); - featureGroup.setReferencingLicenseAgreements(referencingLicenseAgreements); - - return featureGroup; - } - - @BeforeMethod - public void setUp() throws Exception{ - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUpdate(){ - Set licenseKeyGroupIds; - licenseKeyGroupIds = new HashSet<>(); - licenseKeyGroupIds.add("lkg1"); - - Set entitlementPoolIds; - entitlementPoolIds = new HashSet<>(); - entitlementPoolIds.add("ep1"); - - Set referencingLicenseAgreements; - referencingLicenseAgreements = new HashSet<>(); - referencingLicenseAgreements.add("la1"); - - FeatureGroupEntity featureGroupEntity = updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc", - "partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds, - referencingLicenseAgreements); - - doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); - - /*if(featureGroupEntity.getManufacturerReferenceNumber() != null) - featureGroupDao.update(featureGroupEntity); - verify(featureGroupDao).update(anyObject());*/ - } - - @Test - public void testUpdateWithoutManufacturingReferenceNumber(){ - Set licenseKeyGroupIds; - licenseKeyGroupIds = new HashSet<>(); - licenseKeyGroupIds.add("lkg1"); - - Set entitlementPoolIds; - entitlementPoolIds = new HashSet<>(); - entitlementPoolIds.add("ep1"); - - Set referencingLicenseAgreements; - referencingLicenseAgreements = new HashSet<>(); - referencingLicenseAgreements.add("la1"); - - FeatureGroupEntity featureGroupEntity = updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc", - "partNumber", null, licenseKeyGroupIds, entitlementPoolIds, - referencingLicenseAgreements); - - doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); - - /*if(featureGroupEntity.getManufacturerReferenceNumber() != null) - featureGroupDao.update(featureGroupEntity); - verify(featureGroupDao, never()).update(anyObject());*/ - } - - -} - -/* - protected static final Version VERSION01 = new Version(0, 1); - protected static final String USER1 = "FeatureGroupTest_User1"; - protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); - protected static VendorLicenseFacade vendorLicenseFacade = - VendorLicenseFacadeFactory.getInstance().createInterface(); - - - @Test - public void testListFeatureGroups() throws Exception { - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel("vlmId_" + CommonMethods.nextUuId(), "vlm2Id desc", "icon2"), - USER1).getId(); - FeatureGroupEntity - fg22 = LicenseAgreementTest - .createFeatureGroup(vlmId, VERSION01, "fg2", "FG2", "FG2 desc", null, null); - String fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId(); - FeatureGroupEntity fg33 = LicenseAgreementTest - .createFeatureGroup(vlmId, VERSION01, "fg3", "FG3", "FG3 desc", null, null); - String fg33Id = vendorLicenseManager.createFeatureGroup(fg33, USER1).getId(); - - Collection featureGroupEntities = - vendorLicenseManager.listFeatureGroups(vlmId, null, USER1); - - Assert.assertEquals(featureGroupEntities.size(), 2); - Set actualIds = new HashSet<>(); - for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) { - actualIds.add(featureGroupEntity.getId()); - } - - Set expectedIds = new HashSet<>(); - expectedIds.add(fg22Id); - expectedIds.add(fg33Id); - for (String id : actualIds) { - Assert.assertTrue(expectedIds.contains(id)); - } - - } - - @Test - public void testCreateFeatureGroup() throws Exception { - String testName = "testCreateFeatureGroup"; - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1) - .getId(); - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Other); - opScopeChoices.add(OperationalScope.Data_Center); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity - ep = EntitlementPoolTest - .createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80, - ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, - "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1"); - String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId(); - Set opScopeChoicesLKG = new HashSet<>(); - opScopeChoicesLKG.add(OperationalScope.CPU); - opScopeChoicesLKG.add(OperationalScope.VM); - opScopeChoicesLKG.add(OperationalScope.Availability_Zone); - opScopeChoicesLKG.add(OperationalScope.Data_Center); - - LicenseKeyGroupEntity - lkg = LicenseKeyGroupTest - .createLicenseKeyGroup(vlmId, VERSION01, "LKG1", "LKG1 dec", LicenseKeyType.One_Time, - new MultiChoiceOrOther<>(opScopeChoicesLKG, null)); - String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId(); - lkg.setId(lkgId); - FeatureGroupEntity fg1 = - createFGForTest(vlmId, "created" + CommonMethods.nextUuId(), Collections.singleton(epId), - Collections.singleton(lkgId)); - FeatureGroupEntity fg1FromDB = - vendorLicenseManager.getFeatureGroupModel(fg1, USER1).getFeatureGroup(); - Assert.assertTrue(fg1FromDB.equals(fg1)); - } - - - @Test - public void testCreateWithExistingName_negative() { - String testName = "createExistingName"; - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1) - .getId(); - createFGForTest(vlmId, "created", Collections.emptySet(), Collections.emptySet()); - try { - FeatureGroupEntity created = LicenseAgreementTest - .createFeatureGroup(vlmId, null, "created", "created", "created desc", - Collections.emptySet(), Collections.emptySet()); - vendorLicenseManager.createFeatureGroup(created, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); - } - } - - private FeatureGroupEntity createFGForTest(String vlmId, String fgName, Set epIds, - Set lkgIds) { - FeatureGroupEntity created = LicenseAgreementTest - .createFeatureGroup(vlmId, null, null, fgName, "created desc", epIds, lkgIds); - return vendorLicenseManager.createFeatureGroup(created, USER1); - } - - @Test - public void testUpdateFeatureGroup_addEP_andGET() throws Exception { - String testName = "testUpdateFeatureGroup_addEP_andGET"; - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1) - .getId(); - - FeatureGroupEntity fg5 = LicenseAgreementTest - .createFeatureGroup(vlmId, VERSION01, "id" + CommonMethods.nextUuId(), - "created" + CommonMethods.nextUuId(), "created desc", null, null); - vendorLicenseManager.createFeatureGroup(fg5, USER1).getId(); - - - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Other); - opScopeChoices.add(OperationalScope.Data_Center); - - EntitlementPoolEntity epToAdd = EntitlementPoolTest - .createEntitlementPool(vlmId, VERSION01, "epToAdd", "epToAdd dec", 80, - ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, - "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1"); - String epToAddId = vendorLicenseManager.createEntitlementPool(epToAdd, USER1).getId(); - - vendorLicenseManager - .updateFeatureGroup(fg5, null, null, CommonMethods.toSingleElementSet(epToAddId), null, - USER1); - FeatureGroupModel updatedFG = vendorLicenseManager.getFeatureGroupModel(fg5, USER1); - Set updatedEPs = updatedFG.getEntitlementPools(); - - epToAdd.setReferencingFeatureGroups(CommonMethods.toSingleElementSet(fg5.getId())); - - Assert.assertEquals(updatedEPs.size(), 1); - for (EntitlementPoolEntity updatedEP : updatedEPs) { - Assert.assertTrue(updatedEP.getReferencingFeatureGroups().contains(fg5.getId())); - Assert.assertEquals(updatedEP.getId(), epToAddId); - } - } - - @Test - public void testUpdateFeatureGroup_removeLKG_andGET() throws Exception { - String testName = "testUpdateFeatureGroup_removeLKG_andGET"; - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1) - .getId(); - - Set opScopeChoicesLKG = new HashSet<>(); - opScopeChoicesLKG.add(OperationalScope.CPU); - opScopeChoicesLKG.add(OperationalScope.VM); - opScopeChoicesLKG.add(OperationalScope.Availability_Zone); - opScopeChoicesLKG.add(OperationalScope.Data_Center); - LicenseKeyGroupEntity lkg = LicenseKeyGroupTest - .createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg desc", - LicenseKeyType.Unique, new MultiChoiceOrOther<>(opScopeChoicesLKG, null)); - String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId(); - lkg.setId(lkgId); - - LicenseKeyGroupEntity lkg_1 = LicenseKeyGroupTest - .createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg_1 desc", - LicenseKeyType.Unique, new MultiChoiceOrOther<>(opScopeChoicesLKG, null)); - String lkgId_1 = vendorLicenseManager.createLicenseKeyGroup(lkg_1, USER1).getId(); - lkg.setId(lkgId); - - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Other); - opScopeChoices.add(OperationalScope.Data_Center); - opScopeChoices.add(OperationalScope.Network_Wide); - EntitlementPoolEntity ep = EntitlementPoolTest - .createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80, - ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other, - "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1"); - String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId(); - - Set lkgs = new HashSet<>(); - lkgs.add(lkgId); - lkgs.add(lkgId_1); - - FeatureGroupEntity fg = LicenseAgreementTest - .createFeatureGroup(vlmId, VERSION01, "fg11" + CommonMethods.nextUuId(), "FG1", "FG1 desc", - CommonMethods.toSingleElementSet(epId), lkgs); - String fgId = vendorLicenseManager.createFeatureGroup(fg, USER1).getId(); - vendorLicenseManager - .updateFeatureGroup(fg, null, CommonMethods.toSingleElementSet(lkgId), null, null, USER1); - - FeatureGroupModel featureGroup = vendorLicenseManager.getFeatureGroupModel(fg, USER1); - Set licenseKeyGroups = featureGroup.getLicenseKeyGroups(); - Assert.assertEquals(licenseKeyGroups.size(), 1); - List lkgIds = new ArrayList<>(); - for (LicenseKeyGroupEntity licenseKeyGroup : licenseKeyGroups) { - lkgIds.add(licenseKeyGroup.getId()); - } - - Assert.assertTrue(lkgIds.contains(lkgId_1)); - Assert.assertFalse(lkgIds.contains(lkgId)); - - } - - - @Test - public void testDeleteFeatureGroup() throws Exception { - String testName = "testDeleteFeatureGroup"; - String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1) - .getId(); - - FeatureGroupEntity fg1 = - createFGForTest(vlmId, "new", Collections.emptySet(), Collections.emptySet()); - FeatureGroupEntity fg2 = - createFGForTest(vlmId, "newer", Collections.emptySet(), Collections.emptySet()); - Collection featureGroupEntities = - vendorLicenseManager.listFeatureGroups(vlmId, null, USER1); - Assert.assertEquals(featureGroupEntities.size(), 2); //precondition - - vendorLicenseManager.deleteFeatureGroup(fg1, USER1); - Assert.assertEquals(vendorLicenseManager.listFeatureGroups(vlmId, null, USER1).size(), 1); - - - } - - -} -*/ diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseAgreementTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseAgreementTest.java deleted file mode 100644 index 8e49926463..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseAgreementTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -/* -package org.openecomp.sdc.vendorlicense; - -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; -import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory; -import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; -import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory; -import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; -import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -public class LicenseAgreementTest { - private static final Version VERSION01 = new Version(0, 1); - private static final String USER1 = "user1"; - private static final String LA1_NAME = "LA1 Name"; - - private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); - private static FeatureGroupDao featureGroupDao; - private static LicenseAgreementDao licenseAgreementDao; - - private static String vlm1Id; - private static String vlm2Id; - private static String la1Id; - private static String la2Id; - - public static LicenseAgreementEntity createLicenseAgreement(String vlmId, Version version, - String id, String name, String desc, - String requirementsAndConstrains, - ChoiceOrOther term, - String... fgIds) { - LicenseAgreementEntity la = new LicenseAgreementEntity(); - la.setVendorLicenseModelId(vlmId); - la.setVersion(version); - la.setId(id); - la.setName(name); - la.setDescription(desc); - la.setLicenseTerm(term); - la.setRequirementsAndConstrains(requirementsAndConstrains); - for (String fgId : fgIds) { - la.getFeatureGroupIds().add(fgId); - } - return la; - } - - public static FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id, - String name, String description, - Set entitlementPoolIds, - Set licenseKeyGroupIds) { - FeatureGroupEntity featureGroup = new FeatureGroupEntity(); - featureGroup.setVendorLicenseModelId(vendorId); - featureGroup.setVersion(version); - featureGroup.setId(id); - featureGroup.setName(name); - featureGroup.setDescription(description); - featureGroup.setEntitlementPoolIds(entitlementPoolIds); - featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); - return featureGroup; - } - - @BeforeClass - private void init() { - licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface(); - featureGroupDao = FeatureGroupDaoFactory.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 createLicenseAgreementTest() { - la1Id = testCreate(vlm1Id, LA1_NAME); - } - - private String testCreate(String vlmId, String name) { - FeatureGroupEntity - fg1 = createFeatureGroup(vlmId, VERSION01, "fg11", "FG1", "FG1 desc", null, null); - featureGroupDao.create(fg1); - - LicenseAgreementEntity la1 = createLicenseAgreement(vlmId, VERSION01, null, name, "LA1 desc", - "RequirementsAndConstrains1", new ChoiceOrOther<>( - LicenseTerm.Unlimited, null), "fg11"); - la1 = vendorLicenseManager.createLicenseAgreement(la1, USER1); - String la1Id = la1.getId(); - - LicenseAgreementEntity loadedLa1 = licenseAgreementDao.get(la1); - Assert.assertTrue(loadedLa1.equals(la1)); - return la1Id; - } - - @Test(dependsOnMethods = {"createLicenseAgreementTest"}) - public void testCreateWithExistingName_negative() { - try { - LicenseAgreementEntity la1 = - createLicenseAgreement(vlm1Id, VERSION01, null, LA1_NAME, "LA1 desc", - "RequirementsAndConstrains1", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), - "fg11"); - vendorLicenseManager.createLicenseAgreement(la1, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); - } - } - - @Test(dependsOnMethods = {"createLicenseAgreementTest"}) - public void testCreateWithExistingNameUnderOtherVlm() { - testCreate(vlm2Id, LA1_NAME); - } - - @Test(dependsOnMethods = {"testCreateWithExistingName_negative"}) - public void updateLicenseAgreementTest() { - FeatureGroupEntity fg2 = - createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc", null, null); - featureGroupDao.create(fg2); - - FeatureGroupEntity fg3 = - createFeatureGroup(vlm1Id, VERSION01, "fg3", "FG3", "FG3 desc", null, null); - featureGroupDao.create(fg3); - - LicenseAgreementEntity la1 = - licenseAgreementDao.get(new LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); - la1.setDescription("LA1 desc updated"); - la1.setLicenseTerm(new ChoiceOrOther<>(LicenseTerm.Other, "bla bla term")); - la1.getFeatureGroupIds().add("fg2"); - la1.getFeatureGroupIds().add("fg3"); - la1.getFeatureGroupIds().remove("fg11"); - - Set addedFeatureGroupIds = new HashSet<>(); - addedFeatureGroupIds.add("fg2"); - addedFeatureGroupIds.add("fg3"); - - Set removedFeatureGroupIds = new HashSet<>(); - removedFeatureGroupIds.add("fg11"); - - vendorLicenseManager - .updateLicenseAgreement(la1, addedFeatureGroupIds, removedFeatureGroupIds, USER1); - - LicenseAgreementEntity loadedLa1 = - licenseAgreementDao.get(new LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); - Assert.assertTrue(loadedLa1.equals(la1)); - - } - - @Test(dependsOnMethods = {"updateLicenseAgreementTest"}) - public void listLicenseAgreementsTest() { - LicenseAgreementEntity la2 = createLicenseAgreement(vlm1Id, VERSION01, null, "LA2", "LA2 desc", - "RequirementsAndConstrains2", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), "fg2"); - la2 = vendorLicenseManager.createLicenseAgreement(la2, USER1); - la2Id = la2.getId(); - - Collection loadedLas = - vendorLicenseManager.listLicenseAgreements(vlm1Id, null, USER1); - Assert.assertEquals(loadedLas.size(), 2); - boolean la2Exists = false; - for (LicenseAgreementEntity loadedLa : loadedLas) { - if (la2Id.equals(loadedLa.getId())) { - Assert.assertTrue(loadedLa.equals(la2)); - la2Exists = true; - } - } - - Assert.assertTrue(la2Exists); - } - - @Test(dependsOnMethods = {"listLicenseAgreementsTest"}) - public void featureGroupDeletedLicenseAgreementUpdated() { - LicenseAgreementEntity licenseAgreement = - createLicenseAgreement(vlm1Id, VERSION01, "laId", "LA2", "LA2 desc", - "RequirementsAndConstrains2", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), "fg2"); - licenseAgreementDao.create(licenseAgreement); - String featureGroupId = "FeatureGroupId"; - FeatureGroupEntity created = - createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", null, null); - featureGroupDao.create(created); - featureGroupDao.addReferencingLicenseAgreement(created, licenseAgreement.getId()); - - vendorLicenseManager.deleteFeatureGroup(created, USER1); - LicenseAgreementEntity afterDeletingFG = licenseAgreementDao.get(licenseAgreement); - Assert.assertEquals(afterDeletingFG.getFeatureGroupIds().size(), 1); - Assert.assertTrue(afterDeletingFG.getFeatureGroupIds().contains("fg2")); - } - - @Test(dependsOnMethods = {"listLicenseAgreementsTest"}) - public void deleteLicenseAgreementsTest() { - vendorLicenseManager.deleteLicenseAgreement(vlm1Id, null, la1Id, USER1); - - LicenseAgreementEntity loadedLa1 = - licenseAgreementDao.get(new LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); - Assert.assertEquals(loadedLa1, null); - - Collection loadedLas = - licenseAgreementDao.list(new LicenseAgreementEntity(vlm1Id, VERSION01, null)); - Assert.assertEquals(loadedLas.size(), 1); - Assert.assertEquals(loadedLas.iterator().next().getId(), la2Id); - } - - @Test(dependsOnMethods = "deleteLicenseAgreementsTest") - public void testCreateWithRemovedName() { - testCreate(vlm1Id, LA1_NAME); - } -} - -*/ diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseKeyGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseKeyGroupTest.java deleted file mode 100644 index 04f7c794bc..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseKeyGroupTest.java +++ /dev/null @@ -1,521 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - - -package org.openecomp.sdc.vendorlicense; - -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.LicenseKeyGroupDao; -import org.openecomp.sdc.vendorlicense.dao.LimitDao; -import org.openecomp.sdc.vendorlicense.dao.types.*; -import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; -import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.openecomp.sdc.versioning.types.VersionInfo; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - -public class LicenseKeyGroupTest { - - //JUnit Test Cases using Mockito - private final String USER = "lkgTestUser"; - private final String LKG_NAME = "LKG name"; - private final String LT_NAME = "LT name"; - private final String LKG1_NAME = "LKG1 name"; - private final String USER1 = "user1"; - - @Mock - private VendorLicenseFacade vendorLicenseFacade; - - @Mock - private LicenseKeyGroupDao licenseKeyGroupDao; - @Mock - private LimitDao limitDao; - - @InjectMocks - @Spy - private VendorLicenseManagerImpl vendorLicenseManagerImpl; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set operationalScopeChoices, - String operationalScopeOther) - { - LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity(); - licenseKeyGroupEntity.setType(type); - licenseKeyGroupEntity.setOperationalScope( - new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther)); - return licenseKeyGroupEntity; - } - - @Test - public void deleteLicenseKeyGroupTest() { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - - LicenseKeyGroupEntity licenseKeyGroup = - createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null); - - 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(LT_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); - - ArrayList limitEntityList = new ArrayList(); - limitEntityList.add(limitEntity); - - doReturn(licenseKeyGroup).when(licenseKeyGroupDao).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 lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao"); - lkgField.setAccessible(true); - modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL); - lkgField.set(null, licenseKeyGroupDao); - } catch(NoSuchFieldException | IllegalAccessException e) - { - Assert.fail(); - } - - vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER); - - verify(limitDao).delete(anyObject()); - } - - @Test - public void deleteLicenseKeyGroupInvalidTest() { - try { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - - LicenseKeyGroupEntity licenseKeyGroup = - createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null); - - 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(LT_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); - - ArrayList limitEntityList = new ArrayList(); - limitEntityList.add(limitEntity); - - doReturn(licenseKeyGroup).when(licenseKeyGroupDao).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 lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao"); - lkgField.setAccessible(true); - modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL); - lkgField.set(null, licenseKeyGroupDao); - } catch(NoSuchFieldException | IllegalAccessException e) - { - Assert.fail(); - } - - vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); - } - } - - @Test - public void createTest() { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().format(formatter)); - lkg.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter)); - - vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1); - } - - @Test - public void createWithInvalidStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().format(formatter)); - lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); - vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createWithoutStartDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); - vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createWithSameStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter)); - lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); - vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void createUpdate() { - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter)); - lkg.setExpiryDate(LocalDate.now().minusDays(2L).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()); - - vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); - } - - @Test - public void updateWithInvalidStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().format(formatter)); - lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); - vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void updateWithoutStartDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); - vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - @Test - public void updateWithSameStartExpiryDateTest() { - try { - - Set opScopeChoices; - opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Core); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg = - createLicenseKeyGroup("vlm1Id", null, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, - new MultiChoiceOrOther<>(opScopeChoices, null)); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); - lkg.setStartDate(LocalDate.now().format(formatter)); - lkg.setExpiryDate(LocalDate.now().format(formatter)); - vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); - } - } - - - public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version, - String name, String desc, - LicenseKeyType type, - MultiChoiceOrOther operationalScope) { - LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); - licenseKeyGroup.setVendorLicenseModelId(vlmId); - licenseKeyGroup.setVersion(version); - licenseKeyGroup.setName(name); - licenseKeyGroup.setDescription(desc); - licenseKeyGroup.setType(type); - licenseKeyGroup.setOperationalScope(operationalScope); - return licenseKeyGroup; - } - - /*public static final String LKG1_NAME = "LKG1 name"; - private static final Version VERSION01 = new Version(0, 1); - public static final String LKG1_NAME = "LKG1 name"; - private static final String USER1 = "user1"; - public static String vlm1Id; - public static String vlm2Id; - private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); - private static LicenseKeyGroupDao licenseKeyGroupDao; - private static NoSqlDb noSqlDb; - private static String lkg1Id; - private static String lkg2Id; - - public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version, - String name, String desc, - LicenseKeyType type, - MultiChoiceOrOther operationalScope) { - LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); - licenseKeyGroup.setVendorLicenseModelId(vlmId); - licenseKeyGroup.setVersion(version); - licenseKeyGroup.setName(name); - licenseKeyGroup.setDescription(desc); - licenseKeyGroup.setType(type); - licenseKeyGroup.setOperationalScope(operationalScope); - return licenseKeyGroup; - } - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - /*@BeforeClass - private void init() { - licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); - noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - - vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec", - "icon1"), USER1).getId(); - vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest - .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"), - USER1).getId(); - } - - @Test - public void createTest() { - lkg1Id = testCreate(vlm1Id, LKG1_NAME); - } - - private String testCreate(String vlmId, String name) { - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.CPU); - opScopeChoices.add(OperationalScope.VM); - opScopeChoices.add(OperationalScope.Tenant); - opScopeChoices.add(OperationalScope.Data_Center); - LicenseKeyGroupEntity - lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time, - new MultiChoiceOrOther<>(opScopeChoices, null)); - String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId(); - lkg1.setId(lkg1Id); - - LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1); - Assert.assertTrue(loadedLkg1.equals(lkg1)); - return lkg1Id; - } - - @Test(dependsOnMethods = {"createTest"}) - public void testCreateWithExistingName_negative() { - try { - LicenseKeyGroupEntity lkg1 = - createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time, - new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other), - "other op scope")); - vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId(); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); - } - } - - @Test(dependsOnMethods = {"createTest"}) - public void testCreateWithExistingNameUnderOtherVlm() { - testCreate(vlm2Id, LKG1_NAME); - } - - @Test(dependsOnMethods = {"testCreateWithExistingName_negative"}) - public void updateAndGetTest() { - LicenseKeyGroupEntity lkg1 = - licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)); - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Other); - lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated")); - lkg1.setDescription("LKG1 dec updated"); - - vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1); - - LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1); - Assert.assertTrue(loadedLkg1.equals(lkg1)); - - } - - @Test(dependsOnMethods = {"updateAndGetTest"}) - public void listTest() { - Set opScopeChoices = new HashSet<>(); - opScopeChoices.add(OperationalScope.Network_Wide); - LicenseKeyGroupEntity lkg2 = - createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal, - new MultiChoiceOrOther<>(opScopeChoices, null)); - lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId(); - lkg2.setId(lkg2Id); - - Collection loadedLkgs = - vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1); - Assert.assertEquals(loadedLkgs.size(), 2); - for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) { - if (lkg2Id.equals(loadedLkg.getId())) { - Assert.assertTrue(loadedLkg.equals(lkg2)); - } - } - } - - @Test(dependsOnMethods = {"listTest"}) - public void deleteTest() { - vendorLicenseManager - .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1); - - LicenseKeyGroupEntity loadedLkg1 = - licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)); - Assert.assertEquals(loadedLkg1, null); - - Collection loadedLkgs = - licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null)); - Assert.assertEquals(loadedLkgs.size(), 1); - Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id); - } - - @Test(dependsOnMethods = "deleteTest") - public void testCreateWithRemovedName() { - testCreate(vlm1Id, LKG1_NAME); - } - */ -} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java index a8d1ed9f65..c71b591a04 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java @@ -76,9 +76,9 @@ public class LimitTest { private VendorLicenseManagerImpl vendorLicenseManagerImpl; public static LimitEntity createLimitEntity(String name, LimitType type, String description, - Version version, EntitlementMetric metric, + Version version, String metric, AggregationFunction aggregationFunction, int unit, - EntitlementTime time) { + String time) { LimitEntity limitEntity = new LimitEntity(); limitEntity.setName(name); limitEntity.setType(type); @@ -86,7 +86,7 @@ public class LimitTest { limitEntity.setVersion(version); limitEntity.setMetric(metric); limitEntity.setAggregationFunction(aggregationFunction); - limitEntity.setUnit(unit); + limitEntity.setUnit(String.valueOf(unit)); limitEntity.setTime(time); return limitEntity; } @@ -94,26 +94,15 @@ public class LimitTest { @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - 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); - } catch(NoSuchFieldException | IllegalAccessException e) - { - Assert.fail(); - } } @Test public void testUpdateLimit() { Version version = new Version(); LimitEntity limitEntity1 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); + "Core",AggregationFunction.Average,10,"Hour"); LimitEntity limitEntity2 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Tokens,AggregationFunction.Peak,12,EntitlementTime.Month); + "Tokens",AggregationFunction.Peak,12,"Month"); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(version); info.setActiveVersion(version); @@ -140,9 +129,9 @@ public class LimitTest { try { Version version = new Version(); LimitEntity limitEntity1 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); + "Core",AggregationFunction.Average,10,"Hour"); LimitEntity limitEntity2 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Tokens,AggregationFunction.Peak,12,EntitlementTime.Month); + "Tokens",AggregationFunction.Peak,12,"Month"); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(version); info.setActiveVersion(version); @@ -170,7 +159,7 @@ public class LimitTest { public void testDeleteLimit() { Version version = new Version(); LimitEntity limitEntity = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); + "Core",AggregationFunction.Average,10,"Hour"); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(version); info.setActiveVersion(version); @@ -193,9 +182,9 @@ public class LimitTest { try { Version version = new Version(); LimitEntity limitEntity1 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Core,AggregationFunction.Average,10,EntitlementTime.Hour); + "Core",AggregationFunction.Average,10,"Hour"); LimitEntity limitEntity2 = createLimitEntity(LT1_NAME,LimitType.Vendor,"string",version, - EntitlementMetric.Tokens,AggregationFunction.Peak,12,EntitlementTime.Month); + "Tokens",AggregationFunction.Peak,12,"Month"); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(version); info.setActiveVersion(version); @@ -291,11 +280,11 @@ public class LimitTest { public void testGet() { LimitEntity expected = createLimit(VLM_ID, VERSION, EPLKG_ID, LIMIT1_ID); expected.setType(LimitType.Vendor); - expected.setValue(100); - expected.setUnit(10); + expected.setValue(String.valueOf(100)); + expected.setUnit(String.valueOf(10)); expected.setAggregationFunction(AggregationFunction.Average); - expected.setMetric(EntitlementMetric.CPU); - expected.setTime(EntitlementTime.Day); + expected.setMetric("BWTH"); + expected.setTime("Day"); doReturn(true).when(limitDao).isLimitPresent(anyObject()); doReturn(expected).when(limitDao).get(anyObject()); @@ -313,7 +302,7 @@ public class LimitTest { Assert.assertEquals(actual.getValue(), expected.getValue()); Assert.assertEquals(actual.getAggregationFunction().name(), expected.getAggregationFunction() .name()); - Assert.assertEquals(actual.getMetric().name(), expected.getMetric().name()); + Assert.assertEquals(actual.getMetric(), expected.getMetric()); } @@ -322,11 +311,11 @@ public class LimitTest { limitEntity.setName(limitId + " name"); limitEntity.setDescription(limitId + " desc"); limitEntity.setVersion(version); - limitEntity.setMetric(EntitlementMetric.CPU); + limitEntity.setMetric("BWTH"); limitEntity.setAggregationFunction(AggregationFunction.Average); - limitEntity.setUnit(10); - limitEntity.setTime(EntitlementTime.Day); - limitEntity.setValue(100); + limitEntity.setUnit(String.valueOf(10)); + limitEntity.setTime("Day"); + limitEntity.setValue(String.valueOf(100)); return limitEntity; } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java index 40bbc77faa..53e9857a32 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java @@ -1,18 +1,23 @@ package org.openecomp.sdc.vendorlicense; -import org.junit.Assert; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; -import org.openecomp.sdc.vendorlicense.dao.*; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionInfo; +import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -26,13 +31,15 @@ import java.util.Set; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP; +import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG; /** * This test just verifies Feature Group Get and List APIs. */ public class VendorLicenseFacadeImplTest { + /* + //JUnit Test Cases using Mockito private static final Version VERSION01 = new Version(0, 1); public static final String EP1 = "ep1"; @@ -118,6 +125,62 @@ public class VendorLicenseFacadeImplTest { retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber())); } + @Test + public void testSubmitLAWithoutFG() + { + try { + resetFieldModifiers(); + + VersionInfo info = new VersionInfo(); + info.getViewableVersions().add(VERSION01); + info.setActiveVersion(VERSION01); + + LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity(); + List licenseAgreementEntities = new ArrayList(){{ + add(licenseAgreementEntity); + }}; + + doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); + doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject()); + + vendorLicenseFacadeImpl.submit(VLM_ID, USER); + Assert.fail(); + } catch (CoreException exception) { + org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage()); + } + } + + @Test + public void testSubmitLAWithFGWithoutEP() + { + try { + resetFieldModifiers(); + + VersionInfo info = new VersionInfo(); + info.getViewableVersions().add(VERSION01); + info.setActiveVersion(VERSION01); + + LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity(); + FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(); + licenseAgreementEntity.setFeatureGroupIds(new HashSet(){{ + add("54654654asdas5"); + }}); + List licenseAgreementEntities = new ArrayList(){{ + add(licenseAgreementEntity); + }}; + + doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); + doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject()); + doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); + + vendorLicenseFacadeImpl.submit(VLM_ID, USER); + + Assert.fail(); + } catch (CoreException exception) { + org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage()); + } + } + private void resetFieldModifiers() { try { Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao"); @@ -133,6 +196,13 @@ public class VendorLicenseFacadeImplTest { modifiersField.setAccessible(true); modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL); epField.set(null, entitlementPoolDao); + + Field laField = VendorLicenseFacadeImpl.class.getDeclaredField("licenseAgreementDao"); + laField.setAccessible(true); + modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(laField, laField.getModifiers() & ~Modifier.FINAL); + laField.set(null, licenseAgreementDao); } catch(NoSuchFieldException | IllegalAccessException e) { org.testng.Assert.fail(); @@ -159,5 +229,5 @@ public class VendorLicenseFacadeImplTest { ep.setManufacturerReferenceNumber(MRN); return ep; } - -} +*/ +} \ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java deleted file mode 100644 index 32a415bfa6..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java +++ /dev/null @@ -1,436 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - *//* - - -package org.openecomp.sdc.vendorlicense; - -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; -import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory; -import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; -import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; -import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel; -import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; -import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; -import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.testng.Assert; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class VendorLicenseModelTest { - private static final Version VERSION01 = new Version(0, 1); - private static final Version VERSION02 = new Version(0, 2); - private static final String USER1 = "vlmTestUser1"; - private static final String USER2 = "vlmTestUser2"; - private static final String USER3 = "vlmTestUser3"; - private static final String VLM1_NAME = "Vlm1 name"; - private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); - private static VendorLicenseModelDao vendorLicenseModelDao = - VendorLicenseModelDaoFactory.getInstance().createInterface(); - - private static String vlm1Id; - private static String vlm2Id; - private static String vlm3Id; - private static String vlm4Id; - private static String laId; - private static String fg1Id; - private static String fg2Id; - - private static String testCreate() { - VendorLicenseModelEntity vlm1 = createVendorLicenseModel(VLM1_NAME, "VLM1 dec", "icon1"); - String vlmId = vendorLicenseManager.createVendorLicenseModel(vlm1, USER1).getId(); - - vlm1.setVersion(VERSION01); - VendorLicenseModelEntity loadedVlm1 = vendorLicenseModelDao.get(vlm1); - Assert.assertTrue(loadedVlm1.equals(vlm1)); - return vlmId; - } - - public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc, - String icon) { - VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity(); - vendorLicenseModel.setVendorName(name); - vendorLicenseModel.setDescription(desc); - vendorLicenseModel.setIconRef(icon); - return vendorLicenseModel; - } - - @BeforeTest - private void init() { - UniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, VLM1_NAME); - UniqueValueUtil - .deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, "VLM1 updated"); - UniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, "VLM2"); - UniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, "test_vlm1"); - UniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, "test_vlm2"); - UniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, "test_vlm3"); - } - - @Test - public void createTest() { - vlm1Id = testCreate(); - //TODO: add verification of 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"createTest"}) - public void testCreateWithExistingVendorName_negative() { - try { - vendorLicenseManager - .createVendorLicenseModel(createVendorLicenseModel(VLM1_NAME, "VLM1 dec", "icon1"), - USER1); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); - } - //TODO: add verification of none 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"testCreateWithExistingVendorName_negative"}) - public void updateTest() { - VendorLicenseModelEntity expectedVlm1 = new VendorLicenseModelEntity(vlm1Id, VERSION01); - expectedVlm1.setVendorName("VLM1 updated"); - expectedVlm1.setDescription("VLM1 dec updated"); - expectedVlm1.setIconRef("icon1 updated"); - vendorLicenseManager.updateVendorLicenseModel(expectedVlm1, USER1); - - VendorLicenseModelEntity actualVlm1 = - vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlm1Id, VERSION01)); - Assert.assertTrue(actualVlm1.equals(expectedVlm1)); - } - - @Test(dependsOnMethods = {"updateTest"}) - public void testUpdateWithSimilarVendorName() { - VendorLicenseModelEntity expectedVlm1 = new VendorLicenseModelEntity(vlm1Id, VERSION01); - expectedVlm1.setVendorName("vlm1 UPDATED"); - vendorLicenseManager.updateVendorLicenseModel(expectedVlm1, USER1); - - VendorLicenseModelEntity actualVlm1 = - vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlm1Id, VERSION01)); - Assert.assertTrue(actualVlm1.equals(expectedVlm1)); - } - - @Test(dependsOnMethods = {"updateTest"}) - public void testCreateWithRemovedVendorName() { - testCreate(); - } - - @Test(dependsOnMethods = {"updateTest"}) - public void getTest() { - VendorLicenseModelEntity expectedVlm1 = - vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlm1Id, VERSION01)); - VersionedVendorLicenseModel actualVlm1 = - vendorLicenseManager.getVendorLicenseModel(vlm1Id, null, USER1); - - Assert.assertTrue(actualVlm1.getVendorLicenseModel().equals(expectedVlm1)); - Assert.assertEquals(actualVlm1.getVersionInfo().getActiveVersion(), VERSION01); - Assert.assertEquals(actualVlm1.getVersionInfo().getStatus(), VersionStatus.Locked); - Assert.assertEquals(actualVlm1.getVersionInfo().getLockingUser(), USER1); - } - - @Test(dependsOnMethods = {"getTest"}) - public void listTest() { - VendorLicenseModelEntity vlm2 = createVendorLicenseModel("VLM2", "VLM2 dec", "icon2"); - vlm2Id = vendorLicenseManager.createVendorLicenseModel(vlm2, USER1).getId(); - vlm2.setId(vlm2Id); - - Collection loadedVlms = - vendorLicenseManager.listVendorLicenseModels(null, USER1); - boolean vlm1Exists = false; - boolean vlm2Exists = false; - for (VersionedVendorLicenseModel loadedVlm : loadedVlms) { - if (vlm1Id.equals(loadedVlm.getVendorLicenseModel().getId())) { - vlm1Exists = true; - continue; - } - if (vlm2Id.equals(loadedVlm.getVendorLicenseModel().getId())) { - Assert.assertTrue(loadedVlm.getVendorLicenseModel().equals(vlm2)); - - vlm2Exists = true; - } - } - - Assert.assertTrue(vlm1Exists); - Assert.assertTrue(vlm2Exists); - } - - @Test(dependsOnMethods = {"listTest"}) - public void listFinalVersionWhenNoneTest() { - Collection loadedVlms = - vendorLicenseManager.listVendorLicenseModels(VersionStatus.Final.name(), USER1); - boolean vlm1Exists = false; - boolean vlm2Exists = false; - for (VersionedVendorLicenseModel loadedVlm : loadedVlms) { - if (vlm1Id.equals(loadedVlm.getVendorLicenseModel().getId())) { - vlm1Exists = true; - continue; - } - if (vlm2Id.equals(loadedVlm.getVendorLicenseModel().getId())) { - vlm2Exists = true; - } - } - - Assert.assertFalse(vlm1Exists); - Assert.assertFalse(vlm2Exists); - } - - @Test(dependsOnMethods = {"listFinalVersionWhenNoneTest"}) - - // Unsupported operation for 1607 release. -*/ -/* public void deleteTest() { - vendorLicenseManager.deleteVendorLicenseModel(vlm1Id, USER1); - - VendorLicenseModelEntity loadedVlm1 = vendorLicenseModelDao.get(new VendorLicenseModelEntity(vlm1Id, VERSION01)); - Assert.assertEquals(loadedVlm1, null); - - Collection loadedVlms = vendorLicenseModelDao.list(null); - Assert.assertTrue(loadedVlms.size() > 1); - boolean vlm1Exists = false; - boolean vlm2Exists = false; - for (VendorLicenseModelEntity loadedVlm : loadedVlms) { - if (vlm1Id.equals(loadedVlm.getId())) { - vlm1Exists = true; - } - if (vlm2Id.equals(loadedVlm.getId())) { - vlm2Exists = true; - } - } - Assert.assertFalse(vlm1Exists); - Assert.assertTrue(vlm2Exists); - } - - @Test(dependsOnMethods = {"deleteTest"})*//* - - public void checkinTest() { - vendorLicenseManager.checkin(vlm2Id, USER1); - - VersionedVendorLicenseModel versionedVlm2 = - vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER1); - Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION01); - Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), VersionStatus.Available); - Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); - - //TODO: add verification of 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"checkinTest"}) - public void checkoutTest() { - vendorLicenseManager.checkout(vlm2Id, USER2); - - VersionedVendorLicenseModel versionedVlm2 = - vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER2); - Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION02); - Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), VersionStatus.Locked); - Assert.assertEquals(versionedVlm2.getVersionInfo().getLockingUser(), USER2); - - versionedVlm2 = vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER1); - Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION01); - Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), VersionStatus.Locked); - Assert.assertEquals(versionedVlm2.getVersionInfo().getLockingUser(), USER2); - - //TODO: add verification of 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"checkoutTest"}) - public void undoCheckoutTest() { - vendorLicenseManager.undoCheckout(vlm2Id, USER2); - - VersionedVendorLicenseModel versionedVlm2 = - vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER2); - Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION01); - Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), VersionStatus.Available); - Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); - } - - @Test(dependsOnMethods = {"undoCheckoutTest"}, expectedExceptions = CoreException.class) - public void submitUncompletedVlmNegativeTest() { - vendorLicenseManager.submit(vlm2Id, USER2); - - //TODO: add verification of none 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"submitUncompletedVlmNegativeTest"}, - expectedExceptions = CoreException.class) - public void submitUncompletedVlmMissingFGNegativeTest() { - vendorLicenseManager.checkout(vlm2Id, USER2); - LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm2Id, null, null); - LicenseAgreementEntity licenseAgreementEntity = - vendorLicenseManager.createLicenseAgreement(licenseAgreement, USER2); - laId = licenseAgreementEntity.getId(); - vendorLicenseManager.checkin(vlm2Id, USER2); - vendorLicenseManager.submit(vlm2Id, USER2); - } - - @Test(dependsOnMethods = {"submitUncompletedVlmMissingFGNegativeTest"}, - expectedExceptions = CoreException.class) - public void submitUncompletedVlmMissingEPNegativeTest() { - vendorLicenseManager.checkout(vlm2Id, USER2); - FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm2Id, null, null); - featureGroup = vendorLicenseManager.createFeatureGroup(featureGroup, USER2); - fg1Id = featureGroup.getId(); - - LicenseAgreementModel - licenseAgreementModel = - vendorLicenseManager.getLicenseAgreementModel(vlm2Id, null, laId, USER2); - Set fgIdSet = new HashSet<>(); - fgIdSet.add(fg1Id); - vendorLicenseManager - .updateLicenseAgreement(licenseAgreementModel.getLicenseAgreement(), fgIdSet, null, USER2); - vendorLicenseManager.checkin(vlm2Id, USER2); - vendorLicenseManager.submit(vlm2Id, USER2); - } - - @Test(dependsOnMethods = {"submitUncompletedVlmMissingEPNegativeTest"}, - expectedExceptions = CoreException.class) - public void submitUncompletedVlmMissingEPInOneFGNegativeTest() { - vendorLicenseManager.checkout(vlm2Id, USER2); - FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm2Id, null, null); - EntitlementPoolEntity entitlementPool = vendorLicenseManager - .createEntitlementPool(new EntitlementPoolEntity(vlm2Id, null, null), USER2); - featureGroup.getEntitlementPoolIds().add(entitlementPool.getId()); - featureGroup = vendorLicenseManager.createFeatureGroup(featureGroup, USER2); - fg2Id = featureGroup.getId(); - LicenseAgreementModel licenseAgreementModel = - vendorLicenseManager.getLicenseAgreementModel(vlm2Id, null, laId, USER2); - Set fgIdSet = new HashSet<>(); - fgIdSet.add(fg2Id); - vendorLicenseManager - .updateLicenseAgreement(licenseAgreementModel.getLicenseAgreement(), fgIdSet, null, USER2); - - vendorLicenseManager.checkin(vlm2Id, USER2); - vendorLicenseManager.submit(vlm2Id, USER2); - } - - @Test(dependsOnMethods = {"submitUncompletedVlmMissingEPInOneFGNegativeTest"}) - public void submitTest() { - vendorLicenseManager.checkout(vlm2Id, USER2); - - EntitlementPoolEntity entitlementPool = vendorLicenseManager - .createEntitlementPool(new EntitlementPoolEntity(vlm2Id, null, null), USER2); - Set epSetId = new HashSet<>(); - epSetId.add(entitlementPool.getId()); - - FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm2Id, null, fg1Id); - featureGroup.getEntitlementPoolIds().add(entitlementPool.getId()); - FeatureGroupModel - featureGroupModel = vendorLicenseManager.getFeatureGroupModel(featureGroup, USER2); - - vendorLicenseManager - .updateFeatureGroup(featureGroupModel.getFeatureGroup(), null, null, epSetId, null, USER2); - vendorLicenseManager.checkin(vlm2Id, USER2); - vendorLicenseManager.submit(vlm2Id, USER2); - - VersionedVendorLicenseModel versionedVlm2 = - vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER1); - Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), new Version(1, 0)); - Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), VersionStatus.Final); - Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); - - //TODO: add verification of 'ActivityLogManager.addActionLog' func call - } - - @Test(dependsOnMethods = {"submitTest"}) - public void listFinalVersionWhenOneTest() { - Collection loadedVlms = - vendorLicenseManager.listVendorLicenseModels(VersionStatus.Final.name(), USER1); - boolean vlm2Exists = false; - for (VersionedVendorLicenseModel loadedVlm : loadedVlms) { - if (vlm2Id.equals(loadedVlm.getVendorLicenseModel().getId())) { - vlm2Exists = true; - Assert.assertEquals(loadedVlm.getVersionInfo().getActiveVersion(), new Version(1, 0)); - Assert.assertEquals(loadedVlm.getVersionInfo().getStatus(), VersionStatus.Final); - Assert.assertNull(loadedVlm.getVersionInfo().getLockingUser()); - break; - } - } - - Assert.assertTrue(vlm2Exists); - } - - @Test(dependsOnMethods = {"listFinalVersionWhenOneTest"}) - public void testVLMListWithModificationTimeDescOrder() { - VendorLicenseModelEntity vlm1 = createVendorLicenseModel("test_vlm1", "desc", "icon"); - vlm3Id = vendorLicenseManager.createVendorLicenseModel(vlm1, USER3).getId(); - - VendorLicenseModelEntity vlm2 = createVendorLicenseModel("test_vlm2", "desc", "icon"); - vlm4Id = vendorLicenseManager.createVendorLicenseModel(vlm2, USER3).getId(); - - assertVLMInWantedLocationInVSPList(vlm4Id, 0, USER3); - assertVLMInWantedLocationInVSPList(vlm3Id, 1, USER3); - } - - @Test(dependsOnMethods = {"testVLMListWithModificationTimeDescOrder"}) - public void testOldVLMAfterChangeShouldBeInBeginningOfList() { - EntitlementPoolEntity ep = vendorLicenseManager - .createEntitlementPool(new EntitlementPoolEntity(vlm3Id, null, null), USER3); - - assertVLMInWantedLocationInVSPList(vlm3Id, 0, USER3); - } - - @Test(dependsOnMethods = {"testOldVLMAfterChangeShouldBeInBeginningOfList"}) - public void testAddNewVLMShouldBeInBeginningOfList() { - VendorLicenseModelEntity vlm = createVendorLicenseModel("test_vlm3", "desc", "icon"); - String vlm5Id = vendorLicenseManager.createVendorLicenseModel(vlm, USER3).getId(); - - assertVLMInWantedLocationInVSPList(vlm5Id, 0, USER3); - } - - @Test(dependsOnMethods = {"testAddNewVLMShouldBeInBeginningOfList"}) - public void testVLMInBeginningOfListAfterCheckin() { - vendorLicenseManager.checkin(vlm4Id, USER3); - assertVLMInWantedLocationInVSPList(vlm4Id, 0, USER3); - } - - @Test(dependsOnMethods = {"testVLMInBeginningOfListAfterCheckin"}) - public void testVLMInBeginningOfListAfterCheckout() { - vendorLicenseManager.checkin(vlm3Id, USER3); - assertVLMInWantedLocationInVSPList(vlm3Id, 0, USER3); - - vendorLicenseManager.checkout(vlm4Id, USER3); - assertVLMInWantedLocationInVSPList(vlm4Id, 0, USER3); - } - - @Test(dependsOnMethods = {"testVLMInBeginningOfListAfterCheckout"}) - public void testVLMInBeginningOfListAfterUndoCheckout() { - vendorLicenseManager.checkout(vlm3Id, USER3); - vendorLicenseManager.undoCheckout(vlm3Id, USER3); - assertVLMInWantedLocationInVSPList(vlm3Id, 0, USER3); - } - - private void assertVLMInWantedLocationInVSPList(String vlmId, int location, String user) { - List vlmList = - (List) vendorLicenseManager - .listVendorLicenseModels(null, user); - Assert.assertEquals(vlmList.get(location).getVendorLicenseModel().getId(), vlmId); - } - - -} -*/ diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java new file mode 100644 index 0000000000..178d05e6c8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java @@ -0,0 +1,765 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.sdc.vendorlicense.impl; + +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.*; +import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +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 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); + } + + @Test + public void createTest() { + Set 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, USER1); + verify(vendorLicenseFacade).createEntitlementPool(ep2,USER1); + + } + + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + + "license model with id vlm1_id has invalid date range.") + public void createWithInvalidStartExpiryDateTest() { + + Set 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, USER1).getId(); + Assert.fail(); + + } + + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + + "license model with id vlm1_id has invalid date range.") + public void createWithoutStartDateTest() { + + Set 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, USER1).getId(); + Assert.fail(); + + } + + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + + "license model with id vlm1_id has invalid date range.") + public void createWithSameStartExpiryDateTest() { + + Set 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, USER1).getId(); + Assert.fail(); + } + + @Test + public void testUpdate() { + Set 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)); + + VersionInfo info = new VersionInfo(); + info.getViewableVersions().add(VERSION01); + info.setActiveVersion(VERSION01); + doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject()); + + vendorLicenseManagerImpl.updateEntitlementPool(ep2, USER1); + verify(vendorLicenseFacade).updateEntitlementPool(ep2,USER1); + verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01); + } + + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + + "license model with id vlm1_id has invalid date range.") + public void updateWithInvalidStartExpiryDateTest() { + + Set 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, USER1); + Assert.fail(); + + } + + @Test + public void updateWithoutStartDateTest() { + try { + + Set 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, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void updateWithSameStartExpiryDateTest() { + try { + + Set 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, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void deleteEntitlementPoolTest() { + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + + Set 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,USER1); + + doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(), + anyObject(),anyObject()); + + vendorLicenseManagerImpl.deleteEntitlementPool(entitlementPool, USER1); + + verify(entitlementPoolDao).delete(entitlementPool); + verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01); + + } + + @Test + public void testGetEntitlementPool(){ + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + versionInfo.setActiveVersion(VERSION01); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Read, USER1); + + Set 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,USER1); + + Assert.assertEquals(retrived.getId(),entitlementPool.getId()); + Assert.assertEquals(retrived.getVendorLicenseModelId(),entitlementPool.getVendorLicenseModelId()); + Assert.assertEquals(retrived.getVersion(),entitlementPool.getVersion()); + } + + @Test + public void testListEntitlmentPool(){ + + Set 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, USER1); + + Collection EPs = + vendorLicenseManagerImpl.listEntitlementPools(vlm1_id, VERSION01, USER1); + + verify(vendorLicenseFacade).listEntitlementPools(vlm1_id, VERSION01, USER1); + Assert.assertEquals(EPs.size(), 2); + EPs.forEach(ep -> Assert.assertTrue(ep.getId().matches(ep1_id + "|" + ep2_id))); + } + + + /* @Test + public void deleteEntitlementPoolTest() { + Set 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 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 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 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 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 entitlementPools = + vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1); + Assert.assertEquals(entitlementPools.size(), 0); + } + + @Test(dependsOnMethods = "emptyListTest") + public void createTest() { + ep1Id = testCreate(vlm1Id, EP1_NAME); + + Set 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 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 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 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 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); + } + } +*/ +} + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java new file mode 100644 index 0000000000..aa606913e1 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java @@ -0,0 +1,334 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.sdc.vendorlicense.impl; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; +import org.openecomp.sdc.vendorlicense.dao.*; +import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.facade.impl.VendorLicenseFacadeImpl; +import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; +import org.testng.Assert; +import org.testng.AssertJUnit.*; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +/** + * Created by KATYR on 4/10/2016 + */ + +public class FeatureGroupTest { + //JUnit Test Cases using Mockito + private static final Version VERSION01 = new Version(0, 1); + private static final Version VERSION10 = new Version(1, 0); + private final String FG1_NAME = "FG1 name"; + private static final String USER1 = "TestUser1"; + private static final String USER2 = "TestUser2"; + + private static String vlm1_id = "vlm1_id"; + private static String vlm2_id = "vlm2_id"; + private static String lkg1_id = "lkg1_id"; + private static String lkg2_id = "lkg2_id"; + private static String fg1_id = "fg1_id"; + private static String fg2_id = "fg2_id"; + private static String ep1_id = "ep1_id"; + private static String ep2_id = "ep2_id"; + + @Mock + private VendorLicenseFacade vendorLicenseFacadeMcok; + + @Mock + private LimitDao limitDaoMcok; + @Mock + private ActivityLogManager activityLogManagerMcok; + + @Mock + private VendorLicenseModelDao vendorLicenseModelDao; + + @Mock + private LicenseAgreementDao licenseAgreementDao; + + @Mock + private FeatureGroupDao featureGroupDao; + + @Mock + private EntitlementPoolDao entitlementPoolDao; + + @Mock + private LicenseKeyGroupDao licenseKeyGroupDao; + + @Mock + private VersioningManager versioningManager; + + @InjectMocks + @Spy + private VendorLicenseManagerImpl vendorLicenseManagerImpl; + + public FeatureGroupEntity updateFeatureGroup(String vlmId, Version version, String id, String name, String desc, + String partNumber, String manufacturerReferenceNumber, Set + licenseKeyGroupIds, Set entitlementPoolIds, Set + referencingLicenseAgreements){ + FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlmId, version, id); + featureGroup.setVendorLicenseModelId(vlmId); + featureGroup.setVersion(version); + featureGroup.setId(id); + featureGroup.setName(name); + featureGroup.setDescription(desc); + featureGroup.setPartNumber(partNumber); + //featureGroup.setManufacturerReferenceNumber(manufacturerReferenceNumber); + featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); + featureGroup.setEntitlementPoolIds(entitlementPoolIds); + featureGroup.setReferencingLicenseAgreements(referencingLicenseAgreements); + + return featureGroup; + } + + @BeforeMethod + public void setUp() throws Exception{ + MockitoAnnotations.initMocks(this); + } + + @Test + public void testUpdate(){ + Set licenseKeyGroupIds; + licenseKeyGroupIds = new HashSet<>(); + licenseKeyGroupIds.add("lkg1"); + + Set entitlementPoolIds; + entitlementPoolIds = new HashSet<>(); + entitlementPoolIds.add("ep1"); + + Set referencingLicenseAgreements; + referencingLicenseAgreements = new HashSet<>(); + referencingLicenseAgreements.add("la1"); + + FeatureGroupEntity featureGroupEntity = updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc", + "partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds, + referencingLicenseAgreements); + + doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); + + /*if(featureGroupEntity.getManufacturerReferenceNumber() != null) + featureGroupDao.update(featureGroupEntity); + verify(featureGroupDao).update(anyObject());*/ + } + + @Test + public void testUpdateWithoutManufacturingReferenceNumber(){ + Set licenseKeyGroupIds; + licenseKeyGroupIds = new HashSet<>(); + licenseKeyGroupIds.add("lkg1"); + + Set entitlementPoolIds; + entitlementPoolIds = new HashSet<>(); + entitlementPoolIds.add("ep1"); + + Set referencingLicenseAgreements; + referencingLicenseAgreements = new HashSet<>(); + referencingLicenseAgreements.add("la1"); + + FeatureGroupEntity featureGroupEntity = updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc", + "partNumber", null, licenseKeyGroupIds, entitlementPoolIds, + referencingLicenseAgreements); + + doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); + + /*if(featureGroupEntity.getManufacturerReferenceNumber() != null) + featureGroupDao.update(featureGroupEntity); + verify(featureGroupDao, never()).update(anyObject());*/ + } + + @Test + public void testListFeatureGroups() { + doReturn(Arrays.asList( + createFeatureGroup(vlm1_id, VERSION01, fg1_id, "FG1", "FG1 desc", new HashSet(), + new HashSet()), + createFeatureGroup(vlm1_id, VERSION01, fg2_id, "FG2", "FG2 desc", new HashSet(), + new HashSet()))) + .when(vendorLicenseFacadeMcok).listFeatureGroups(vlm1_id, VERSION01, USER1); + + Collection FGs = + vendorLicenseManagerImpl.listFeatureGroups(vlm1_id, VERSION01, USER1); + + verify(vendorLicenseFacadeMcok).listFeatureGroups(vlm1_id, VERSION01, USER1); + Assert.assertEquals(FGs.size(), 2); + FGs.forEach(fg -> Assert.assertTrue(fg.getId().matches(fg1_id + "|" + fg2_id))); + } + + @Test + public void testCreateFeatureGroup() { + FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(vlm1_id,VERSION01, + fg1_id); + + doReturn(featureGroupEntity).when(vendorLicenseFacadeMcok).createFeatureGroup + (featureGroupEntity,USER1); + + vendorLicenseManagerImpl.createFeatureGroup(featureGroupEntity,USER1); + + verify(vendorLicenseFacadeMcok).createFeatureGroup(featureGroupEntity,USER1); + } + + + @Test + public void testUpdateFeatureGroup(){ + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id); + + existingFG.setEntitlementPoolIds(new HashSet()); + existingFG.setLicenseKeyGroupIds(new HashSet()); + + doReturn(existingFG).when(featureGroupDao).get(existingFG); + + Set removedEPs = new HashSet<>(); + Set addedEPs = new HashSet<>(); + + addedEPs.add(ep1_id); + addedEPs.add(ep2_id); + EntitlementPoolEntity ep1 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep1_id); + EntitlementPoolEntity ep2 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep2_id); + doReturn(ep1).when(entitlementPoolDao).get(ep1); + doReturn(ep2).when(entitlementPoolDao).get(ep2); + + Set removedLKGs = new HashSet<>(); + Set addedLKGs = new HashSet<>(); + + addedLKGs.add(lkg1_id); + addedLKGs.add(lkg2_id); + LicenseKeyGroupEntity lkg1 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg1_id); + LicenseKeyGroupEntity lkg2 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg2_id); + doReturn(lkg1).when(licenseKeyGroupDao).get(lkg1); + doReturn(lkg2).when(licenseKeyGroupDao).get(lkg2); + + doNothing().when(vendorLicenseManagerImpl).updateUniqueName(anyObject(), anyObject(), + anyObject(),anyObject(), anyObject()); + + vendorLicenseManagerImpl.updateFeatureGroup(existingFG,addedLKGs,removedLKGs, addedEPs, + removedEPs, USER1); + + verify(vendorLicenseManagerImpl).addLicenseKeyGroupsToFeatureGroupsRef(addedLKGs, + existingFG); + verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(removedLKGs, + existingFG); + verify(vendorLicenseManagerImpl).addEntitlementPoolsToFeatureGroupsRef(addedEPs,existingFG); + verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(removedEPs, + existingFG); + + verify(featureGroupDao) + .updateFeatureGroup(existingFG,addedEPs,removedEPs, addedLKGs, removedLKGs); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id,VERSION01); + } + + + @Test + public void testGetFeatureGroup(){ + FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(vlm1_id,VERSION01,fg1_id); + vendorLicenseManagerImpl.getFeatureGroupModel(featureGroupEntity,USER1); + verify(vendorLicenseFacadeMcok).getFeatureGroupModel(featureGroupEntity,USER1); + } + + @Test + public void deleteFeatureGroupTest() { + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + + FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id); + existingFG.setName("FG_name"); + existingFG.setLicenseKeyGroupIds(new HashSet()); + existingFG.setEntitlementPoolIds(new HashSet()); + existingFG.setLicenseKeyGroupIds(new HashSet()); + + doReturn(existingFG).when(featureGroupDao).get(anyObject()); + + doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(VendorLicenseConstants + .UniqueValues.FEATURE_GROUP_NAME,vlm1_id,VERSION01.toString(),existingFG.getName()); + + vendorLicenseManagerImpl.deleteFeatureGroup(existingFG, USER1); + + verify(featureGroupDao).delete(existingFG); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id,VERSION01); + + verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(existingFG + .getLicenseKeyGroupIds(),existingFG); + verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(existingFG + .getEntitlementPoolIds(),existingFG); + verify(vendorLicenseManagerImpl).deleteUniqueName(VendorLicenseConstants + .UniqueValues.FEATURE_GROUP_NAME,vlm1_id,VERSION01.toString(),existingFG.getName()); + } + + private FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id, + String name, String description, + Set entitlementPoolIds, + Set licenseKeyGroupIds) { + FeatureGroupEntity featureGroup = new FeatureGroupEntity(); + featureGroup.setVendorLicenseModelId(vendorId); + featureGroup.setVersion(version); + featureGroup.setId(id); + featureGroup.setName(name); + featureGroup.setDescription(description); + featureGroup.setEntitlementPoolIds(entitlementPoolIds); + featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); + return featureGroup; + } +} + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java new file mode 100644 index 0000000000..b0b5953a53 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java @@ -0,0 +1,311 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorlicense.impl; + +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LimitDao; +import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; +import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; +import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.VersioningUtil; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE; +import static org.testng.AssertJUnit.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public class LicenseAgreementTest { + + private static final String USER1 = "TestUser1"; + private static final String USER2 = "TestUser2"; + + private static String vlm1_id = "vlm1_id"; + private static String vlm2_id = "vlm2_id"; + private static String la1_id = "la1_id"; + private static String la2_id = "la2_id"; + private static String fg1_id = "fg1_id"; + private static String fg2_id = "fg2_id"; + public static final Version VERSION01 = new Version(0, 1); + private static final Version VERSION10 = new Version(1, 0); + + @Mock + private VersioningManager versioningManagerMcok; + @Mock + private VendorLicenseFacade vendorLicenseFacadeMcok; + @Mock + private VendorLicenseModelDao vendorLicenseModelDaoMcok; + @Mock + private LicenseAgreementDao licenseAgreementDaoMcok; + @Mock + private FeatureGroupDao featureGroupDaoMcok; + @Mock + private EntitlementPoolDao entitlementPoolDaoMcok; + @Mock + private LicenseKeyGroupDao licenseKeyGroupDaoMcok; + @Mock + private LimitDao limitDaoMcok; + @Mock + private ActivityLogManager activityLogManagerMcok; + + + @Spy + @InjectMocks + private VendorLicenseManagerImpl vendorLicenseManager; + + + @Captor + private ArgumentCaptor activityLogEntityArg; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + public static LicenseAgreementEntity createLicenseAgreement(String vlmId, Version version, + String id, String name, String desc, + String requirementsAndConstrains, + ChoiceOrOther term, + String... fgIds) { + LicenseAgreementEntity la = new LicenseAgreementEntity(); + la.setVendorLicenseModelId(vlmId); + la.setVersion(version); + la.setId(id); + la.setName(name); + la.setDescription(desc); + la.setLicenseTerm(term); + la.setRequirementsAndConstrains(requirementsAndConstrains); + for (String fgId : fgIds) { + la.getFeatureGroupIds().add(fgId); + } + return la; + } + + public static FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id, + String name, String description, + Set entitlementPoolIds, + Set licenseKeyGroupIds) { + FeatureGroupEntity featureGroup = new FeatureGroupEntity(); + featureGroup.setVendorLicenseModelId(vendorId); + featureGroup.setVersion(version); + featureGroup.setId(id); + featureGroup.setName(name); + featureGroup.setDescription(description); + featureGroup.setEntitlementPoolIds(entitlementPoolIds); + featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); + return featureGroup; + } + + + @Test + public void listLicenseAgreementsTest() { + + LicenseAgreementEntity la = new LicenseAgreementEntity(vlm1_id,VERSION01,USER1); + doReturn(la).when(vendorLicenseManager).createLicenseAgreementForList(vlm1_id,VERSION01, USER1); + + doReturn(Arrays.asList( + createLicenseAgreement(vlm1_id, VERSION01, la1_id, "LA1", "LA1 " + + "desc","RequirementsAndConstrains2", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), + "fg1"), + createLicenseAgreement(vlm1_id, VERSION01, la2_id, "LA2", "LA2 desc", + "RequirementsAndConstrains2", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), + "fg2"))) + .when(licenseAgreementDaoMcok).list(la); + + Collection LAs = + vendorLicenseManager.listLicenseAgreements(vlm1_id, VERSION01, USER1); + Assert.assertEquals(LAs.size(), 2); + LAs.forEach(licseAgreement-> Assert.assertTrue(licseAgreement.getId().matches(la1_id + "|" + la2_id))); + } + + @Test + public void testListLicenseAgreementsWhenNone() { + + LicenseAgreementEntity la = new LicenseAgreementEntity(vlm1_id,VERSION01,USER1); + doReturn(la).when(vendorLicenseManager).createLicenseAgreementForList(vlm1_id,VERSION01, + USER1); + + doReturn(new ArrayList()) + .when(licenseAgreementDaoMcok).list(la); + + Collection LAs = + vendorLicenseManager.listLicenseAgreements(vlm1_id, VERSION01, USER1); + + verify(licenseAgreementDaoMcok).list(la); + Assert.assertEquals(LAs.size(), 0); + } + + + @Test + public void testCreateLicenseAgreement() { + + LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity(vlm1_id,VERSION01, + la2_id); + + doReturn(licenseAgreementEntity).when(vendorLicenseFacadeMcok).createLicenseAgreement + (licenseAgreementEntity,USER1); + + vendorLicenseManager.createLicenseAgreement(licenseAgreementEntity,USER1); + + verify(vendorLicenseFacadeMcok).createLicenseAgreement(licenseAgreementEntity,USER1); + } + + @Test + public void testUpdateLicenseAgreement() { + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManager).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + LicenseAgreementEntity existingLA = new LicenseAgreementEntity(vlm1_id, VERSION01, la1_id); + + existingLA.setFeatureGroupIds(new HashSet()); + + doReturn(existingLA).when(licenseAgreementDaoMcok).get(existingLA); + + Set removedFGs = new HashSet<>(); + Set addedFGs = new HashSet<>(); + addedFGs.add(fg1_id); + addedFGs.add(fg2_id); + FeatureGroupEntity fg1 = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id); + FeatureGroupEntity fg2 = new FeatureGroupEntity(vlm1_id, VERSION01, fg2_id); + doReturn(fg1).when(featureGroupDaoMcok).get(fg1); + doReturn(fg2).when(featureGroupDaoMcok).get(fg2); + doReturn(existingLA).when(vendorLicenseManager).createLicenseAgreementForList(vlm1_id,VERSION01, + USER1); + doNothing().when(vendorLicenseManager).updateUniqueName(anyObject(), anyObject(), anyObject(), + anyObject(), anyObject()); + + vendorLicenseManager.updateLicenseAgreement(existingLA, addedFGs, removedFGs, USER1); + + verify(licenseAgreementDaoMcok) + .updateColumnsAndDeltaFeatureGroupIds(existingLA, addedFGs, removedFGs); + verify(vendorLicenseManager).addFeatureGroupsToLicenseAgreementRef(addedFGs,existingLA); + verify(vendorLicenseManager).removeFeatureGroupsToLicenseAgreementRef(removedFGs,existingLA); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id,VERSION01); + + } + + @Test + public void deleteLicenseAgreementsTest() { + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManager).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + + LicenseAgreementEntity existingLA = new LicenseAgreementEntity(vlm1_id, VERSION01, la1_id); + existingLA.setName("LA"); + existingLA.setFeatureGroupIds(new HashSet<>()); + + doReturn(existingLA).when(licenseAgreementDaoMcok).get(anyObject()); + + doNothing().when(vendorLicenseManager).deleteUniqueName(VendorLicenseConstants.UniqueValues + .LICENSE_AGREEMENT_NAME,vlm1_id,VERSION01.toString(),existingLA.getName()); + + vendorLicenseManager.deleteLicenseAgreement(vlm1_id, VERSION01, la1_id, USER1); + + verify(licenseAgreementDaoMcok).delete(existingLA); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id,VERSION01); + verify(vendorLicenseManager).removeFeatureGroupsToLicenseAgreementRef(existingLA + .getFeatureGroupIds(),existingLA); + } + + @Test + public void testGetLicenseAgreement(){ + vendorLicenseManager.getLicenseAgreementModel(vlm1_id,VERSION01,la1_id,USER1); + verify(vendorLicenseFacadeMcok).getLicenseAgreementModel(vlm1_id,VERSION01,la1_id,USER1); + } + +/* + @Test(dependsOnMethods = {"listLicenseAgreementsTest"}) + public void featureGroupDeletedLicenseAgreementUpdated() { + LicenseAgreementEntity licenseAgreement = + createLicenseAgreement(vlm1Id, VERSION01, "laId", "LA2", "LA2 desc", + "RequirementsAndConstrains2", new ChoiceOrOther<>(LicenseTerm.Unlimited, null), "fg2"); + licenseAgreementDao.create(licenseAgreement); + String featureGroupId = "FeatureGroupId"; + FeatureGroupEntity created = + createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", null, null); + featureGroupDao.create(created); + featureGroupDao.addReferencingLicenseAgreement(created, licenseAgreement.getId()); + + vendorLicenseManager.deleteFeatureGroup(created, USER1); + LicenseAgreementEntity afterDeletingFG = licenseAgreementDao.get(licenseAgreement); + Assert.assertEquals(afterDeletingFG.getFeatureGroupIds().size(), 1); + Assert.assertTrue(afterDeletingFG.getFeatureGroupIds().contains("fg2")); + } + + */ +} + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java new file mode 100644 index 0000000000..acd1ce8cce --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java @@ -0,0 +1,629 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.sdc.vendorlicense.impl; + +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.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LimitDao; +import org.openecomp.sdc.vendorlicense.dao.types.*; +import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +public class LicenseKeyGroupTest { + + //JUnit Test Cases using Mockito + private final String USER = "lkgTestUser"; + private final String LKG_NAME = "LKG name"; + private final String LKG2_NAME = "LKG2 name"; + private final String LT_NAME = "LT name"; + private final String LKG1_NAME = "LKG1 name"; + private final String USER1 = "user1"; + private static String lkg1_id = "lkg1_id"; + private static String lkg2_id = "lkg2_id"; + private static String vlm1_id = "vlm1_id"; + public static final Version VERSION01 = new Version(0, 1); + + + @Mock + private VendorLicenseFacade vendorLicenseFacade; + + @Mock + private LicenseKeyGroupDao licenseKeyGroupDao; + @Mock + private LimitDao limitDao; + + @InjectMocks + @Spy + private VendorLicenseManagerImpl vendorLicenseManagerImpl; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set operationalScopeChoices, + String operationalScopeOther) + { + LicenseKeyGroupEntity licenseKeyGroupEntity = new LicenseKeyGroupEntity(); + licenseKeyGroupEntity.setType(type); + licenseKeyGroupEntity.setOperationalScope( + new MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther)); + return licenseKeyGroupEntity; + } + /* + @Test + public void deleteLicenseKeyGroupTest() { + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + + LicenseKeyGroupEntity licenseKeyGroup = + createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null); + + 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(LT_NAME,LimitType.Vendor,"string",version, + "Core",AggregationFunction.Average,10,"Hour"); + + ArrayList limitEntityList = new ArrayList(); + limitEntityList.add(limitEntity); + + doReturn(licenseKeyGroup).when(licenseKeyGroupDao).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 lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao"); + lkgField.setAccessible(true); + modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL); + lkgField.set(null, licenseKeyGroupDao); + } catch(NoSuchFieldException | IllegalAccessException e) + { + Assert.fail(); + } + + vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER); + + verify(limitDao).delete(anyObject()); + } + + @Test + public void deleteLicenseKeyGroupInvalidTest() { + try { + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + + LicenseKeyGroupEntity licenseKeyGroup = + createLicenseKeyGroup(LicenseKeyType.Unique, opScopeChoices, null); + + 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(LT_NAME,LimitType.Vendor,"string",version, + "Core",AggregationFunction.Average,10,"Hour"); + + ArrayList limitEntityList = new ArrayList(); + limitEntityList.add(limitEntity); + + doReturn(licenseKeyGroup).when(licenseKeyGroupDao).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 lkgField = VendorLicenseManagerImpl.class.getDeclaredField("licenseKeyGroupDao"); + lkgField.setAccessible(true); + modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(lkgField, lkgField.getModifiers() & ~Modifier.FINAL); + lkgField.set(null, licenseKeyGroupDao); + } catch(NoSuchFieldException | IllegalAccessException e) + { + Assert.fail(); + } + + vendorLicenseManagerImpl.deleteLicenseKeyGroup(licenseKeyGroup, USER); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + } + */ + @Test + public void createTest() { + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().format(formatter)); + lkg.setExpiryDate(LocalDate.now().plusDays(1L).format(formatter)); + + vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1); + verify(vendorLicenseFacade).createLicenseKeyGroup(lkg,USER1); + } + + @Test + public void createWithInvalidStartExpiryDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().format(formatter)); + lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); + vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void createWithoutStartDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); + vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId(); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void createWithSameStartExpiryDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().plusDays(2L).format(formatter)); + lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); + vendorLicenseManagerImpl.createLicenseKeyGroup(lkg, USER1).getId(); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void testUpdate() { + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup(vlm1_id, null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().minusDays(3L).format(formatter)); + lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); + VersionInfo info = new VersionInfo(); + info.getViewableVersions().add(VERSION01); + info.setActiveVersion(VERSION01); + doReturn(info).when(vendorLicenseFacade).getVersionInfo(anyObject(),anyObject(),anyObject()); + + vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); + verify(vendorLicenseFacade).updateLicenseKeyGroup(lkg,USER1); + verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01); + } + + @Test + public void updateWithInvalidStartExpiryDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().format(formatter)); + lkg.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); + vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void updateWithoutStartDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null, lkg1_id,LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); + vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void updateWithSameStartExpiryDateTest() { + try { + + Set opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg = + createLicenseKeyGroup("vlm1Id", null,lkg1_id, LKG1_NAME, "LKG1 dec",LicenseKeyType.Unique, + new MultiChoiceOrOther<>(opScopeChoices, null)); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + lkg.setStartDate(LocalDate.now().format(formatter)); + lkg.setExpiryDate(LocalDate.now().format(formatter)); + vendorLicenseManagerImpl.updateLicenseKeyGroup(lkg, USER1); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorLicenseErrorCodes.DATE_RANGE_INVALID); + } + } + + @Test + public void testListlistLicenseKeyGroups(){ + + MultiChoiceOrOther multiChoiceOrOther = new MultiChoiceOrOther(); + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + multiChoiceOrOther.setChoices(opScopeChoices); + multiChoiceOrOther.setOther("Other"); + + doReturn(Arrays.asList( + createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME,"LKG1 dec", LicenseKeyType.Universal, + multiChoiceOrOther), + createLicenseKeyGroup(vlm1_id,VERSION01, lkg2_id, LKG2_NAME,"LKG2 dec", LicenseKeyType + .Universal, multiChoiceOrOther))) + .when(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1); + + Collection LKGs = + vendorLicenseManagerImpl.listLicenseKeyGroups(vlm1_id, VERSION01, USER1); + + verify(vendorLicenseFacade).listLicenseKeyGroups(vlm1_id, VERSION01, USER1); + Assert.assertEquals(LKGs.size(), 2); + LKGs.forEach(lkg -> Assert.assertTrue(lkg.getId().matches(lkg1_id + "|" + lkg2_id))); + } + + @Test + public void testGetLicenseKeyGroup(){ + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + versionInfo.setActiveVersion(VERSION01); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Read, USER1); + + MultiChoiceOrOther multiChoiceOrOther = new MultiChoiceOrOther(); + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + multiChoiceOrOther.setChoices(opScopeChoices); + multiChoiceOrOther.setOther("Other"); + + LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME, + "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther); + + doReturn(lkg).when(licenseKeyGroupDao).get(anyObject()); + + LicenseKeyGroupEntity lkgRetrived = vendorLicenseManagerImpl.getLicenseKeyGroup(lkg,USER1); + verify(licenseKeyGroupDao).get(lkg); + + Assert.assertEquals(lkgRetrived.getId(),lkg.getId()); + Assert.assertEquals(lkgRetrived.getVendorLicenseModelId(),lkg.getVendorLicenseModelId()); + Assert.assertEquals(lkgRetrived.getVersion(),lkg.getVersion()); + + } + + @Test + public void testDeleteLicenseKeyGroup() { + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + versionInfo.setLockingUser(USER1); + ArrayList viewable = new ArrayList(); + viewable.add(VERSION01); + versionInfo.setViewableVersions(viewable); + + doReturn(versionInfo).when(vendorLicenseManagerImpl).getVersionInfo(vlm1_id, + VersionableEntityAction.Write, USER1); + + + MultiChoiceOrOther multiChoiceOrOther = new MultiChoiceOrOther(); + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + multiChoiceOrOther.setChoices(opScopeChoices); + multiChoiceOrOther.setOther("Other"); + + LicenseKeyGroupEntity lkg = createLicenseKeyGroup(vlm1_id,VERSION01, lkg1_id, LKG1_NAME, + "LKG1 dec", LicenseKeyType.Universal, multiChoiceOrOther); + + lkg.setReferencingFeatureGroups(new HashSet<>()); + + doReturn(lkg).when(licenseKeyGroupDao).get(anyObject()); + + doNothing().when(vendorLicenseManagerImpl).deleteChildLimits(vlm1_id,VERSION01,lkg1_id,USER1); + + doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(anyObject(),anyObject(), + anyObject(),anyObject()); + + vendorLicenseManagerImpl.deleteLicenseKeyGroup(lkg, USER1); + + verify(licenseKeyGroupDao).delete(lkg); + verify(vendorLicenseFacade).updateVlmLastModificationTime(vlm1_id,VERSION01); + + } + + public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version,String id, + String name, String desc, + LicenseKeyType type, + MultiChoiceOrOther operationalScope) { + LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); + licenseKeyGroup.setVendorLicenseModelId(vlmId); + licenseKeyGroup.setVersion(version); + licenseKeyGroup.setId(id); + licenseKeyGroup.setName(name); + licenseKeyGroup.setDescription(desc); + licenseKeyGroup.setType(type); + licenseKeyGroup.setOperationalScope(operationalScope); + return licenseKeyGroup; + } + + /*public static final String LKG1_NAME = "LKG1 name"; + private static final Version VERSION01 = new Version(0, 1); + public static final String LKG1_NAME = "LKG1 name"; + private static final String USER1 = "user1"; + public static String vlm1Id; + public static String vlm2Id; + private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); + private static LicenseKeyGroupDao licenseKeyGroupDao; + private static NoSqlDb noSqlDb; + private static String lkg1Id; + private static String lkg2Id; + + public static LicenseKeyGroupEntity createLicenseKeyGroup(String vlmId, Version version, + String name, String desc, + LicenseKeyType type, + MultiChoiceOrOther operationalScope) { + LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); + licenseKeyGroup.setVendorLicenseModelId(vlmId); + licenseKeyGroup.setVersion(version); + licenseKeyGroup.setName(name); + licenseKeyGroup.setDescription(desc); + licenseKeyGroup.setType(type); + licenseKeyGroup.setOperationalScope(operationalScope); + return licenseKeyGroup; + } + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + /*@BeforeClass + private void init() { + licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); + noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + + vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest + .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1Id dec", + "icon1"), USER1).getId(); + vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest + .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"), + USER1).getId(); + } + + @Test + public void createTest() { + lkg1Id = testCreate(vlm1Id, LKG1_NAME); + } + + private String testCreate(String vlmId, String name) { + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.VM); + opScopeChoices.add(OperationalScope.Tenant); + opScopeChoices.add(OperationalScope.Data_Center); + LicenseKeyGroupEntity + lkg1 = createLicenseKeyGroup(vlmId, VERSION01, name, "LKG1 dec", LicenseKeyType.One_Time, + new MultiChoiceOrOther<>(opScopeChoices, null)); + String lkg1Id = vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId(); + lkg1.setId(lkg1Id); + + LicenseKeyGroupEntity loadedLkg1 = licenseKeyGroupDao.get(lkg1); + Assert.assertTrue(loadedLkg1.equals(lkg1)); + return lkg1Id; + } + + @Test(dependsOnMethods = {"createTest"}) + public void testCreateWithExistingName_negative() { + try { + LicenseKeyGroupEntity lkg1 = + createLicenseKeyGroup(vlm1Id, VERSION01, LKG1_NAME, "LKG1 dec", LicenseKeyType.One_Time, + new MultiChoiceOrOther<>(Collections.singleton(OperationalScope.Other), + "other op scope")); + vendorLicenseManager.createLicenseKeyGroup(lkg1, USER1).getId(); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + } + + @Test(dependsOnMethods = {"createTest"}) + public void testCreateWithExistingNameUnderOtherVlm() { + testCreate(vlm2Id, LKG1_NAME); + } + + @Test(dependsOnMethods = {"testCreateWithExistingName_negative"}) + public void updateAndGetTest() { + LicenseKeyGroupEntity lkg1 = + licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)); + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Other); + lkg1.setOperationalScope(new MultiChoiceOrOther<>(opScopeChoices, "op scope1 updated")); + lkg1.setDescription("LKG1 dec updated"); + + vendorLicenseManager.updateLicenseKeyGroup(lkg1, USER1); + + LicenseKeyGroupEntity loadedLkg1 = vendorLicenseManager.getLicenseKeyGroup(lkg1, USER1); + Assert.assertTrue(loadedLkg1.equals(lkg1)); + + } + + @Test(dependsOnMethods = {"updateAndGetTest"}) + public void listTest() { + Set opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Network_Wide); + LicenseKeyGroupEntity lkg2 = + createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", LicenseKeyType.Universal, + new MultiChoiceOrOther<>(opScopeChoices, null)); + lkg2Id = vendorLicenseManager.createLicenseKeyGroup(lkg2, USER1).getId(); + lkg2.setId(lkg2Id); + + Collection loadedLkgs = + vendorLicenseManager.listLicenseKeyGroups(vlm1Id, null, USER1); + Assert.assertEquals(loadedLkgs.size(), 2); + for (LicenseKeyGroupEntity loadedLkg : loadedLkgs) { + if (lkg2Id.equals(loadedLkg.getId())) { + Assert.assertTrue(loadedLkg.equals(lkg2)); + } + } + } + + @Test(dependsOnMethods = {"listTest"}) + public void deleteTest() { + vendorLicenseManager + .deleteLicenseKeyGroup(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id), USER1); + + LicenseKeyGroupEntity loadedLkg1 = + licenseKeyGroupDao.get(new LicenseKeyGroupEntity(vlm1Id, VERSION01, lkg1Id)); + Assert.assertEquals(loadedLkg1, null); + + Collection loadedLkgs = + licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlm1Id, VERSION01, null)); + Assert.assertEquals(loadedLkgs.size(), 1); + Assert.assertEquals(loadedLkgs.iterator().next().getId(), lkg2Id); + } + + @Test(dependsOnMethods = "deleteTest") + public void testCreateWithRemovedName() { + testCreate(vlm1Id, LKG1_NAME); + } + */ +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java new file mode 100644 index 0000000000..195fa5d4da --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java @@ -0,0 +1,330 @@ +package org.openecomp.sdc.vendorlicense.impl; + +import org.junit.rules.ExpectedException; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LimitDao; +import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; +import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; +import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.VersioningUtil; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; +import org.testng.annotations.BeforeMethod; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE; + + +/** + * Created by ayalaben on 7/19/2017 + */ +public class VendorLicenseModelTest { + + private static final String USER1 = "TestUser1"; + private static final String USER2 = "TestUser2"; + + private static String vlm1_id = "vlm1_id"; + private static String vlm2_id = "vlm2_id"; + private static String la1_id = "la1_id"; + private static String la2_id = "la2_id"; + private static String fg1_id = "fg1_id"; + private static String fg2_id = "fg2_id"; + public static final Version VERSION01 = new Version(0, 1); + private static final Version VERSION10 = new Version(1, 0); + + @Mock + private VersioningManager versioningManagerMcok; + @Mock + private VendorLicenseFacade vendorLicenseFacadeMcok; + @Mock + private VendorLicenseModelDao vendorLicenseModelDaoMcok; + @Mock + private LicenseAgreementDao licenseAgreementDaoMcok; + @Mock + private FeatureGroupDao featureGroupDaoMcok; + @Mock + private EntitlementPoolDao entitlementPoolDaoMcok; + @Mock + private LicenseKeyGroupDao licenseKeyGroupDaoMcok; + @Mock + private LimitDao limitDaoMcok; + @Mock + private ActivityLogManager activityLogManagerMcok; + + + @Spy + @InjectMocks + private VendorLicenseManagerImpl vendorLicenseManager; + + + @Captor + private ArgumentCaptor activityLogEntityArg; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testCheckout() { + + doReturn(VERSION01).when(versioningManagerMcok) + .checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1_id, USER1); + + vendorLicenseManager.checkout(vlm1_id, USER1); + + Assert.assertEquals(VERSION01.getStatus(), VersionStatus.Locked); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id, VERSION01); + + verify(versioningManagerMcok) + .checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1_id, USER1); + + verify(activityLogManagerMcok).addActionLog(activityLogEntityArg.capture(), eq(USER1)); + ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); + Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); + Assert.assertTrue(activityLogEntity.isSuccess()); + } + + @Test + public void testUndoCheckout() { + Version existingVersion = new Version(0, 2); + doReturn(existingVersion).when(versioningManagerMcok).undoCheckout( + VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1_id, USER1); + + vendorLicenseManager.undoCheckout(vlm1_id, USER1); + + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id, existingVersion); + } + + @Test + public void testCheckin() { + + doReturn(VERSION10).when(vendorLicenseFacadeMcok).checkin(vlm1_id, USER1); + + vendorLicenseManager.checkin(vlm1_id, USER1); + verify(activityLogManagerMcok).addActionLog(activityLogEntityArg.capture(), eq(USER1)); + ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); + Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor() + 1)); + verify(vendorLicenseFacadeMcok).checkin(vlm1_id, USER1); + + } + + @Test + public void testSubmit() { + + doReturn(VERSION10).when(vendorLicenseFacadeMcok).submit(vlm1_id, USER1); + + vendorLicenseManager.submit(vlm1_id, USER1); + verify(activityLogManagerMcok).addActionLog(activityLogEntityArg.capture(), eq(USER1)); + ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); + Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor())); + verify(vendorLicenseFacadeMcok).submit(vlm1_id, USER1); + + } + + @Test + public void testListWhenNone() { + doReturn(new HashMap<>()).when(versioningManagerMcok).listEntitiesVersionInfo + (VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, USER1, VersionableEntityAction.Read); + Collection vlms = vendorLicenseManager.listVendorLicenseModels + (null, USER1); + Assert.assertEquals(vlms.size(), 0); + } + + @Test + public void testList() { + + Map vlmsTobeReturned = new HashMap<>(); + + VersionInfo versionInfo1 = new VersionInfo(); + versionInfo1.setActiveVersion(VERSION01); + vlmsTobeReturned.put(vlm1_id, versionInfo1); + + VersionInfo versionInfo2 = new VersionInfo(); + versionInfo2.setActiveVersion(VERSION10); + vlmsTobeReturned.put(vlm2_id, versionInfo2); + + doReturn(vlmsTobeReturned).when(versioningManagerMcok).listEntitiesVersionInfo + (VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, USER1, VersionableEntityAction.Read); + + VendorLicenseModelEntity vlm1 = new VendorLicenseModelEntity(vlm1_id, VERSION01); + vlm1.setWritetimeMicroSeconds(8L); + doReturn(vlm1).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class)); + + Collection vlms = vendorLicenseManager.listVendorLicenseModels + (null, USER1); + Assert.assertEquals(vlms.size(), 2); + } + + @Test + public void testListFinalsWhenNone() { + + Map vspsTobeReturned = new HashMap<>(); + + VersionInfo versionInfo1 = new VersionInfo(); + versionInfo1.setActiveVersion(VERSION01); + vspsTobeReturned.put(vlm1_id, versionInfo1); + + VersionInfo versionInfo2 = new VersionInfo(); + versionInfo2.setActiveVersion(VERSION10); + vspsTobeReturned.put(vlm2_id, versionInfo2); + + doReturn(vspsTobeReturned).when(versioningManagerMcok).listEntitiesVersionInfo + (VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, USER1, VersionableEntityAction.Read); + + Collection vlms = vendorLicenseManager.listVendorLicenseModels + (VersionStatus.Final.name(), USER1); + Assert.assertEquals(vlms.size(), 0); + } + + @Test + public void testListFinals() { + Map vlmsTobeReturned = new HashMap<>(); + + VersionInfo versionInfo1 = new VersionInfo(); + versionInfo1.setActiveVersion(VERSION01); + vlmsTobeReturned.put(vlm1_id, versionInfo1); + + VersionInfo versionInfo2 = new VersionInfo(); + + versionInfo2.setActiveVersion(new Version(1, 3)); + versionInfo2.setLatestFinalVersion(VERSION10); + vlmsTobeReturned.put(vlm2_id, versionInfo2); + + doReturn(vlmsTobeReturned).when(versioningManagerMcok).listEntitiesVersionInfo + (VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, USER1, VersionableEntityAction.Read); + + VendorLicenseModelEntity vlm1 = new VendorLicenseModelEntity(vlm1_id, VERSION01); + vlm1.setWritetimeMicroSeconds(8L); + doReturn(vlm1).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class)); + + Collection vlms = vendorLicenseManager.listVendorLicenseModels + (VersionStatus.Final.name(), USER1); + + Assert.assertEquals(vlms.size(), 1); + } + + @Test + public void testCreate() { + + VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01); + + doReturn(vlmEntity).when(vendorLicenseFacadeMcok).createVendorLicenseModel(vlmEntity, USER1); + + vendorLicenseManager.createVendorLicenseModel(vlmEntity, USER1); + + verify(vendorLicenseFacadeMcok).createVendorLicenseModel(vlmEntity, USER1); + verify(activityLogManagerMcok).addActionLog(activityLogEntityArg.capture(), eq(USER1)); + ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); + Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); + Assert.assertTrue(activityLogEntity.isSuccess()); + + } + + @Test + public void testUpdate() { + + VendorLicenseModelEntity existingVlm = new VendorLicenseModelEntity(); + existingVlm.setVersion(VERSION01); + existingVlm.setId(vlm1_id); + existingVlm.setIconRef("icon"); + existingVlm.setVendorName("VLM1"); + existingVlm.setDescription("decription"); + + VersionInfo versionInfo = new VersionInfo(); + versionInfo.setActiveVersion(VERSION01); + + doReturn(versionInfo).when(vendorLicenseManager).getVersionInfo(existingVlm.getId(), + VersionableEntityAction.Write, USER1); + + doReturn(VERSION01).when(vendorLicenseManager).resloveVersion(vlm1_id,null, versionInfo, USER1); + + doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm); + + VendorLicenseModelEntity updatedVlm = new VendorLicenseModelEntity(); + updatedVlm.setVersion(VERSION01); + updatedVlm.setId(vlm1_id); + updatedVlm.setIconRef("icon"); + updatedVlm.setVendorName("VLM1_updated"); + updatedVlm.setDescription("decription"); + + doNothing().when(vendorLicenseManager) + .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, + existingVlm.getVendorName(), updatedVlm.getVendorName()); + + existingVlm.setWritetimeMicroSeconds(8L); + + doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class)); + + vendorLicenseManager.updateVendorLicenseModel(updatedVlm, USER1); + + verify(vendorLicenseModelDaoMcok).update(updatedVlm); + verify(vendorLicenseFacadeMcok).updateVlmLastModificationTime(vlm1_id, VERSION01); + } + + @Test + public void testGetVendorLicenseModel(){ + vendorLicenseManager.getVendorLicenseModel(vlm1_id,VERSION01,USER1); + verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id,VERSION01,USER1); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testDeleteVLMUnsupportedOperation() { + vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, USER1); + } + + +// @Test(expectedExceptions = CoreException.class) +// public void testGetNonExistingVersion_negative() { +// Version notExistversion = new Version(43, 8); +// doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class)); +// vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion, USER1); +// } + +} \ No newline at end of file -- cgit 1.2.3-korg