diff options
author | bilal.iqbal <bilal.iqbal@est.tech> | 2019-03-19 19:16:03 +0000 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2019-03-20 08:02:02 +0000 |
commit | 54b96133b33b3bf55e9670ed2a8c89996ac413b9 (patch) | |
tree | 5c1dd673a61938e68fb1f43f6199c847e2f4fe7a /openecomp-be/backend/openecomp-sdc-vendor-license-manager/src | |
parent | d0031501cd81a9046396358f42657f168b5a58a8 (diff) |
Process CSAR
1. Handle Main service Template
2. keep copy of the onboarded package
3. Sonar fixes
Issue-ID: SDC-2153
Issue-ID: SDC-2112
Change-Id: I7f84d5d6d7a4c6eeed317a7ddd19b53272182fd8
Signed-off-by: bilal.iqbal <bilal.iqbal@est.tech>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src')
7 files changed, 83 insertions, 116 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java index 4183f7950c..f27e6c05c4 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java @@ -248,101 +248,73 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) { - entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME - : null) : null); - entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME - : null) : null); - + entitlementPool.setStartDate(getDate(entitlementPool.getStartDate(), EP_POOL_START_TIME)); + entitlementPool.setExpiryDate(getDate(entitlementPool.getExpiryDate(), EP_POOL_EXPIRY_TIME)); validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), entitlementPool.getVendorLicenseModelId()); return vendorLicenseFacade.createEntitlementPool(entitlementPool); } - private void validateCreateDate(String startDate, String expiryDate, - String vendorLicenseModelId) { - LocalDate parsedStartDate = parseLocalDate(startDate); - LocalDate parsedExpiryDate = parseLocalDate(expiryDate); - - - validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate, - vendorLicenseModelId, parsedStartDate, parsedExpiryDate); - - if (startDate != null && expiryDate == null - && parsedStartDate.atStartOfDay().isBefore - (LocalDate.now().atStartOfDay())) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); - } - - if (startDate == null && expiryDate != null) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); - - } + private String getDate(String date, String poolTime){ + return date != null ? (!date.trim().isEmpty() ? date + poolTime: null) : null; } - private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate, - String vendorLicenseModelId, - LocalDate parsedStartDate, - LocalDate parsedExpiryDate) { - if (startDate != null && expiryDate != null - && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) { + private void validateCreateDate(String startDate, String expiryDate, + String vendorLicenseModelId) { + if(isNull(startDate, expiryDate) || isEmpty(startDate, expiryDate) || + isInvalidStartEndDate(startDate, expiryDate)){ throw new CoreException( new InvalidDateErrorBuilder(vendorLicenseModelId) .build()); } } - private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate, - LocalDate parsedExpiryDate) { + private boolean isInvalidStartEndDate(String startDate, String expiryDate) { + LocalDate parsedStartDate = parseLocalDate(startDate); + LocalDate parsedExpiryDate = parseLocalDate(expiryDate); + return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay()) - || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay()) - || parsedExpiryDate.isBefore(parsedStartDate); + || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay()) + || parsedExpiryDate.isBefore(parsedStartDate); } - private static LocalDate parseLocalDate(String date) { - if (date == null || date.isEmpty()) { - return null; - } + private boolean isEmpty(String startDate, String expiryDate) { + return startDate.isEmpty() || expiryDate.isEmpty(); + } + private boolean isNull(String startDate, String expiryDate) { + return startDate == null || expiryDate == null; + } + + private static LocalDate parseLocalDate(String date) { return LocalDate.parse(date, FORMATTER ); } private void validateUpdateDate(String startDate, String expiryDate, String vendorLicenseModelId) { - LocalDate parsedStartDate = parseLocalDate(startDate); - LocalDate parsedExpiryDate = parseLocalDate(expiryDate); - if (startDate != null && expiryDate != null - && (parsedExpiryDate.atStartOfDay() - .isEqual(parsedStartDate.atStartOfDay()) - || parsedExpiryDate.isBefore(parsedStartDate ))) { + if(isNull(startDate, expiryDate) || isEmpty(startDate, expiryDate) + || isInvalidUpdateDate(startDate, expiryDate)){ throw new CoreException( new InvalidDateErrorBuilder(vendorLicenseModelId) .build()); } + } - if (startDate == null && expiryDate != null) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + private boolean isInvalidUpdateDate(String startDate, String expiryDate) { - } + LocalDate parsedStartDate = parseLocalDate(startDate); + LocalDate parsedExpiryDate = parseLocalDate(expiryDate); + + return parsedExpiryDate.atStartOfDay() + .isEqual(parsedStartDate.atStartOfDay()) + || parsedExpiryDate.isBefore(parsedStartDate); } @Override public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) { - entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME - : null) : null); - entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME - : null) : null); - + entitlementPool.setStartDate(getDate(entitlementPool.getStartDate(), EP_POOL_START_TIME)); + entitlementPool.setExpiryDate(getDate(entitlementPool.getExpiryDate(), EP_POOL_EXPIRY_TIME)); validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), entitlementPool.getVendorLicenseModelId()); vendorLicenseFacade.updateEntitlementPool(entitlementPool); 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 986e732410..101ecde4c8 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 @@ -16,6 +16,10 @@ package org.openecomp.sdc.vendorlicense; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -31,11 +35,6 @@ 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.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -82,12 +81,12 @@ public class LimitTest { return limitEntity; } - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ vendorLicenseManagerImpl = null; } 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 index ca242f5810..03be183ab7 100644 --- 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 @@ -17,6 +17,10 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -28,11 +32,6 @@ 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.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -94,13 +93,13 @@ public class EntitlementPoolTest { return entitlementPool; } - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ vendorLicenseManagerImpl = null; } @@ -127,8 +126,7 @@ public class EntitlementPoolTest { } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + - "license model with id vlm1_id has invalid date range.") + @Test(expected = CoreException.class) public void createWithInvalidStartExpiryDateTest() { Set<OperationalScope> opScopeChoices; @@ -146,12 +144,11 @@ public class EntitlementPoolTest { ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); ep2.setVendorLicenseModelId(vlm1_id); vendorLicenseManagerImpl.createEntitlementPool(ep2).getId(); - Assert.fail(); + Assert.fail("Vendor license model with id vlm1_id has invalid date range."); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + - "license model with id vlm1_id has invalid date range.") + @Test(expected = CoreException.class) public void createWithoutStartDateTest() { Set<OperationalScope> opScopeChoices; @@ -168,12 +165,11 @@ public class EntitlementPoolTest { ep2.setExpiryDate(LocalDate.now().plusDays(2L).format(formatter)); ep2.setVendorLicenseModelId(vlm1_id); vendorLicenseManagerImpl.createEntitlementPool(ep2).getId(); - Assert.fail(); + Assert.fail("Vendor license model with id vlm1_id has invalid date range."); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + - "license model with id vlm1_id has invalid date range.") + @Test(expected = CoreException.class) public void createWithSameStartExpiryDateTest() { Set<OperationalScope> opScopeChoices; @@ -191,7 +187,7 @@ public class EntitlementPoolTest { ep2.setExpiryDate(LocalDate.now().format(formatter)); ep2.setVendorLicenseModelId(vlm1_id); vendorLicenseManagerImpl.createEntitlementPool(ep2).getId(); - Assert.fail(); + Assert.fail("Vendor license model with id vlm1_id has invalid date range."); } @Test @@ -214,8 +210,7 @@ public class EntitlementPoolTest { vendorLicenseManagerImpl.updateEntitlementPool(ep2); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + - "license model with id vlm1_id has invalid date range.") + @Test(expected = CoreException.class) public void updateWithInvalidStartExpiryDateTest() { Set<OperationalScope> opScopeChoices; @@ -233,7 +228,7 @@ public class EntitlementPoolTest { ep2.setExpiryDate(LocalDate.now().minusDays(2L).format(formatter)); ep2.setVendorLicenseModelId(vlm1_id); vendorLicenseManagerImpl.updateEntitlementPool(ep2); - Assert.fail(); + Assert.fail("Vendor license model with id vlm1_id has invalid date range."); } 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 index b7636bb514..ca37dcd801 100644 --- 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 @@ -16,6 +16,10 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -28,11 +32,6 @@ import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -87,7 +86,7 @@ public class FeatureGroupTest { private VendorLicenseManagerImpl vendorLicenseManagerImpl; - @AfterMethod + @After public void tearDown(){ vendorLicenseManagerImpl = null; } @@ -114,7 +113,7 @@ public class FeatureGroupTest { return featureGroup; } - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } 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 index 511ebb87d0..722343a4a3 100644 --- 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 @@ -16,6 +16,10 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.*; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; @@ -27,12 +31,11 @@ import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.*; +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.*; @@ -78,12 +81,12 @@ public class LicenseAgreementTest { private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ vendorLicenseManager = null; } 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 index c5076fdf2c..d8e2959464 100644 --- 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 @@ -17,6 +17,10 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -31,11 +35,6 @@ import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Arrays; @@ -73,12 +72,12 @@ public class LicenseKeyGroupTest { @Spy private VendorLicenseManagerImpl vendorLicenseManagerImpl; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ vendorLicenseManagerImpl = null; } 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 index b81c2e805f..e072453421 100644 --- 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 @@ -1,5 +1,8 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.mockito.*; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; @@ -8,9 +11,6 @@ import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -59,12 +59,12 @@ public class VendorLicenseModelTest { private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ vendorLicenseManager = null; } @@ -121,7 +121,7 @@ public class VendorLicenseModelTest { verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01); } - @Test(expectedExceptions = UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testDeleteVLMUnsupportedOperation() { vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017 } |