diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test')
7 files changed, 1652 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/ArtifactTestUtils.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/ArtifactTestUtils.java new file mode 100644 index 0000000000..60fe06a23e --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/ArtifactTestUtils.java @@ -0,0 +1,252 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; +import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; +import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +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.openecomp.core.utilities.CommonMethods; +import org.testng.annotations.BeforeMethod; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE; + +public class ArtifactTestUtils { + + protected static final Version VERSION01 = new Version(0, 1); + protected static final String USER1 = "baseTest_TestUser1"; + protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl(); + protected static VendorSoftwareProductManager vendorSoftwareProductManager = new VendorSoftwareProductManagerImpl(); + protected static VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance().createInterface(); + private static final VersioningManager versioningManager = org.openecomp.sdc.versioning.VersioningManagerFactory + .getInstance().createInterface(); + protected static VendorLicenseArtifactsService vendorLicenseArtifactsService = VendorLicenseArtifactServiceFactory + .getInstance().createInterface(); + + protected static Version currVersion; + + protected String vlm1Id; + protected String vlm2Id; + + protected String ep11Id; + protected String ep12Id; + protected String lkg11Id; + protected String lkg12Id; + protected String lkg13Id; + protected String fg11Id; + protected String fg12Id; + protected String la11Id; + + protected String ep21Id; + protected String ep22Id; + protected String lkg21Id; + protected String lkg22Id; + protected String fg21Id; + protected String fg22Id; + protected String la21Id; + protected String la22Id; + + protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg11; + protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg12; + protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep11; + protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep12; + protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg11; + protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg12; + protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg13; + + protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg21; + protected org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg22; + protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep21; + protected org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep22; + protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg21; + protected org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg22; + + protected VspDetails vspDetails; + protected VspDetails vsp2; + + + @BeforeMethod + public void setUp() { + vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest.createVendorLicenseModel("vlm1 name" + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), USER1).getId(); + vlm2Id = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest.createVendorLicenseModel("vlm2 name" + CommonMethods.nextUuId(), "vlm2Id desc", "icon2"), USER1).getId(); + + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide); + + ep11 = EntitlementPoolTest.createEntitlementPool(vlm1Id, VERSION01, "EP1_" + CommonMethods.nextUuId(), "EP1 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc1", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func1", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku1"); + ep11Id = vendorLicenseManager.createEntitlementPool(ep11, USER1).getId(); + ep12 = EntitlementPoolTest.createEntitlementPool(vlm1Id, VERSION01, "EP2_" + CommonMethods.nextUuId(), "EP2 dec", 70, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Other, "e metric2", "inc2", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Average, null, opScopeChoices, "op scope2", org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Other, "time2", "sku2"); + ep12Id = vendorLicenseManager.createEntitlementPool(ep12, USER1).getId(); + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>(); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + + lkg11 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG1", "LKG1 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + lkg11Id = vendorLicenseManager.createLicenseKeyGroup(lkg11, USER1).getId(); + lkg11.setId(lkg11Id); + + lkg12 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG2", "LKG2 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Unique, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + lkg12Id = vendorLicenseManager.createLicenseKeyGroup(lkg12, USER1).getId(); + lkg12.setId(lkg11Id); + + lkg13 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm1Id, VERSION01, "LKG3", "LKG3 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Universal, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + lkg13Id = vendorLicenseManager.createLicenseKeyGroup(lkg13, USER1).getId(); + lkg13.setId(lkg13Id); + + fg11 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", CommonMethods.toSingleElementSet(ep11Id), CommonMethods.toSingleElementSet(lkg11Id)); + fg11Id = vendorLicenseManager.createFeatureGroup(fg11, USER1).getId(); + + fg12 = LicenseAgreementTest.createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc", CommonMethods.toSingleElementSet(ep12Id), CommonMethods.toSingleElementSet(lkg12Id)); + fg12Id = vendorLicenseManager.createFeatureGroup(fg12, USER1).getId(); + + + String requirementsAndConstrains1 = "Requirements And Constraints1"; + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la1 = LicenseAgreementTest.createLicenseAgreement(vlm1Id, VERSION01, null, "LA1", "LA1 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg11Id); + la11Id = vendorLicenseManager.createLicenseAgreement(la1, USER1).getId(); + + List<String> fgs = new ArrayList<>(); + fgs.add(fg11Id); + createTwoFinalVersionsForVLM(vlm1Id); + VersionInfo versionInfo = vendorLicenseFacade.getVersionInfo(vlm1Id, VersionableEntityAction.Read, ""); + vspDetails = createVspDetails(null, null, "VSP1_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName", vlm1Id, "icon", "category", "subCategory", la11Id, fgs); + + List<Version> finalVersions = versionInfo.getFinalVersions(); + Version finalVersion = finalVersions.get(1); + + vspDetails.setVlmVersion(finalVersion); + + vspDetails = vendorSoftwareProductManager.createNewVsp(vspDetails, USER1); + + } + + private void createTwoFinalVersionsForVLM(String vlm1Id) { + versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1"); + versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1); + versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1"); + vendorLicenseFacade.submit(vlm1Id, USER1); + versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1); + versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc2"); + vendorLicenseFacade.submit(vlm1Id, USER1); + + } + + protected void createThirdFinalVersionForVLMChangeEpLKGInSome(String vlm1Id, org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep, org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity lkg) { + versioningManager.checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1); + vendorLicenseManager.updateEntitlementPool(ep, USER1); + vendorLicenseManager.updateLicenseKeyGroup(lkg, USER1); + versioningManager.checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm1Id, USER1, "desc1"); + vendorLicenseFacade.submit(vlm1Id, USER1); + + } + + + protected void setVlm2FirstVersion() { + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide); + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>(); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + + ep21 = EntitlementPoolTest.createEntitlementPool(vlm2Id, VERSION01, "EP21", "EP21 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc21", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func21", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku21"); + ep21Id = vendorLicenseManager.createEntitlementPool(ep21, USER1).getId(); + + lkg21 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm2Id, VERSION01, "LKG21", "LKG21 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + lkg21Id = vendorLicenseManager.createLicenseKeyGroup(lkg21, USER1).getId(); + lkg21.setId(lkg21Id); + + fg21 = LicenseAgreementTest.createFeatureGroup(vlm2Id, VERSION01, "fg21", "FG21", "FG21 desc", CommonMethods.toSingleElementSet(ep21Id), CommonMethods.toSingleElementSet(lkg21Id)); + fg21Id = vendorLicenseManager.createFeatureGroup(fg21, USER1).getId(); + + String requirementsAndConstrains1 = "Requirements And Constraints21"; + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la2 = LicenseAgreementTest.createLicenseAgreement(vlm2Id, VERSION01, null, "LA21", "LA21 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg21Id); + la21Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId(); + +// setValuesForVlm(VERSION01, ep21, ep21Id, lkg21, lkg21Id, fg21, fg21Id, la21Id, 1); + + vendorLicenseManager.checkin(vlm2Id, USER1); + currVersion = versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null); + + List<String> fgs = new ArrayList<>(); + fgs.add(fg21Id); + vsp2 = createVspDetails(null, null, "VSP2_" + CommonMethods.nextUuId(), "Test-vsp", "vendorName", vlm2Id, "icon", "category", "subCategory", la21Id, fgs); + vsp2 = vendorSoftwareProductManager.createNewVsp(vsp2, USER1); + } + + protected void setVlm2SecondVersion() { + vendorLicenseManager.checkout(vlm2Id, USER1); + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide); + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>(); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + + ep22 = EntitlementPoolTest.createEntitlementPool(vlm2Id, currVersion, "EP22", "EP22 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc22", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func22", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku22"); + ep22Id = vendorLicenseManager.createEntitlementPool(ep22, USER1).getId(); + + lkg22 = LicenseKeyGroupTest.createLicenseKeyGroup(vlm2Id, currVersion, "LKG22", "LKG22 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + lkg22Id = vendorLicenseManager.createLicenseKeyGroup(lkg22, USER1).getId(); + lkg22.setId(lkg22Id); + + fg22 = LicenseAgreementTest.createFeatureGroup(vlm2Id, currVersion, "fg22", "FG22", "FG22 desc", CommonMethods.toSingleElementSet(ep22Id), CommonMethods.toSingleElementSet(lkg22Id)); + fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId(); + + String requirementsAndConstrains1 = "Requirements And Constraints22"; + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la2 = LicenseAgreementTest.createLicenseAgreement(vlm2Id, currVersion, null, "LA22", "LA22 desc", requirementsAndConstrains1, new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), fg22Id); + la22Id = vendorLicenseManager.createLicenseAgreement(la2, USER1).getId(); + +// setValuesForVlm(currVersion, ep22, ep22Id, lkg22, lkg22Id, fg22, fg22Id, la22Id, 2); + + vendorLicenseManager.checkin(vlm2Id, USER1); + currVersion = versioningManager.submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vlm2Id, USER1, null); + } + + protected static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, String licenseAgreement, List<String> featureGroups) { + VspDetails vspDetails = new VspDetails(id, version); + vspDetails.setName(name); + vspDetails.setDescription(desc); + vspDetails.setIcon(icon); + vspDetails.setCategory(category); + vspDetails.setSubCategory(subCategory); + vspDetails.setVendorName(vendorName); + vspDetails.setVendorId(vlm); + vspDetails.setLicenseAgreement(licenseAgreement); + vspDetails.setFeatureGroups(featureGroups); + return vspDetails; + } + + +} + 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 new file mode 100644 index 0000000000..0c05fee10d --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/EntitlementPoolTest.java @@ -0,0 +1,275 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory; +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.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; + +import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class EntitlementPoolTest { + + 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, + org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit thresholdUnit, + EntitlementMetric entitlementMetricChoice, + String entitlementMetricOther, + String increments, + AggregationFunction aggregationFunctionChoice, + String aggregationFunctionOther, + Set<OperationalScope> operationalScopeChoices, + String operationalScopeOther, + EntitlementTime timeChoice, + String timeOther, String sku) { + EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity(); + entitlementPool.setVendorLicenseModelId(vlmId); + entitlementPool.setVersion(version); + entitlementPool.setName(name); + entitlementPool.setDescription(desc); + entitlementPool.setThresholdValue(threshold); + entitlementPool.setThresholdUnit(thresholdUnit); + entitlementPool + .setEntitlementMetric(new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(entitlementMetricChoice, entitlementMetricOther)); + entitlementPool.setIncrements(increments); + entitlementPool.setAggregationFunction( + new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(aggregationFunctionChoice, aggregationFunctionOther)); + entitlementPool.setOperationalScope( + new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(operationalScopeChoices, operationalScopeOther)); + entitlementPool.setTime(new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(timeChoice, timeOther)); + entitlementPool.setManufacturerReferenceNumber(sku); + 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()); + Assert.assertEquals(actual.getManufacturerReferenceNumber(), + expected.getManufacturerReferenceNumber()); + } + + @BeforeClass + private void init() { + entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface(); + vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest + .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1 dec", "icon1"), + USER1).getId(); + vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest + .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"), + USER1).getId(); + } + + @Test + public void emptyListTest() { + Collection<EntitlementPoolEntity> entitlementPools = + vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1); + Assert.assertEquals(entitlementPools.size(), 0); + } + + @Test(dependsOnMethods = "emptyListTest") + public void createTest() { + ep1Id = testCreate(vlm1Id, EP1_NAME); + + Set<OperationalScope> opScopeChoices; + opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Core); + opScopeChoices.add(OperationalScope.CPU); + opScopeChoices.add(OperationalScope.Network_Wide); + EntitlementPoolEntity ep2 = + createEntitlementPool(vlm1Id, null, EP2_NAME, "EP2 dec", 70, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, + EntitlementMetric.Other, "e metric2", "inc2", AggregationFunction.Average, null, + opScopeChoices, null, EntitlementTime.Other, "time2", "sku2"); + ep2Id = vendorLicenseManager.createEntitlementPool(ep2, USER1).getId(); + ep2.setId(ep2Id); + } + + private String testCreate(String vlmId, String name) { + Set<OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(OperationalScope.Other); + EntitlementPoolEntity ep1 = + createEntitlementPool(vlmId, null, name, EP1_V01_DESC, 80, org.openecomp.sdc.vendorlicense.dao.types.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 org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(EntitlementMetric.Other, "e metric1 updated")); + ep1.setAggregationFunction(new org.openecomp.sdc.vendorlicense.dao.types.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 e) { + Assert.assertEquals(e.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 e) { + Assert.assertEquals(e.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID); + } + } + + @Test(dependsOnMethods = {"testGetOtherUserCandidateVersion_negative"}) + public void testGetCandidateVersion() { + EntitlementPoolEntity ep = new EntitlementPoolEntity(vlm1Id, new Version(0, 2), ep1Id); + ep.setDescription("updated!"); + vendorLicenseManager.updateEntitlementPool(ep, USER2); + + EntitlementPoolEntity actualEp = vendorLicenseManager.getEntitlementPool(ep, USER2); + EntitlementPoolEntity expectedEp = entitlementPoolDao.get(ep); + + Assert.assertEquals(actualEp.getDescription(), ep.getDescription()); + assertEntitlementPoolsEquals(actualEp, expectedEp); + } + + @Test(dependsOnMethods = {"testGetCandidateVersion"}) + public void testGetOldVersion() { + vendorLicenseManager.checkin(vlm1Id, USER2); + EntitlementPoolEntity actualEp = vendorLicenseManager + .getEntitlementPool(new EntitlementPoolEntity(vlm1Id, new Version(0, 1), ep1Id), USER2); + Assert.assertEquals(actualEp.getDescription(), EP1_V01_DESC); + } + + @Test(dependsOnMethods = {"testGetOldVersion"}) + public void listTest() { + Collection<EntitlementPoolEntity> loadedEps = + vendorLicenseManager.listEntitlementPools(vlm1Id, null, USER1); + Assert.assertEquals(loadedEps.size(), 2); + + int existingCounter = 0; + for (EntitlementPoolEntity loadedEp : loadedEps) { + if (ep2Id.equals(loadedEp.getId()) || ep1Id.equals(loadedEp.getId())) { + existingCounter++; + } + } + + Assert.assertEquals(existingCounter, 2); + } + + @Test(dependsOnMethods = {"listTest"}) + public void deleteTest() { + vendorLicenseManager.checkout(vlm1Id, USER1); + EntitlementPoolEntity emptyEp1 = new EntitlementPoolEntity(vlm1Id, null, ep1Id); + vendorLicenseManager.deleteEntitlementPool(emptyEp1, USER1); + + emptyEp1.setVersion(VERSION03); + EntitlementPoolEntity loadedEp1 = entitlementPoolDao.get(emptyEp1); + Assert.assertEquals(loadedEp1, null); + + Collection<EntitlementPoolEntity> loadedEps = + entitlementPoolDao.list(new EntitlementPoolEntity(vlm1Id, VERSION03, null)); + Assert.assertEquals(loadedEps.size(), 1); + Assert.assertEquals(loadedEps.iterator().next().getId(), ep2Id); + } + + @Test(dependsOnMethods = "deleteTest") + public void listOldVersionTest() { + Collection<EntitlementPoolEntity> loadedEps = + vendorLicenseManager.listEntitlementPools(vlm1Id, VERSION01, USER1); + Assert.assertEquals(loadedEps.size(), 2); + } + + @Test(dependsOnMethods = "deleteTest") + public void testCreateWithRemovedName() { + testCreate(vlm1Id, EP1_NAME); + } + + @Test(dependsOnMethods = "deleteTest") + public void testCreateWithExistingNameAfterCheckout_negative() { + testCreateWithExistingName_negative(vlm1Id, EP2_NAME); + } + + private void testCreateWithExistingName_negative(String vlmId, String epName) { + try { + EntitlementPoolEntity ep1 = + createEntitlementPool(vlmId, null, epName, EP1_V01_DESC, 80, org.openecomp.sdc.vendorlicense.dao.types.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 e) { + Assert.assertEquals(e.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 new file mode 100644 index 0000000000..c2381dd2f3 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/FeatureGroupTest.java @@ -0,0 +1,202 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.common.errors.CoreException; +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.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.*; + +public class FeatureGroupTest { + 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 = org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory + .getInstance().createInterface(); + + + @Test + public void testListFeatureGroups() throws Exception { + String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest.createVendorLicenseModel("vlmId_" + CommonMethods.nextUuId(), "vlm2Id desc", "icon2"), USER1).getId(); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg22 = LicenseAgreementTest.createFeatureGroup(vlmId, VERSION01, "fg2", "FG2", "FG2 desc", null, null); + String fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId(); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg33 = LicenseAgreementTest.createFeatureGroup(vlmId, VERSION01, "fg3", "FG3", "FG3 desc", null, null); + String fg33Id = vendorLicenseManager.createFeatureGroup(fg33, USER1).getId(); + + Collection<org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity> featureGroupEntities = vendorLicenseManager.listFeatureGroups(vlmId, null, USER1); + + Assert.assertEquals(featureGroupEntities.size(), 2); + Set<String> actualIds = new HashSet<>(); + for (org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity featureGroupEntity : featureGroupEntities) { + actualIds.add(featureGroupEntity.getId()); + } + + Set<String> 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<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide); + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity + ep = EntitlementPoolTest.createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc1", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func1", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku1"); + String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId(); + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>(); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity + lkg = LicenseKeyGroupTest.createLicenseKeyGroup(vlmId, VERSION01, "LKG1", "LKG1 dec", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.One_Time, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId(); + lkg.setId(lkgId); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg1 = createFGForTest(vlmId, "created" + CommonMethods.nextUuId(), Collections.singleton(epId), Collections.singleton(lkgId)); + org.openecomp.sdc.vendorlicense.dao.types.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 { + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + created = LicenseAgreementTest.createFeatureGroup(vlmId, null, "created", "created", "created desc", Collections.emptySet(), Collections.emptySet()); + vendorLicenseManager.createFeatureGroup(created, USER1); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + } + + private org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity createFGForTest(String vlmId, String fgName, Set<String> epIds, Set<String> lkgIds) { + org.openecomp.sdc.vendorlicense.dao.types.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(); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg5 = LicenseAgreementTest.createFeatureGroup(vlmId, VERSION01, "id" + CommonMethods.nextUuId(), "created" + CommonMethods.nextUuId(), "created desc", null, null); + vendorLicenseManager.createFeatureGroup(fg5, USER1).getId(); + + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity + epToAdd = EntitlementPoolTest.createEntitlementPool(vlmId, VERSION01, "epToAdd", "epToAdd dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc1", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func1", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku1"); + String epToAddId = vendorLicenseManager.createEntitlementPool(epToAdd, USER1).getId(); + + vendorLicenseManager.updateFeatureGroup(fg5, null, null, CommonMethods.toSingleElementSet(epToAddId), null, USER1); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel + updatedFG = vendorLicenseManager.getFeatureGroupModel(fg5, USER1); + Set<org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity> updatedEPs = updatedFG.getEntitlementPools(); + + epToAdd.setReferencingFeatureGroups(CommonMethods.toSingleElementSet(fg5.getId())); + + Assert.assertEquals(updatedEPs.size(), 1); + for (org.openecomp.sdc.vendorlicense.dao.types.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<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoicesLKG = new HashSet<>(); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.CPU); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.VM); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Availability_Zone); + opScopeChoicesLKG.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity + lkg = LicenseKeyGroupTest.createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg desc", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Unique, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId(); + lkg.setId(lkgId); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity + lkg_1 = LicenseKeyGroupTest.createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg_1 desc", org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType.Unique, new org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther<>(opScopeChoicesLKG, null)); + String lkgId_1 = vendorLicenseManager.createLicenseKeyGroup(lkg_1, USER1).getId(); + lkg.setId(lkgId); + + Set<org.openecomp.sdc.vendorlicense.dao.types.OperationalScope> opScopeChoices = new HashSet<>(); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Other); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Data_Center); + opScopeChoices.add(org.openecomp.sdc.vendorlicense.dao.types.OperationalScope.Network_Wide); + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity + ep = EntitlementPoolTest.createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80, org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit.Absolute, org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric.Core, null, "inc1", org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction.Other, "agg func1", opScopeChoices, null, org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime.Hour, null, "sku1"); + String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId(); + + Set<String> lkgs = new HashSet<>(); + lkgs.add(lkgId); + lkgs.add(lkgId_1); + + org.openecomp.sdc.vendorlicense.dao.types.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); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel + featureGroup = vendorLicenseManager.getFeatureGroupModel(fg, USER1); + Set<org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity> licenseKeyGroups = featureGroup.getLicenseKeyGroups(); + Assert.assertEquals(licenseKeyGroups.size(), 1); + List<String> lkgIds = new ArrayList<>(); + for (org.openecomp.sdc.vendorlicense.dao.types.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(); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg1 = createFGForTest(vlmId, "new", Collections.emptySet(), Collections.emptySet()); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + fg2 = createFGForTest(vlmId, "newer", Collections.emptySet(), Collections.emptySet()); + Collection<org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity> 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); + + + } + + +}
\ No newline at end of file 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 new file mode 100644 index 0000000000..f68f84ec0a --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseAgreementTest.java @@ -0,0 +1,218 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory; +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.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +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 org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao featureGroupDao; + private static org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao licenseAgreementDao; + + private static String vlm1Id; + private static String vlm2Id; + private static String la1Id; + private static String la2Id; + + public static org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity createLicenseAgreement(String vlmId, Version version, + String id, String name, String desc, + String requirementsAndConstrains, + org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<LicenseTerm> term, + String... fgIds) { + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la = new org.openecomp.sdc.vendorlicense.dao.types.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 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id, + String name, String description, + Set<String> entitlementPoolIds, + Set<String> licenseKeyGroupIds) { + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.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 = org.openecomp.sdc.vendorlicense.dao.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) { + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg1 = + createFeatureGroup(vlmId, VERSION01, "fg11", "FG1", "FG1 desc", null, null); + featureGroupDao.create(fg1); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la1 = createLicenseAgreement(vlmId, VERSION01, null, name, "LA1 desc", + "RequirementsAndConstrains1", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg11"); + la1 = vendorLicenseManager.createLicenseAgreement(la1, USER1); + String la1Id = la1.getId(); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 = licenseAgreementDao.get(la1); + Assert.assertTrue(loadedLa1.equals(la1)); + return la1Id; + } + + @Test(dependsOnMethods = {"createLicenseAgreementTest"}) + public void testCreateWithExistingName_negative() { + try { + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity la1 = + createLicenseAgreement(vlm1Id, VERSION01, null, LA1_NAME, "LA1 desc", + "RequirementsAndConstrains1", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), + "fg11"); + vendorLicenseManager.createLicenseAgreement(la1, USER1); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + } + + @Test(dependsOnMethods = {"createLicenseAgreementTest"}) + public void testCreateWithExistingNameUnderOtherVlm() { + testCreate(vlm2Id, LA1_NAME); + } + + @Test(dependsOnMethods = {"testCreateWithExistingName_negative"}) + public void updateLicenseAgreementTest() { + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg2 = + createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc", null, null); + featureGroupDao.create(fg2); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg3 = + createFeatureGroup(vlm1Id, VERSION01, "fg3", "FG3", "FG3 desc", null, null); + featureGroupDao.create(fg3); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity la1 = + licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); + la1.setDescription("LA1 desc updated"); + la1.setLicenseTerm(new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Other, "bla bla term")); + la1.getFeatureGroupIds().add("fg2"); + la1.getFeatureGroupIds().add("fg3"); + la1.getFeatureGroupIds().remove("fg11"); + + Set<String> addedFeatureGroupIds = new HashSet<>(); + addedFeatureGroupIds.add("fg2"); + addedFeatureGroupIds.add("fg3"); + + Set<String> removedFeatureGroupIds = new HashSet<>(); + removedFeatureGroupIds.add("fg11"); + + vendorLicenseManager + .updateLicenseAgreement(la1, addedFeatureGroupIds, removedFeatureGroupIds, USER1); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 = + licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); + Assert.assertTrue(loadedLa1.equals(la1)); + + } + + @Test(dependsOnMethods = {"updateLicenseAgreementTest"}) + public void listLicenseAgreementsTest() { + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + la2 = createLicenseAgreement(vlm1Id, VERSION01, null, "LA2", "LA2 desc", + "RequirementsAndConstrains2", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg2"); + la2 = vendorLicenseManager.createLicenseAgreement(la2, USER1); + la2Id = la2.getId(); + + Collection<org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity> loadedLas = + vendorLicenseManager.listLicenseAgreements(vlm1Id, null, USER1); + Assert.assertEquals(loadedLas.size(), 2); + boolean la2Exists = false; + for (org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa : loadedLas) { + if (la2Id.equals(loadedLa.getId())) { + Assert.assertTrue(loadedLa.equals(la2)); + la2Exists = true; + } + } + + Assert.assertTrue(la2Exists); + } + + @Test(dependsOnMethods = {"listLicenseAgreementsTest"}) + public void featureGroupDeletedLicenseAgreementUpdated() { + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity licenseAgreement = + createLicenseAgreement(vlm1Id, VERSION01, "laId", "LA2", "LA2 desc", + "RequirementsAndConstrains2", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>( + org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg2"); + licenseAgreementDao.create(licenseAgreement); + String featureGroupId = "FeatureGroupId"; + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity created = + createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", null, null); + featureGroupDao.create(created); + featureGroupDao.addReferencingLicenseAgreement(created, licenseAgreement.getId()); + + vendorLicenseManager.deleteFeatureGroup(created, USER1); + org.openecomp.sdc.vendorlicense.dao.types.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, la1Id, USER1); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 = + licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id)); + Assert.assertEquals(loadedLa1, null); + + Collection<org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity> loadedLas = + licenseAgreementDao.list(new org.openecomp.sdc.vendorlicense.dao.types.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 new file mode 100644 index 0000000000..15b179b9c6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LicenseKeyGroupTest.java @@ -0,0 +1,162 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType; +import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class LicenseKeyGroupTest { + + public static final String LKG1_NAME = "LKG1 name"; + private static final Version VERSION01 = new Version(0, 1); + 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> 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; + } + + @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<OperationalScope> 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 e) { + Assert.assertEquals(e.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<OperationalScope> 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<OperationalScope> 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<LicenseKeyGroupEntity> 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<LicenseKeyGroupEntity> 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/VendorLicenseModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java new file mode 100644 index 0000000000..c2a8d14c01 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseModelTest.java @@ -0,0 +1,402 @@ +package org.openecomp.sdc.vendorlicense; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl; +import org.openecomp.core.util.UniqueValueUtil; + +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 org.openecomp.sdc.versioning.dao.types.Version + VERSION01 = new org.openecomp.sdc.versioning.dao.types.Version(0, 1); + private static final org.openecomp.sdc.versioning.dao.types.Version + VERSION02 = new org.openecomp.sdc.versioning.dao.types.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 org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao vendorLicenseModelDao = + org.openecomp.sdc.vendorlicense.dao.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() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity vlm1 = createVendorLicenseModel(VLM1_NAME, "VLM1 dec", "icon1"); + String vlmId = vendorLicenseManager.createVendorLicenseModel(vlm1, USER1).getId(); + + vlm1.setVersion(VERSION01); + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity loadedVlm1 = vendorLicenseModelDao.get(vlm1); + Assert.assertTrue(loadedVlm1.equals(vlm1)); + return vlmId; + } + + public static org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity createVendorLicenseModel(String name, String desc, + String icon) { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity + vendorLicenseModel = new org.openecomp.sdc.vendorlicense.dao.types.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(); + } + + @Test(dependsOnMethods = {"createTest"}) + public void testCreateWithExistingVendorName_negative() { + try { + vendorLicenseManager + .createVendorLicenseModel(createVendorLicenseModel(VLM1_NAME, "VLM1 dec", "icon1"), + USER1); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + } + + @Test(dependsOnMethods = {"testCreateWithExistingVendorName_negative"}) + public void updateTest() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity + expectedVlm1 = new org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity(vlm1Id, VERSION01); + expectedVlm1.setVendorName("VLM1 updated"); + expectedVlm1.setDescription("VLM1 dec updated"); + expectedVlm1.setIconRef("icon1 updated"); + vendorLicenseManager.updateVendorLicenseModel(expectedVlm1, USER1); + + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity actualVlm1 = + vendorLicenseModelDao.get(new org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity(vlm1Id, VERSION01)); + Assert.assertTrue(actualVlm1.equals(expectedVlm1)); + } + + @Test(dependsOnMethods = {"updateTest"}) + public void testUpdateWithSimilarVendorName() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity + expectedVlm1 = new org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity(vlm1Id, VERSION01); + expectedVlm1.setVendorName("vlm1 UPDATED"); + vendorLicenseManager.updateVendorLicenseModel(expectedVlm1, USER1); + + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity actualVlm1 = + vendorLicenseModelDao.get(new org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity(vlm1Id, VERSION01)); + Assert.assertTrue(actualVlm1.equals(expectedVlm1)); + } + + @Test(dependsOnMethods = {"updateTest"}) + public void testCreateWithRemovedVendorName() { + testCreate(); + } + + @Test(dependsOnMethods = {"updateTest"}) + public void getTest() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity expectedVlm1 = + vendorLicenseModelDao.get(new org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity(vlm1Id, VERSION01)); + org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel actualVlm1 = + vendorLicenseManager.getVendorLicenseModel(vlm1Id, null, USER1); + + Assert.assertTrue(actualVlm1.getVendorLicenseModel().equals(expectedVlm1)); + Assert.assertEquals(actualVlm1.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(actualVlm1.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(actualVlm1.getVersionInfo().getLockingUser(), USER1); + } + + @Test(dependsOnMethods = {"getTest"}) + public void listTest() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity vlm2 = createVendorLicenseModel("VLM2", "VLM2 dec", "icon2"); + vlm2Id = vendorLicenseManager.createVendorLicenseModel(vlm2, USER1).getId(); + vlm2.setId(vlm2Id); + + Collection<org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel> loadedVlms = + vendorLicenseManager.listVendorLicenseModels(null, USER1); + boolean vlm1Exists = false; + boolean vlm2Exists = false; + for (org.openecomp.sdc.vendorlicense.types.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<org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel> loadedVlms = + vendorLicenseManager.listVendorLicenseModels( + org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1); + boolean vlm1Exists = false; + boolean vlm2Exists = false; + for (org.openecomp.sdc.vendorlicense.types.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<VendorLicenseModelEntity> 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); + + org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel versionedVlm2 = + vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER1); + Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available); + Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"checkinTest"}) + public void checkoutTest() { + vendorLicenseManager.checkout(vlm2Id, USER2); + + org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel versionedVlm2 = + vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER2); + Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION02); + Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.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(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(versionedVlm2.getVersionInfo().getLockingUser(), USER2); + } + + @Test(dependsOnMethods = {"checkoutTest"}) + public void undoCheckoutTest() { + vendorLicenseManager.undoCheckout(vlm2Id, USER2); + + org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel versionedVlm2 = + vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER2); + Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available); + Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"undoCheckoutTest"}, expectedExceptions = CoreException.class) + public void submitUncompletedVlmNegativeTest() { + vendorLicenseManager.submit(vlm2Id, USER2); + } + + @Test(dependsOnMethods = {"submitUncompletedVlmNegativeTest"}, + expectedExceptions = CoreException.class) + public void submitUncompletedVlmMissingFGNegativeTest() { + vendorLicenseManager.checkout(vlm2Id, USER2); + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + licenseAgreement = new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm2Id, null, null); + org.openecomp.sdc.vendorlicense.dao.types.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); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm2Id, null, null); + featureGroup = vendorLicenseManager.createFeatureGroup(featureGroup, USER2); + fg1Id = featureGroup.getId(); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel licenseAgreementModel = + vendorLicenseManager.getLicenseAgreementModel(vlm2Id, null, laId, USER2); + Set<String> 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); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm2Id, null, null); + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity entitlementPool = vendorLicenseManager + .createEntitlementPool(new org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity(vlm2Id, null, null), USER2); + featureGroup.getEntitlementPoolIds().add(entitlementPool.getId()); + featureGroup = vendorLicenseManager.createFeatureGroup(featureGroup, USER2); + fg2Id = featureGroup.getId(); + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel licenseAgreementModel = + vendorLicenseManager.getLicenseAgreementModel(vlm2Id, null, laId, USER2); + Set<String> 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); + + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity entitlementPool = vendorLicenseManager + .createEntitlementPool(new org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity(vlm2Id, null, null), USER2); + Set<String> epSetId = new HashSet<>(); + epSetId.add(entitlementPool.getId()); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm2Id, null, fg1Id); + featureGroup.getEntitlementPoolIds().add(entitlementPool.getId()); + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel featureGroupModel = + vendorLicenseManager.getFeatureGroupModel(featureGroup, USER2); + + vendorLicenseManager + .updateFeatureGroup(featureGroupModel.getFeatureGroup(), null, null, epSetId, null, USER2); + vendorLicenseManager.checkin(vlm2Id, USER2); + vendorLicenseManager.submit(vlm2Id, USER2); + + org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel versionedVlm2 = + vendorLicenseManager.getVendorLicenseModel(vlm2Id, null, USER1); + Assert.assertEquals(versionedVlm2.getVersionInfo().getActiveVersion(), new org.openecomp.sdc.versioning.dao.types.Version(1, 0)); + Assert.assertEquals(versionedVlm2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Final); + Assert.assertNull(versionedVlm2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"submitTest"}) + public void listFinalVersionWhenOneTest() { + Collection<org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel> loadedVlms = + vendorLicenseManager.listVendorLicenseModels( + org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1); + boolean vlm2Exists = false; + for (org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel loadedVlm : loadedVlms) { + if (vlm2Id.equals(loadedVlm.getVendorLicenseModel().getId())) { + vlm2Exists = true; + Assert.assertEquals(loadedVlm.getVersionInfo().getActiveVersion(), new org.openecomp.sdc.versioning.dao.types.Version(1, 0)); + Assert.assertEquals(loadedVlm.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Final); + Assert.assertNull(loadedVlm.getVersionInfo().getLockingUser()); + break; + } + } + + Assert.assertTrue(vlm2Exists); + } + + @Test(dependsOnMethods = {"listFinalVersionWhenOneTest"}) + public void testVLMListWithModificationTimeDescOrder() { + org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity vlm1 = createVendorLicenseModel("test_vlm1", "desc", "icon"); + vlm3Id = vendorLicenseManager.createVendorLicenseModel(vlm1, USER3).getId(); + + org.openecomp.sdc.vendorlicense.dao.types.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() { + org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity ep = vendorLicenseManager + .createEntitlementPool(new org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity(vlm3Id, null, null), USER3); + + assertVLMInWantedLocationInVSPList(vlm3Id, 0, USER3); + } + + @Test(dependsOnMethods = {"testOldVLMAfterChangeShouldBeInBeginningOfList"}) + public void testAddNewVLMShouldBeInBeginningOfList() { + org.openecomp.sdc.vendorlicense.dao.types.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<org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel> vlmList = + (List<org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel>) 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/licenseartifacts/impl/VendorLicenseArtifactsServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceTest.java new file mode 100644 index 0000000000..778caf3756 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceTest.java @@ -0,0 +1,141 @@ +package org.openecomp.sdc.vendorlicense.licenseartifacts.impl; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.vendorlicense.ArtifactTestUtils; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +public class VendorLicenseArtifactsServiceTest extends ArtifactTestUtils { + private FileContentHandler licenseArtifacts; + + + @Test + public void createVNFArtifact() throws Exception { + Version vlmVersion = vspDetails.getVlmVersion(); + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1); + String actual = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); +// System.out.println("createVnfArtifact = " + actual); + + Assert.assertTrue(actual.contains("type")); + Assert.assertFalse(actual.contains(lkg13Id)); + Assert.assertTrue(actual.contains(OperationalScope.Availability_Zone.toString())); + Assert.assertTrue(actual.contains("vf-id")); + Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE)); + Assert.assertFalse(actual.contains("80.0")); + Assert.assertTrue(actual.contains("80")); + + } + + @Test + public void createVendorLicenseArtifact() throws Exception { + Version vlmVersion = vspDetails.getVlmVersion(); + + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1); + String actual = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); + +// System.out.println("createVendorLicenseArtifact = " + actual); + Assert.assertFalse(actual.contains(lkg11Id)); + Assert.assertFalse(actual.contains(ep11Id)); + Assert.assertTrue(actual.contains("type")); + Assert.assertTrue(actual.contains(EntitlementMetric.Core.toString())); + Assert.assertTrue(actual.contains("entitlement-pool-list")); + Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE)); + + Assert.assertTrue(actual.contains("vendor-license-model")); + Assert.assertFalse(actual.contains("80.0")); + Assert.assertTrue(actual.contains("80")); + } + + @Test + public void vNFArtifactContainsCurrentVLMVersion() throws IOException { + super.setVlm2FirstVersion(); + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1); + String actual = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); + + Assert.assertTrue(actual.contains(ep21.getVersionUuId())); + } + + @Test + public void vnfArtifactContainsSameIdAsVLMArtifact() throws IOException { + Version vlmVersion = vspDetails.getVlmVersion(); + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1); + String actualVnfArtifact = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); + String actualVendorLicenseArtifact = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); + + String firstLKGUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<license-key-group-uuid>") + 24, actualVnfArtifact.indexOf("<license-key-group-uuid>") + 60); + Assert.assertTrue(actualVendorLicenseArtifact.contains(firstLKGUUID)); + + String firstEPUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 23, actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 60); + Assert.assertTrue(actualVendorLicenseArtifact.contains(firstEPUUID)); + } + + + @Test + public void vNFArtifactContainsPreviousVLMVersionAndNotLatest() throws IOException { + super.setVlm2SecondVersion(); + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1); + String actual = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); + + Assert.assertTrue(actual.contains(lkg21.getVersionUuId())); + Assert.assertTrue(actual.contains(ep21.getVersionUuId())); + Assert.assertFalse(actual.contains(lkg22Id)); + Assert.assertFalse(actual.contains(ep22Id)); + + + Assert.assertTrue(actual.contains("80")); + } + + + @Test + public void onlyAddChangedEntitiesToVendorArtifact() throws IOException { + Version vlmVersion = vspDetails.getVlmVersion(); + + EntitlementPoolEntity updatedEP = ep11; + String updatedNameEP = "updatedNameEP"; + updatedEP.setName(updatedNameEP); + LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity(); + updatedLKG.setId(lkg11Id); + updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId()); + String updateDescLKG = "UpdateDescLKG"; + updatedLKG.setName(lkg11.getName()); + updatedLKG.setDescription(updateDescLKG); + + createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP, updatedLKG); + licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1); + String actual = IOUtils.toString(licenseArtifacts.getFileContent( + org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); +// System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual); + + int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG); + Assert.assertEquals(countUpdatedLKG, 1); + + int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP); + Assert.assertEquals(countUpdatedEp, 1); + + int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>"); + Assert.assertEquals(epOccurrences, 3); + } + + @BeforeClass + public void setUp() { + super.setUp(); + } +} + |