diff options
author | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
commit | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch) | |
tree | 72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java | |
parent | 451a3400b76511393c62a444f588a4ed15f4a549 (diff) |
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java')
19 files changed, 3983 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentProcessesTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentProcessesTest.java new file mode 100644 index 0000000000..cfc2e111ac --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentProcessesTest.java @@ -0,0 +1,46 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.testng.annotations.BeforeClass; + +public class ComponentProcessesTest extends ProcessesTest { + + @BeforeClass + @Override + protected void init() { +// super.init(); +// +// org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity +// comp11 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null); +// org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData +// compData11 = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData(); +// compData11.setName("c11 name"); +// compData11.setDescription("c11 desc"); +// comp11.setComponentCompositionData(compData11); +// +//// component11Id = vendorSoftwareProductManager.createComponent(comp11, USER1).getId(); +// +// org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity +// comp21 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp2Id, null, null); +// org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData +// compData21 = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData(); +// compData21.setName("c21 name"); +// compData21.setDescription("c21 desc"); +// comp21.setComponentCompositionData(compData21); + +// component21Id = vendorSoftwareProductManager.createComponent(comp21, USER1).getId(); + } + + @Override + public void testCreateWithExistingNameUnderOtherComponent() { +// org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity +// comp12 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null); +// org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData +// compData12 = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData(); +// compData12.setName("c12 name"); +// compData12.setDescription("c12 desc"); +// comp12.setComponentCompositionData(compData12); +// +// String component12Id = vendorSoftwareProductManager.createComponent(comp12, USER1).getId(); +// testCreate(vsp1Id, component12Id); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsTest.java new file mode 100644 index 0000000000..ff33bcb9ee --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsTest.java @@ -0,0 +1,329 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.openecomp.core.utilities.CommonMethods; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; + +public class ComponentsTest { + + private static final String USER1 = "componentsTestUser1"; + private static final String USER2 = "componentsTestUser2"; + private static final Version VERSION01 = new Version(0, 1); + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao + vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + + private static String vsp1Id; + private static String vsp2Id; + private static String comp1Id = "1"; + private static String comp2Id = "2"; + + static org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity createComponent(String vspId, Version version, String compId) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity + componentEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vspId, version, compId); + ComponentData compData = new ComponentData(); + compData.setName(compId + " name"); + compData.setDisplayName(compId + " display name"); + compData.setDescription(compId + " desc"); + componentEntity.setComponentCompositionData(compData); + vendorSoftwareProductDao.createComponent(componentEntity); + return componentEntity; + } + + @BeforeClass + private void init() { + VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp1Id = vsp1.getId(); + + VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp2Id = vsp2.getId(); + } + + @Test + public void testListWhenNone() { + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = + vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1); + Assert.assertEquals(components.size(), 0); + } + + @Test + public void testCreateNonExistingVspId_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity("non existing vsp id", null, null), USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testCreateOnLockedVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null), USER2, + VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER); + } + +/* @Test(dependsOnMethods = "testListWhenNone") + public void testCreate() { + comp1Id = testCreate(vsp1Id); + } + + private String testCreate(String vspId) { + ComponentEntity expected = new ComponentEntity(vspId, null, null); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + expected.setComponentCompositionData(compData); + + ComponentEntity created = vendorSoftwareProductManager.createComponent(expected, USER1); + Assert.assertNotNull(created); + expected.setId(created.getId()); + expected.setVersion(VERSION01); + + ComponentEntity actual = vendorSoftwareProductDao.getComponent(vspId, VERSION01, created.getId()); + + Assert.assertEquals(actual, expected); + return created.getId(); + }*/ + +/* @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingName_negative() { + ComponentEntity component = new ComponentEntity(vsp1Id, null, null); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + component.setComponentCompositionData(compData); + testCreate_negative(component, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + }*/ + +/* @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingNameUnderOtherVsp() { + testCreate(vsp2Id); + }*/ + + @Test + public void testCreateOnUploadVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null), USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + @Test + public void testGetNonExistingComponentId_negative() { + testGet_negative(vsp1Id, null, "non existing component id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, comp1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGet() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity + expected = createComponent(vsp1Id, VERSION01, comp1Id); + testGet(vsp1Id, VERSION01, comp1Id, USER1, expected); + } + + @Test + public void testUpdateNonExistingComponentId_negative() { + testUpdate_negative(vsp1Id, "non existing component id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testUpdateNonExistingVspId_negative() { + testUpdate_negative("non existing vsp id", comp1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testUpdateOnUploadVsp() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, comp1Id); + ComponentData compData = new ComponentData(); + compData.setName(comp1Id + " name"); // no change + compData.setDisplayName(comp1Id + " display name"); // no change + compData.setDescription(comp1Id + " desc updated"); // allowed change + expected.setComponentCompositionData(compData); + + CompositionEntityValidationData validationData = + vendorSoftwareProductManager.updateComponent(expected, USER1); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + expected.setVersion(VERSION01); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity actual = vendorSoftwareProductDao.getComponent(vsp1Id, VERSION01, comp1Id); + Assert.assertEquals(actual, expected); + } + + @Test(dependsOnMethods = {"testUpdateOnUploadVsp"}) + public void testIllegalUpdateOnUploadVsp() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, comp1Id); + ComponentData compData = new ComponentData(); + compData + .setName("comp1 name updated"); // not allowed: changed name + omitted display name + expected.setComponentCompositionData(compData); + + CompositionEntityValidationData validationData = + vendorSoftwareProductManager.updateComponent(expected, USER1); + Assert.assertNotNull(validationData); + Assert.assertEquals(validationData.getErrors().size(), 2); + } + + @Test + public void testListNonExistingVspId_negative() { + testList_negative("non existing vsp id", null, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"}) + public void testCreateWithERemovedName() { + testCreate(vsp1Id); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingComponentId_negative() { + testDelete_negative(vsp1Id, "non existing component id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + }*/ + + @Test(dependsOnMethods = {"testGet"}) + public void testList() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity + createdP2 = createComponent(vsp1Id, VERSION01, comp2Id); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> actual = + vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1); + Assert.assertEquals(actual.size(), 2); + } + + @Test + public void testDeleteNonExistingVspId_negative() { + testDelete_negative("non existing vsp id", comp1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = "testList") + public void testDelete() { + vendorSoftwareProductManager.deleteComponent(vsp1Id, comp1Id, USER1); + ComponentEntity actual = vendorSoftwareProductDao.getComponent(vsp1Id, VERSION01, comp1Id); + Assert.assertNull(actual); + }*/ + + @Test + public void testDeleteOnUploadVsp_negative() { + testDelete_negative(vsp1Id, comp1Id, USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + @Test + public void testDeleteListNonExistingVspId_negative() { + testDeleteList_negative("non existing vsp id", USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = "testDelete") + public void testDeleteList() { + ComponentEntity comp3 = new ComponentEntity(vsp1Id, null, null); + comp3.setName("comp3 name"); + comp3.setDescription("comp3 desc"); + vendorSoftwareProductManager.createComponent(comp3, USER1); + + vendorSoftwareProductManager.deleteComponents(vsp1Id, USER1); + + Collection<ComponentEntity> actual = vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1); + Assert.assertEquals(actual.size(), 0); + }*/ + + @Test + public void testDeleteListOnUploadVsp_negative() { + testDeleteList_negative(vsp1Id, USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + private void testGet(String vspId, Version version, String componentId, String user, + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity expected) { + CompositionEntityResponse<ComponentData> response = + vendorSoftwareProductManager.getComponent(vspId, null, componentId, user); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData(), expected.getComponentCompositionData()); + Assert.assertNotNull(response.getSchema()); + } + + private void testCreate_negative( + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.createComponent(component, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.getComponent(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testUpdate_negative(String vspId, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager + .updateComponent(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vspId, null, componentId), user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testList_negative(String vspId, Version version, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.listComponents(vspId, version, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDeleteList_negative(String vspId, String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteComponents(vspId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteComponent(vspId, componentId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsUploadTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsUploadTest.java new file mode 100644 index 0000000000..0819d89851 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComponentsUploadTest.java @@ -0,0 +1,159 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus; +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.BeforeTest; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class ComponentsUploadTest { + + private static final String USER1 = "vspTestUser1"; + + private static VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static VendorLicenseFacade vendorLicenseFacade = + VendorLicenseFacadeFactory.getInstance().createInterface(); + + private static String vspId = null; + private static Version activeVersion = null; + private static String trapFileName = "MMSC.zip"; + private static String pollFileName = "MNS OAM FW.zip"; + private static String notZipFileName = "notZipFile"; + private static String zipWithFoldersFileName = "zipFileWithFolder.zip"; + private static String emptyZipFileName = "emptyZip.zip"; + private String vlm1Id; + private String componentId; + + @BeforeTest + private void init() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSPTestMib"); + vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon + .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), + USER1).getId(); + VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSPTestMib", "Test-vsp-mib", "vendorName", vlm1Id, "icon", + "category", "subCategory", "123", null), USER1); + + vspId = vspDetails.getId(); + activeVersion = vspDetails.getVersion(); + componentId = createComponent(new ComponentEntity(vspId, activeVersion, null)).getId(); + } + + + @Test + public void testUploadAndFilenamesList() { + InputStream zis1 = getFileInputStream("/validation/zips/various/MMSC.zip"); + InputStream zis2 = getFileInputStream("/validation/zips/various/MNS OAM FW.zip"); + + vendorSoftwareProductManager + .uploadComponentMib(zis1, "MMSC.zip", vspId, componentId, true, USER1); + vendorSoftwareProductManager + .uploadComponentMib(zis2, "MNS OAM FW.zip", vspId, componentId, false, USER1); + + MibUploadStatus mibUploadStatus = + vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1); + Assert.assertEquals(mibUploadStatus.getSnmpTrap(), trapFileName); + Assert.assertEquals(mibUploadStatus.getSnmpPoll(), pollFileName); + } + + @Test(dependsOnMethods = "testUploadAndFilenamesList") + public void testMibsExistentAfterCheckout() throws IOException { + activeVersion = vendorSoftwareProductManager.checkin(vspId, USER1); +// UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, "MMSC.zip"); +// UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, "MNS OAM FW.zip"); + activeVersion = vendorSoftwareProductManager.checkout(vspId, USER1); + + MibUploadStatus mibUploadStatus = + vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1); + Assert.assertNotNull(mibUploadStatus.getSnmpTrap()); + Assert.assertNotNull(mibUploadStatus.getSnmpPoll()); + } + + @Test(dependsOnMethods = "testMibsExistentAfterCheckout") + public void testDeleteFile() { + vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, true, USER1); + vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, false, USER1); + + MibUploadStatus mibUploadStatus = + vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1); + Assert.assertNull(mibUploadStatus.getSnmpTrap()); + Assert.assertNull(mibUploadStatus.getSnmpPoll()); + } + + @Test(dependsOnMethods = "testDeleteFile") + public void testUploadInvalidZip() { + URL url = this.getClass().getResource("/notZipFile"); + + try { + vendorSoftwareProductManager + .uploadComponentMib(url.openStream(), notZipFileName, vspId, componentId, true, USER1); + Assert.fail(); + } catch (Exception e) { +// Assert.assertEquals(e.getMessage(), "MIB uploaded for vendor software product with Id " + vspId + " and version " + activeVersion + " is invalid: Invalid zip file"); + Assert.assertEquals(e.getMessage(), "Invalid zip file"); + } + } + + @Test(dependsOnMethods = "testUploadInvalidZip") + public void testUploadZipWithFolders() { + InputStream zis = getFileInputStream("/vspmanager/zips/zipFileWithFolder.zip"); + + try { + vendorSoftwareProductManager + .uploadComponentMib(zis, zipWithFoldersFileName, vspId, componentId, true, USER1); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals(e.getMessage(), "Zip file should not contain folders"); + } + } + + @Test(dependsOnMethods = "testUploadZipWithFolders") + public void testUploadEmptyZip() { + InputStream zis = getFileInputStream("/vspmanager/zips/emptyZip.zip"); + + try { + vendorSoftwareProductManager + .uploadComponentMib(zis, emptyZipFileName, vspId, componentId, true, USER1); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals(e.getMessage(), "Invalid zip file"); + } + } + + + private InputStream getFileInputStream(String fileName) { + URL url = this.getClass().getResource(fileName); + try { + return url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + + private ComponentEntity createComponent(ComponentEntity component) { + component.setId(CommonMethods.nextUuId()); + vendorSoftwareProductDao.createComponent(component); + return component; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NetworksTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NetworksTest.java new file mode 100644 index 0000000000..2921f19c1b --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NetworksTest.java @@ -0,0 +1,292 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.openecomp.core.utilities.CommonMethods; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; + +public class NetworksTest { + + private static final String USER1 = "networksTestUser1"; + private static final String USER2 = "networksTestUser2"; + private static final Version VERSION01 = new Version(0, 1); + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao + vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + + private static String vsp1Id; + private static String vsp2Id; + private static String networkId = "1"; + + static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity createNetwork(String vspId, Version version, String networkId) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity + networkEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity(vspId, version, networkId); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network + networkData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network(); + networkData.setName(networkId + " name"); + networkData.setDhcp(true); + networkEntity.setNetworkCompositionData(networkData); + vendorSoftwareProductDao.createNetwork(networkEntity); + return networkEntity; + } + + @BeforeClass + private void init() { + VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp1Id = vsp1.getId(); + + VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp2Id = vsp2.getId(); + } + + @Test + public void testListWhenNone() { + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity> networks = + vendorSoftwareProductManager.listNetworks(vsp1Id, null, USER1); + Assert.assertEquals(networks.size(), 0); + } + + @Test + public void testCreateNonExistingVspId_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity("non existing vsp id", null, null), USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testCreateOnLockedVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity(vsp1Id, null, null), USER2, + VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER); + } + +/* @Test(dependsOnMethods = "testListWhenNone") + public void testCreate() { + networkId = testCreate(vsp1Id); + } + + private String testCreate(String vspId) { + NetworkEntity expected = new NetworkEntity(vspId, null, null); + Network networkData = new Network(); + networkData.setName("network1 name"); + networkData.setDhcp(true); + expected.setNetworkCompositionData(networkData); + + + NetworkEntity created = vendorSoftwareProductManager.createNetwork(expected, USER1); + Assert.assertNotNull(created); + expected.setId(created.getId()); + expected.setVersion(VERSION01); + + NetworkEntity actual = vendorSoftwareProductDao.getNetwork(vspId, VERSION01, created.getId()); + + Assert.assertEquals(actual, expected); + return created.getId(); + } + + @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingName_negative() { + NetworkEntity network = new NetworkEntity(vsp1Id, null, null); + Network networkData = new Network(); + networkData.setName("network1 name"); + networkData.setDhcp(true); + network.setNetworkCompositionData(networkData); + testCreate_negative(network, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + }*/ + + @Test + public void testCreateOnUploadVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity(vsp1Id, null, null), USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + /* @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingNameUnderOtherVsp() { + testCreate(vsp2Id); + } + */ + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGetNonExistingNetworkId_negative() { + testGet_negative(vsp1Id, null, "non existing network id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, networkId, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGet() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity + expected = createNetwork(vsp1Id, VERSION01, networkId); + testGet(vsp1Id, VERSION01, networkId, USER1, expected); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testUpdateNonExistingNetworkId_negative() { + testUpdate_negative(vsp1Id, "non existing network id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testUpdateNonExistingVspId_negative() { + testUpdate_negative("non existing vsp id", networkId, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testIllegalUpdateOnUploadVsp() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity(vsp1Id, null, networkId); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network + networkData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network(); + networkData.setName(networkId + " name updated"); + networkData.setDhcp(false); + expected.setNetworkCompositionData(networkData); + + CompositionEntityValidationData validationData = + vendorSoftwareProductManager.updateNetwork(expected, USER1); + Assert.assertNotNull(validationData); + Assert.assertTrue(validationData.getErrors().size() > 0); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testListNonExistingVspId_negative() { + testList_negative("non existing vsp id", null, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + /* + @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"}) + public void testCreateWithERemovedName() { + testCreate(vsp1Id); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingNetworkId_negative() { + testDelete_negative(vsp1Id, "non existing network id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + }*/ + + @Test(dependsOnMethods = {"testGet"}) + public void testList() { + createNetwork(vsp1Id, VERSION01, "2"); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity> actual = + vendorSoftwareProductManager.listNetworks(vsp1Id, null, USER1); + Assert.assertEquals(actual.size(), 2); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingVspId_negative() { + testDelete_negative("non existing vsp id", networkId, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = "testList") + public void testDelete() { + vendorSoftwareProductManager.deleteNetwork(vsp1Id, networkId, USER1); + NetworkEntity actual = vendorSoftwareProductDao.getNetwork(vsp1Id, VERSION01, networkId); + Assert.assertNull(actual); + } + + @Test + public void testDeleteListNonExistingVspId_negative() { + testDeleteList_negative("non existing vsp id", USER1, VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testDelete") + public void testDeleteList() { + NetworkEntity network3 = new NetworkEntity(vsp1Id, null, null); + network3.setName("network3 name"); + network3.setDescription("network3 desc"); + vendorSoftwareProductManager.createNetwork(network3, USER1); + + vendorSoftwareProductManager.deleteNetworks(vsp1Id, USER1); + + Collection<NetworkEntity> actual = vendorSoftwareProductManager.listNetworks(vsp1Id, null, USER1); + Assert.assertEquals(actual.size(), 0); + }*/ + + @Test(dependsOnMethods = "testList") + public void testDeleteOnUploadVsp_negative() { + testDelete_negative(vsp1Id, networkId, USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + private void testGet(String vspId, Version version, String networkId, String user, + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity expected) { + CompositionEntityResponse<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network> response = + vendorSoftwareProductManager.getNetwork(vspId, null, networkId, user); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData(), expected.getNetworkCompositionData()); + Assert.assertNotNull(response.getSchema()); + } + + private void testCreate_negative( + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network, String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.createNetwork(network, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String networkId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.getNetwork(vspId, version, networkId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testUpdate_negative(String vspId, String networkId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.updateNetwork(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity(vspId, null, networkId), user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testList_negative(String vspId, Version version, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.listNetworks(vspId, version, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, String networkId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteNetwork(vspId, networkId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NicsTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NicsTest.java new file mode 100644 index 0000000000..10ea7f7eaf --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NicsTest.java @@ -0,0 +1,346 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData; +import org.openecomp.core.utilities.CommonMethods; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; + +public class NicsTest { + + private static final String USER1 = "nicsTestUser1"; + private static final String USER2 = "nicsTestUser2"; + private static final org.openecomp.sdc.versioning.dao.types.Version + VERSION01 = new org.openecomp.sdc.versioning.dao.types.Version(0, 1); + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao + vendorSoftwareProductDao = + org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory.getInstance().createInterface(); + + private static String vsp1Id; + private static String vsp2Id; + private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network1; + private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network2; + private static String component11Id; + private static String component21Id; + private static String nic1Id = "nic1"; + + static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String compId, String nicId, + String networkId) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + nicEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, version, compId, nicId); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic + nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic(); + nicData.setName(nicId + " name"); + nicData.setDescription(nicId + " desc"); + nicData.setNetworkId(networkId); + nicEntity.setNicCompositionData(nicData); + vendorSoftwareProductDao.createNic(nicEntity); + return nicEntity; + } + + @BeforeClass + private void init() { + vsp1Id = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId(); + network1 = NetworksTest.createNetwork(vsp1Id, VERSION01, "network1"); + component11Id = ComponentsTest.createComponent(vsp1Id, VERSION01, "component11").getId(); + + vsp2Id = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId(); + network2 = NetworksTest.createNetwork(vsp2Id, VERSION01, "network2"); + component21Id = ComponentsTest.createComponent(vsp2Id, VERSION01, "component21").getId(); + } + +/* @Test + public void testCreateNonExistingComponentId_negative() { + testCreate_negative(new NicEntity(vsp1Id, null, "non existing component id", null), USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + }*/ + + @Test + public void testListWhenNone() { + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics = + vendorSoftwareProductManager.listNics(vsp1Id, null, component11Id, USER1); + Assert.assertEquals(nics.size(), 0); + } + + @Test + public void testCreateNonExistingVspId_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity("non existing vsp id", null, component11Id, null), USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testCreateOnLockedVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, null), USER2, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER); + } + +// @Test(dependsOnMethods = "testListWhenNone") +// public void testCreate() { +// nic1Id = testCreate(vsp1Id, component11Id, network1.getId(), network1.getNetworkCompositionData().getName()); +// } + +/* @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingName_negative() { + NicEntity nic = new NicEntity(vsp1Id, null, component11Id, null); + Nic nicData = new Nic(); + nicData.setName("nic1 name"); + nic.setNicCompositionData(nicData); + testCreate_negative(nic, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + }*/ + +// @Test(dependsOnMethods = {"testCreate"}) +// public void testCreateWithExistingNameUnderOtherComponent() { +// ComponentEntity component12 = new ComponentEntity(vsp1Id, null, null); +// ComponentData compData12 = new ComponentData(); +// compData12.setName("comp12 name"); +// compData12.setDescription("comp12 desc"); +// component12.setComponentCompositionData(compData12); +// +// String component12Id = vendorSoftwareProductManager.createComponent(component12, USER1).getId(); +// testCreate(vsp1Id, component12Id, network1.getId(), network1.getNetworkCompositionData().getName()); +// } + +// @Test(dependsOnMethods = {"testCreate"}) +// public void testCreateWithExistingNameUnderOtherVsp() { +// testCreate(vsp2Id, component21Id, network2.getId(), network2.getNetworkCompositionData().getName()); +// } + + @Test + public void testCreateOnUploadVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, null), USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + @Test + public void testGetNonExistingNicId_negative() { + testGet_negative(vsp1Id, null, component11Id, "non existing nic id", USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGetNonExistingComponentId_negative() { + testGet_negative(vsp1Id, null, "non existing component id", nic1Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, component11Id, nic1Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testGet() { + createNic(vsp1Id, VERSION01, component11Id, nic1Id, network1.getId()); + testGet(vsp1Id, VERSION01, component11Id, nic1Id, USER1); + } + + @Test + public void testUpdateNonExistingNicId_negative() { + testUpdate_negative(vsp1Id, component11Id, "non existing nic id", USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testUpdateNonExistingComponentId_negative() { + testUpdate_negative(vsp1Id, "non existing component id", nic1Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testListWhenNone")//"testCreate") + public void testUpdateNonExistingVspId_negative() { + testUpdate_negative("non existing vsp id", component11Id, nic1Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testUpdateOnUploadVsp() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic + nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic(); + nicData.setName(nic1Id + " name"); + nicData.setDescription(nic1Id + " desc updated"); + nicData.setNetworkId(network1.getId()); + expected.setNicCompositionData(nicData); + + CompositionEntityValidationData validationData = + vendorSoftwareProductManager.updateNic(expected, USER1); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + expected.setVersion(VERSION01); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id); + Assert.assertEquals(actual, expected); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testIllegalUpdateOnUploadVsp() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic + nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic(); + nicData.setName(nic1Id + " name updated"); + nicData.setDescription(nic1Id + " desc updated"); + nicData.setNetworkId(network1.getId()); + expected.setNicCompositionData(nicData); + + CompositionEntityValidationData validationData = + vendorSoftwareProductManager.updateNic(expected, USER1); + Assert.assertNotNull(validationData); + Assert.assertTrue(validationData.getErrors().size() > 0); + } + + @Test + public void testListNonExistingComponentId_negative() { + testList_negative(vsp1Id, null, "non existing component id", USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testListNonExistingVspId_negative() { + testList_negative("non existing vsp id", null, component11Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"}) + public void testCreateWithRemovedName() { + testCreate(vsp1Id, component11Id); + } + + @Test + public void testDeleteNonExistingNicId_negative() { + testDelete_negative(vsp1Id, component11Id, "non existing nic id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingComponentId_negative() { + testDelete_negative(vsp1Id, "non existing component id", nic1Id, USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + }*/ + + @Test(dependsOnMethods = {"testGet"}) + public void testList() { + createNic(vsp1Id, VERSION01, component11Id, "nic2", network1.getId()); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> actual = + vendorSoftwareProductManager.listNics(vsp1Id, null, component11Id, USER1); + Assert.assertEquals(actual.size(), 2); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingVspId_negative() { + testDelete_negative("non existing vsp id", component11Id, nic1Id, USER1, + org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } +/* + @Test(dependsOnMethods = "testList") + public void testDelete() { + vendorSoftwareProductManager.deleteNic(vsp1Id, component11Id, nic1Id, USER1); + NicEntity actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id); + Assert.assertNull(actual); + }*/ + + @Test(dependsOnMethods = "testList") + public void testDeleteOnUploadVsp_negative() { + testDelete_negative(vsp1Id, component11Id, nic1Id, USER1, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + private String testCreate(String vspId, String componentId, String networkId, + String networkName) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, null); + + org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic + nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic(); + nicData.setName("nic1 name"); + nicData.setNetworkId(networkId); + //nicData.setNetworkName(networkName); + nicData.setNetworkType(org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType.External); + expected.setNicCompositionData(nicData); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity created = vendorSoftwareProductManager.createNic(expected, USER1); + Assert.assertNotNull(created); + expected.setId(created.getId()); + expected.setVersion(VERSION01); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity actual = + vendorSoftwareProductDao.getNic(vspId, VERSION01, componentId, created.getId()); + + Assert.assertEquals(actual, expected); + + return created.getId(); + } + + private void testGet(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId, + String user) { + CompositionEntityResponse<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic> response = + vendorSoftwareProductManager.getNic(vspId, null, componentId, nicId, user); + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + expected = vendorSoftwareProductDao.getNic(vspId, version, componentId, nicId); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData(), expected.getNicCompositionData()); + Assert.assertNotNull(response.getSchema()); + } + + private void testCreate_negative(org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.createNic(nic, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId, + String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.getNic(vspId, version, componentId, nicId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testUpdate_negative(String vspId, String componentId, String nicId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.updateNic(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, nicId), user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testList_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.listNics(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, String componentId, String nicId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteNic(vspId, componentId, nicId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ProcessesTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ProcessesTest.java new file mode 100644 index 0000000000..8571088be1 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ProcessesTest.java @@ -0,0 +1,473 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +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.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.util.Collection; + +public class ProcessesTest { + + protected static final String USER1 = "processesTestUser1"; + protected static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final String USER2 = "processesTestUser2"; + private static final String ARTIFACT_NAME = "artifact.sh"; + private static final Version VERSION01 = new Version(0, 1); + private static final VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + + protected String vsp1Id; + protected String vsp2Id; + protected String component11Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; + protected String component21Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; + private String p1Id; + private String p2Id; + + @BeforeClass + protected void init() { + VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp1Id = vsp1.getId(); + + VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", null), USER1); + vsp2Id = vsp2.getId(); + } + + @Test + public void testListWhenNone() { + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> processes = + vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1); + Assert.assertEquals(processes.size(), 0); + } + + @Test + public void testCreateNonExistingComponentId_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, "non existing component id", null), USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testCreateNonExistingVspId_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity("non existing vsp id", null, component11Id, null), USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testCreateOnLockedVsp_negative() { + testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null), USER2, + VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER); + } + + @Test(dependsOnMethods = "testListWhenNone") + public void testCreate() { + p1Id = testCreate(vsp1Id, component11Id); + } + + @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingName_negative() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + process = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null); + process.setName("p1 name"); + testCreate_negative(process, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + + @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingNameUnderOtherComponent() { + // This method is implemented in the sub class ComponentProcessesTest, it is here in order to keep the tests sequence down there (using @Test). + } + + @Test(dependsOnMethods = {"testCreate"}) + public void testCreateWithExistingNameUnderOtherVsp() { + testCreate(vsp2Id, component21Id); + } + + @Test + public void testGetNonExistingProcessId_negative() { + testGet_negative(vsp1Id, null, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreate") + public void testGetNonExistingComponentId_negative() { + testGet_negative(vsp1Id, null, "non existing component id", p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreate") + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, component11Id, p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testCreate") + public void testGet() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + actual = testGet(vsp1Id, VERSION01, component11Id, p1Id, USER1); + Assert.assertNull(actual.getArtifactName()); + } + + @Test + public void testUpdateNonExistingProcessId_negative() { + testUpdate_negative(vsp1Id, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreate") + public void testUpdateNonExistingComponentId_negative() { + testUpdate_negative(vsp1Id, "non existing component id", p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreate") + public void testUpdateNonExistingVspId_negative() { + testUpdate_negative("non existing vsp id", component11Id, p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testUpdate() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, p1Id); + expected.setName("p1 name updated"); + expected.setDescription("p1 desc updated"); + + vendorSoftwareProductManager.updateProcess(expected, USER1); + expected.setVersion(VERSION01); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual = + vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id); + Assert.assertEquals(actual, expected); + } + + @Test + public void testListNonExistingComponentId_negative() { + testList_negative(vsp1Id, null, "non existing component id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testListNonExistingVspId_negative() { + testList_negative("non existing vsp id", null, component11Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testGet"}) + public void testList() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + p2 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null); + p2.setName("p2 name"); + p2.setDescription("p2 desc"); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity createdP2 = vendorSoftwareProductManager.createProcess(p2, USER1); + p2Id = createdP2.getId(); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual = + vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1); + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> expected = + vendorSoftwareProductDao.listProcesses(vsp1Id, VERSION01, component11Id); + Assert.assertEquals(actual.size(), 2); + Assert.assertEquals(actual, expected); + } + + @Test(dependsOnMethods = {"testUpdate", "testList"}) + public void testCreateWithRemovedName() { + testCreate(vsp1Id, component11Id); + } + + @Test + public void testDeleteNonExistingProcessId_negative() { + testDelete_negative(vsp1Id, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingComponentId_negative() { + testDelete_negative(vsp1Id, "non existing component id", p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteNonExistingVspId_negative() { + testDelete_negative("non existing vsp id", component11Id, p1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testList") + public void testDelete() { + vendorSoftwareProductManager.deleteProcess(vsp1Id, component11Id, p1Id, USER1); + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual = + vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id); + Assert.assertNull(actual); + } + + @Test + public void testUploadFileNonExistingProcessId_negative() { + testUploadFile_negative(vsp1Id, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testUploadFileNonExistingComponentId_negative() { + testUploadFile_negative(vsp1Id, "non existing component id", p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testUploadFileNonExistingVspId_negative() { + testUploadFile_negative("non existing vsp id", component11Id, p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testList") + public void testGetFileWhenNone_negative() { + testGetFile_negative(vsp1Id, null, component11Id, p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteFileWhenNone_negative() { + testDeleteFile_negative(vsp1Id, component11Id, p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = {"testGetFileWhenNone_negative", "testDeleteFileWhenNone_negative"}) + public void testUploadFile() { + vendorSoftwareProductManager + .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), ARTIFACT_NAME, + vsp1Id, component11Id, p2Id, USER1); + ProcessArtifactEntity actual = + vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id); + Assert.assertNotNull(actual); + Assert.assertNotNull(actual.getArtifact()); + Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME); + } + + @Test(dependsOnMethods = "testUploadFile") + public void testGetAfterUploadFile() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + actual = testGet(vsp1Id, VERSION01, component11Id, p2Id, USER1); + Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME); + } + + @Test + public void testGetFileNonExistingProcessId_negative() { + testGetFile_negative(vsp1Id, null, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testGetFileNonExistingComponentId_negative() { + testGetFile_negative(vsp1Id, null, "non existing component id", p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testGetFileNonExistingVspId_negative() { + testGetFile_negative("non existing vsp id", null, component11Id, p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testUploadFile") + public void testGetFile() { + File actual = + vendorSoftwareProductManager.getProcessArtifact(vsp1Id, null, component11Id, p2Id, USER1); + Assert.assertNotNull(actual); + ProcessArtifactEntity expected = + vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id); + Assert.assertNotNull(expected); + Assert.assertNotNull(expected.getArtifact()); + } + + @Test + public void testDeleteFileNonExistingProcessId_negative() { + testDeleteFile_negative(vsp1Id, component11Id, "non existing process id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteFileNonExistingComponentId_negative() { + testDeleteFile_negative(vsp1Id, "non existing component id", p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testList") + public void testDeleteFileNonExistingVspId_negative() { + testDeleteFile_negative("non existing vsp id", component11Id, p2Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = "testGetFile") + public void testDeleteFile() { + vendorSoftwareProductManager.deleteProcessArtifact(vsp1Id, component11Id, p2Id, USER1); + ProcessArtifactEntity expected = + vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id); + Assert.assertNull(expected.getArtifact()); + } + + @Test + public void testDeleteListNonExistingComponentId_negative() { + testDeleteList_negative(vsp1Id, "non existing component id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteListNonExistingVspId_negative() { + testDeleteList_negative("non existing vsp id", component11Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test(dependsOnMethods = {"testDeleteFile"}) + public void testDeleteList() { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + p3 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null); + p3.setName("p3 name"); + p3.setDescription("p3 desc"); + vendorSoftwareProductManager.createProcess(p3, USER1); + + vendorSoftwareProductManager.deleteProcesses(vsp1Id, component11Id, USER1); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual = + vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1); + Assert.assertEquals(actual.size(), 0); + } + + protected String testCreate(String vspId, String componentId) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity + expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, null); + expected.setName("p1 name"); + expected.setDescription("p1 desc"); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity created = vendorSoftwareProductManager.createProcess(expected, USER1); + Assert.assertNotNull(created); + expected.setId(created.getId()); + expected.setVersion(VERSION01); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual = + vendorSoftwareProductDao.getProcess(vspId, VERSION01, componentId, created.getId()); + + Assert.assertEquals(actual, expected); + + return created.getId(); + } + + private org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity testGet(String vspId, Version version, String componentId, String processId, + String user) { + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual = + vendorSoftwareProductManager.getProcess(vspId, null, componentId, processId, user); + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity expected = + vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId); + Assert.assertEquals(actual, expected); + return actual; + } + + private void testCreate_negative( + org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process, String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.createProcess(process, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String componentId, String processId, + String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.getProcess(vspId, version, componentId, processId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testUpdate_negative(String vspId, String componentId, String processId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager + .updateProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, processId), user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testList_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.listProcesses(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDeleteList_negative(String vspId, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteProcesses(vspId, componentId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, String componentId, String processId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteProcess(vspId, componentId, processId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testGetFile_negative(String vspId, Version version, String componentId, + String processId, String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.getProcessArtifact(vspId, version, componentId, processId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testUploadFile_negative(String vspId, String componentId, String processId, + String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager + .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), "artifact.sh", + vspId, componentId, processId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + + private void testDeleteFile_negative(String vspId, String componentId, String processId, + String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.deleteProcessArtifact(vspId, componentId, processId, user); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), expectedErrorCode); + } + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPCommon.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPCommon.java new file mode 100644 index 0000000000..4eaba77f2b --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPCommon.java @@ -0,0 +1,78 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; + +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.utilities.file.FileUtils; + +import java.io.*; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class VSPCommon { + + public 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.setVlmVersion(new Version(1, 0)); + vspDetails.setLicenseAgreement(licenseAgreement); + vspDetails.setFeatureGroups(featureGroups); + return vspDetails; + } + + + public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc, + String icon) { + VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity(); + vendorLicenseModel.setVendorName(name); + vendorLicenseModel.setDescription(desc); + vendorLicenseModel.setIconRef(icon); + return vendorLicenseModel; + } + + public static void zipDir(File file, String path, ZipOutputStream zos) { + zipDir(file, path, zos, false); + } + + public static void zipDir(File file, String path, ZipOutputStream zos, boolean isRootDir) { + if (file.isDirectory()) { + path += File.separator + file.getName(); + File[] files = file.listFiles(); + if (files != null) { + for (File innerFile : files) { + if (isRootDir) { + zipDir(innerFile, "", zos, false); + } else { + zipDir(innerFile, path, zos, false); + } + } + } + } else { + + try { + if (!path.isEmpty()) { + path += File.separator; + } + zos.putNextEntry(new ZipEntry(path + file.getName())); + InputStream is = new FileInputStream(file); + byte[] data = FileUtils.toByteArray(is); + zos.write(data); + zos.closeEntry(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java new file mode 100644 index 0000000000..ebc4c3af64 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java @@ -0,0 +1,194 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.io.IOUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.*; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class VSPFullTest { + + + public static final Version VERSION01 = new Version(0, 1); + private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao + vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static final String USER1 = "vspTestUser1"; + private static VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static VendorLicenseFacade vendorLicenseFacade = + org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory.getInstance().createInterface(); + + @Test + public void testEnrichModelInSubmit() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP_FullTest"); + + String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon + .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), + USER1).getId(); + String entitlementPoolId = vendorLicenseFacade + .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId(); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm1Id, null, null); + featureGroup.getEntitlementPoolIds().add(entitlementPoolId); + String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId(); + + org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity + licenseAgreement = new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, null, null); + licenseAgreement.getFeatureGroupIds().add(featureGroupId); + String licenseAgreementId = + vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId(); + + vendorLicenseFacade.checkin(vlm1Id, USER1); + vendorLicenseFacade.submit(vlm1Id, USER1); + + String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds()); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = uploadFullCompositionFile(vspId); + + + //check in + vendorSoftwareProductManager.checkin(vspId, USER1); + //submit + try { + ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1); + //Assert.assertTrue(result.isValid()); + //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1); + + } catch (IOException e) { + Assert.fail(); + } + VersionedVendorSoftwareProductInfo details = + vendorSoftwareProductManager.getVspDetails(vspId, null, USER1); + + + //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1); + // writeFile(csar); + + + ToscaServiceModel model = + (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() + .getServiceModel(vspId, details.getVersionInfo().getActiveVersion()); + + Map<String, CapabilityDefinition> capabilities = new HashMap<>(); + for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) { + model.getServiceTemplates(). + entrySet(). + stream(). + filter(entryValue -> entryValue.getValue() != null && + entryValue.getValue().getNode_types() != null && + entryValue.getValue(). + getNode_types(). + containsKey(component.getComponentCompositionData().getName())). + forEach(entryValue -> entryValue.getValue().getNode_types(). + values(). + stream(). + filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). + forEach(type -> type.getCapabilities(). + entrySet(). + forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), + entry.getValue())))); + + } + + Assert.assertNotNull(capabilities); + } + + private Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> uploadFullCompositionFile(String vspId) { + vendorSoftwareProductManager + .uploadFile(vspId, getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = + vendorSoftwareProductManager.listComponents(vspId, null, USER1); + Assert.assertFalse(components.isEmpty()); + + for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) { + Assert.assertNotNull(vendorSoftwareProductManager + .getComponentQuestionnaire(vspId, null, component.getId(), USER1).getData()); + + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics = + vendorSoftwareProductManager.listNics(vspId, null, component.getId(), USER1); + Assert.assertFalse(nics.isEmpty()); + for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic : nics) { + Assert.assertNotNull(vendorSoftwareProductManager + .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData()); + } + } + + return components; + } + + private String createVsp(String vlm1Id, String licenseAgreementId, Set<String> featureGroupIds) { + VspDetails expectedVsp = VSPCommon + .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id, + "icon", "category", "subCategory", licenseAgreementId, + featureGroupIds.stream().collect(Collectors.toList())); + String vspId = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1).getId(); + + VspDetails actualVsp = + vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01)); + expectedVsp.setId(vspId); + expectedVsp.setVersion(VERSION01); + + VendorSoftwareProductManagerTest.assertVspsEquals(actualVsp, expectedVsp); + Assert.assertNotNull( + vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData()); + return vspId; + } + + private void writeFile(File csar) { + try { + FileInputStream in = new FileInputStream(csar); + File output = new File("CSAR_vDNS.zip"); + + FileOutputStream out = new FileOutputStream(output); + + IOUtils.copy(in, out); + in.close(); + out.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities, + String key, CapabilityDefinition value) { + + capabilities.put(entryValueKey + "_" + key, value); + } + + private InputStream getFileInputStream(String fileName) { + URL url = this.getClass().getResource(fileName); + try { + return url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManagerTest.java new file mode 100644 index 0000000000..d94c868f25 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManagerTest.java @@ -0,0 +1,672 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.errors.ValidationErrorBuilder; +import org.openecomp.sdc.common.utils.AsdcCommon; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.validation.errors.Messages; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.io.IOUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.io.*; +import java.net.URL; +import java.util.*; +import java.util.stream.Collectors; + +public class VendorSoftwareProductManagerTest { + public static final Version VERSION01 = new Version(0, 1); + public static final Version VERSION10 = new Version(1, 0); + private static final String USER1 = "vspTestUser1"; + private static final String USER2 = "vspTestUser2"; + private static final String USER3 = "vspTestUser3"; + public static String id001 = null; + public static String id002 = null; + public static String id003 = null; + public static String id004 = null; + public static String id005 = null; + public static String id006 = null; + public static String id007 = null; + public static Version activeVersion002 = null; + private static VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao + vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static VendorLicenseFacade vendorLicenseFacade = + org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory.getInstance().createInterface(); + private static String vlm1Id; + private static String licenseAgreementId; + private static String featureGroupId; + private static VspDetails vsp1; + private static VspDetails vsp2; + UploadFileTest ut = new UploadFileTest(); + + static void assertVspsEquals(VspDetails actual, VspDetails expected) { + Assert.assertEquals(actual.getId(), expected.getId()); + Assert.assertEquals(actual.getVersion(), expected.getVersion()); + Assert.assertEquals(actual.getName(), expected.getName()); + Assert.assertEquals(actual.getDescription(), expected.getDescription()); + Assert.assertEquals(actual.getIcon(), expected.getIcon()); + Assert.assertEquals(actual.getCategory(), expected.getCategory()); + Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory()); + Assert.assertEquals(actual.getVendorName(), expected.getVendorName()); + Assert.assertEquals(actual.getVendorId(), expected.getVendorId()); + Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement()); + Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups()); + } + + @BeforeTest + private void init() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP1"); + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP3"); + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP4"); + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP5"); + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "vsp1_test"); + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "vsp2_test"); + createVlm(); + } + + private void createVlm() { + vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon + .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), + USER1).getId(); + + String entitlementPoolId = vendorLicenseFacade + .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId(); + + org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity + featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm1Id, null, null); + featureGroup.getEntitlementPoolIds().add(entitlementPoolId); + featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId(); + + LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null); + licenseAgreement.getFeatureGroupIds().add(featureGroupId); + licenseAgreementId = + vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId(); + + vendorLicenseFacade.checkin(vlm1Id, USER1); + vendorLicenseFacade.submit(vlm1Id, USER1); + } + + @Test + public void testHeatSet() { + Set<HeatStructureTree> set = new HashSet<>(); + HeatStructureTree heatStructureTree1 = new HeatStructureTree(); + HeatStructureTree heatStructureTree2 = new HeatStructureTree(); + + heatStructureTree1.setFileName("file"); + + HeatStructureTree env = new HeatStructureTree(); + env.setFileName("env"); + heatStructureTree1.setEnv(env); + + heatStructureTree2.setFileName("file"); + heatStructureTree2.setEnv(env); + + set.add(heatStructureTree1); + set.add(heatStructureTree2); + + Assert.assertEquals(set.size(), 1); + } + + @Test(dependsOnMethods = {"testHeatSet"}) + public void testCreateVSP() { + VspDetails expectedVsp = VSPCommon + .createVspDetails(null, null, "VSP1", "Test-vsp", "vendorName", vlm1Id, "icon", "category", + "subCategory", "123", null); + + VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1); + id001 = createdVsp.getId(); + Assert.assertNotNull(id001); + Assert.assertNotNull(createdVsp.getVersion()); + + VspDetails actualVsp = + vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01)); + expectedVsp.setId(id001); + expectedVsp.setVersion(VERSION01); + + assertVspsEquals(actualVsp, expectedVsp); + Assert.assertNotNull( + vendorSoftwareProductManager.getVspQuestionnaire(id001, null, USER1).getData()); + } + + @Test(dependsOnMethods = {"testCreateVSP"}) + public void testCreateWithExistingName_negative() { + try { + VspDetails expectedVsp = VSPCommon + .createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", vlm1Id, "icon", + "category", "subCategory", "123", null); + vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1); + Assert.fail(); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + } + } + + @Test(dependsOnMethods = {"testCreateWithExistingName_negative"}) + public void testGetVSPDetails() { + VersionedVendorSoftwareProductInfo actualVsp = + vendorSoftwareProductManager.getVspDetails(id001, null, USER1); + + VspDetails expectedVsp = + vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01)); + assertVspsEquals(actualVsp.getVspDetails(), expectedVsp); + Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1); + } + + @Test(dependsOnMethods = {"testGetVSPDetails"}) + public void testUpdateVSP() { + VspDetails expectedVsp = VSPCommon + .createVspDetails(id001, VERSION01, "VSP1", null, "vendorName", vlm1Id, "icon", "category", + "subCategory", "456", null); + vendorSoftwareProductManager.updateVsp(expectedVsp, USER1); + + VspDetails actualVsp = + vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01)); + + assertVspsEquals(actualVsp, expectedVsp); + } + + @Test(dependsOnMethods = {"testUpdateVSP"}) + public void testGetVSPDetailsAfterUpdate() { + VersionedVendorSoftwareProductInfo vspDetails = + vendorSoftwareProductManager.getVspDetails(id001, null, USER1); + Assert.assertEquals(vspDetails.getVspDetails().getName(), "VSP1"); + Assert.assertEquals(vspDetails.getVspDetails().getCategory(), "category"); + Assert.assertEquals(vspDetails.getVspDetails().getSubCategory(), "subCategory"); + Assert.assertEquals(vspDetails.getVspDetails().getVendorId(), vlm1Id); + Assert.assertEquals(vspDetails.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(vspDetails.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(vspDetails.getVersionInfo().getLockingUser(), USER1); + } + + @Test(dependsOnMethods = {"testGetVSPDetailsAfterUpdate"}) + public void testGetVSPList() { + String licenseAgreementId = "bla bla"; + VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP3", "Test-vsp", "vendorName", vlm1Id, "icon", "category", + "subCategory", licenseAgreementId, null), USER1); + id002 = vspDetails.getId(); + vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP4", "Test-vsp", "vendorName", vlm1Id, "icon", "category", + "subCategory", licenseAgreementId, null), USER1); + id003 = vspDetails.getId(); + + List<VersionedVendorSoftwareProductInfo> vspDetailsList = + vendorSoftwareProductManager.getVspList(null, USER1); + int foundCount = 0; + for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) { + if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id002) || + vsp.getVspDetails().getId().equals(id003)) { + foundCount++; + } + } + + Assert.assertEquals(foundCount, 3); + } + + @Test(dependsOnMethods = {"testGetVSPList"}) + // Unsupported operation for 1607 release. +/* public void testDeleteVSP() { + vendorSoftwareProductManager.deleteVsp(id001, USER1); + + VspDetails vspDetails = vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01)); + Assert.assertNull(vspDetails); + + List<VersionedVendorSoftwareProductInfo> vspDetailsList = vendorSoftwareProductManager.getVspList(null, USER1); + boolean found001 = false; + for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) { + if (vsp.getVspDetails().getId().equals(id001)) { + found001 = true; + } + } + + Assert.assertFalse(found001); + } + + + @Test(dependsOnMethods = {"testDeleteVSP"})*/ + public void testCheckin() { + vendorSoftwareProductManager.checkin(id002, USER1); + + VersionedVendorSoftwareProductInfo vsp2 = + vendorSoftwareProductManager.getVspDetails(id002, null, USER1); + Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available); + Assert.assertNull(vsp2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"testCheckin"}) + public void testCheckout() { + vendorSoftwareProductManager.checkout(id002, USER2); + + VersionedVendorSoftwareProductInfo vsp2 = + vendorSoftwareProductManager.getVspDetails(id002, null, USER2); + Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), new Version(0, 2)); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(vsp2.getVersionInfo().getLockingUser(), USER2); + + vsp2 = vendorSoftwareProductManager.getVspDetails(id002, null, USER1); + Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(vsp2.getVersionInfo().getLockingUser(), USER2); + } + + @Test(dependsOnMethods = {"testCheckout"}) + public void testUndoCheckout() { + vendorSoftwareProductManager.undoCheckout(id002, USER2); + + VersionedVendorSoftwareProductInfo vsp2 = + vendorSoftwareProductManager.getVspDetails(id002, null, USER2); + Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available); + Assert.assertNull(vsp2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"testUndoCheckout"}) + public void testListFinalVspsWhenNone() { + List<VersionedVendorSoftwareProductInfo> vspDetailsList = + vendorSoftwareProductManager.getVspList( + org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1); + int nonFinalFoundCount = 0; + for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) { + if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id002) || + vsp.getVspDetails().getId().equals(id003)) { + nonFinalFoundCount++; + } + } + + Assert.assertEquals(nonFinalFoundCount, 0); + } + + @Test(dependsOnMethods = "testListFinalVspsWhenNone") + public void testSubmitWithoutLicencingData() throws IOException { + ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER2); + Assert.assertNotNull(validationResponse); + Assert.assertFalse(validationResponse.isValid()); + List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct() + .collect(Collectors.toList()); + Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID)); + Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID)); + } + + @Test(dependsOnMethods = {"testSubmitWithoutLicencingData"}) + public void testSubmitWithoutUploadData() throws IOException { + vendorSoftwareProductManager.checkout(id002, USER2); + + VspDetails updatedVsp2 = + vendorSoftwareProductManager.getVspDetails(id002, null, USER2).getVspDetails(); + updatedVsp2.setFeatureGroups(new ArrayList<>()); + updatedVsp2.getFeatureGroups().add(featureGroupId); + updatedVsp2.setLicenseAgreement(licenseAgreementId); + + vendorSoftwareProductManager.updateVsp(updatedVsp2, USER2); + activeVersion002 = vendorSoftwareProductManager.checkin(id002, USER2); + + ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER2); + Assert.assertNotNull(validationResponse); + Assert.assertFalse(validationResponse.isValid()); + Assert.assertTrue(validationResponse.getVspErrors().size() > 0); + } + + @Test(dependsOnMethods = {"testSubmitWithoutUploadData"}) + public void testUploadFile() throws IOException { + activeVersion002 = vendorSoftwareProductManager.checkout(id002, USER1); + testLegalUpload(id002, activeVersion002, + getFileInputStream("/vspmanager/zips/emptyComposition.zip"), USER1); + } + +/* @Test(dependsOnMethods = {"testUploadFile"}) + public void testUploadFile2() throws IOException { + testLegalUpload(id002, activeVersion002, ut.getZipInputStream("/legalUpload2"), USER1); + }*/ + + @Test + public void testDownloadFile() throws IOException { + VspDetails expectedVsp = VSPCommon + .createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", + "vendorName", vlm1Id, "icon", "category", "subCategory", "123", null); + VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1); + + id005 = createdVsp.getId(); + Assert.assertNotNull(id005); + Assert.assertNotNull(createdVsp.getVersion()); + + //InputStream zipInputStream = getFileInputStream("/legalUpload/zip/legalUpload.zip") + try (InputStream zipInputStream = ut.getZipInputStream("/legalUpload")) { + + UploadFileResponse resp = + vendorSoftwareProductManager.uploadFile(id005, zipInputStream, USER1); + File latestHeatPackage = vendorSoftwareProductManager.getLatestHeatPackage(id005, USER1); + + zipInputStream.reset(); + byte[] uploaded = IOUtils.toByteArray(zipInputStream); + + byte[] downloaded; + try (BufferedInputStream fileStream = new BufferedInputStream( + new FileInputStream(latestHeatPackage))) { + downloaded = IOUtils.toByteArray(fileStream); + } + + Assert.assertTrue(Arrays.equals(uploaded, downloaded)); + } + } + + @Test(dependsOnMethods = {"testUploadFile"}) + public void testUploadNotExistingFile() throws IOException { + URL url = this.getClass().getResource("notExist.zip"); + testLegalUpload(id002, activeVersion002, url == null ? null : url.openStream(), USER1); + } + + @Test(dependsOnMethods = {"testUploadFile"}, expectedExceptions = CoreException.class) + public void negativeTestCreatePackageBeforeSubmit() throws IOException { + vendorSoftwareProductManager.createPackage(id002, USER1); + } + + @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"}) + public void negativeTestGetVSPDetailsNonExistingVersion() { + try { + vendorSoftwareProductManager.getVspDetails(id002, new Version(43, 8), USER1); + Assert.assertTrue(false); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID); + } + } + + @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"}) + public void negativeTestGetVSPDetailsCheckoutByOtherVersion() { + try { + vendorSoftwareProductManager.getVspDetails(id002, activeVersion002, USER2); + Assert.assertTrue(false); + } catch (CoreException e) { + Assert.assertEquals(e.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID); + } + } + + @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"}) + public void testGetVSPDetailsCandidateVersion() { + VersionedVendorSoftwareProductInfo actualVsp = + vendorSoftwareProductManager.getVspDetails(id002, new Version(0, 3), USER1); + + VspDetails expectedVsp = vendorSoftwareProductDao + .getVendorSoftwareProductInfo(new VspDetails(id002, new Version(0, 3))); + assertVspsEquals(actualVsp.getVspDetails(), expectedVsp); + Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), new Version(0, 3)); + Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1); + } + + @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"}) + public void testGetVSPDetailsOldVersion() { + VersionedVendorSoftwareProductInfo actualVsp = + vendorSoftwareProductManager.getVspDetails(id002, new Version(0, 1), USER2); + + VspDetails expectedVsp = vendorSoftwareProductDao + .getVendorSoftwareProductInfo(new VspDetails(id002, new Version(0, 1))); + assertVspsEquals(actualVsp.getVspDetails(), expectedVsp); + Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), new Version(0, 2)); + Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked); + Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1); + } + + @Test(dependsOnMethods = {"negativeTestGetVSPDetailsNonExistingVersion", + "negativeTestGetVSPDetailsCheckoutByOtherVersion", "testGetVSPDetailsCandidateVersion", + "testGetVSPDetailsOldVersion"}) + public void testSubmit() throws IOException { + activeVersion002 = vendorSoftwareProductManager.checkin(id002, USER1); + ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER1); + Assert.assertTrue(validationResponse.isValid()); + + VersionedVendorSoftwareProductInfo vsp2 = + vendorSoftwareProductManager.getVspDetails(id002, null, USER1); + Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Final); + Assert.assertNull(vsp2.getVersionInfo().getLockingUser()); + } + + @Test(dependsOnMethods = {"testSubmit"}) + public void testListFinalVspsWhenExist() { + List<VersionedVendorSoftwareProductInfo> vspDetailsList = + vendorSoftwareProductManager.getVspList( + org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1); + int nonFinalFoundCount = 0; + boolean found002 = false; + for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) { + if (vsp.getVspDetails().getId().equals(id002)) { + found002 = true; + } + if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id003)) { + nonFinalFoundCount++; + } + } + + Assert.assertEquals(nonFinalFoundCount, 0); + Assert.assertTrue(found002); + } + + @Test(dependsOnMethods = {"testSubmit"}) + public void testCreatePackage() throws IOException { + PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(id002, USER1); + Assert.assertNotNull(packageInfo.getVspId()); + } + + @Test + public void testUploadFileWithoutManifest() { + InputStream zis = getFileInputStream("/vspmanager/zips/withoutManifest.zip"); + VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP5", "Test-vsp", "vendorName", vlm1Id, "icon", "category", + "subCategory", "456", null), USER1); + id004 = vspDetails.getId(); + + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(id004, zis, USER1); + + Assert.assertNotNull(uploadFileResponse.getErrors()); + Assert.assertEquals(uploadFileResponse.getErrors().size(), 1); + } + + @Test(dependsOnMethods = {"testUploadFileWithoutManifest"}) + public void testUploadFileMissingFile() { + InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip"); + + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(id004, zis, USER1); + + Assert.assertEquals(uploadFileResponse.getErrors().size(), 3); + } + + @Test(dependsOnMethods = {"testUploadFileMissingFile"}) + public void testUploadNotZipFile() throws IOException { + URL url = this.getClass().getResource("/notZipFile"); + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(id004, url.openStream(), USER1); + + Assert.assertNotNull(uploadFileResponse.getErrors()); + Assert.assertEquals( + uploadFileResponse.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(), + Messages.INVALID_ZIP_FILE.getErrorMessage()); + } + + @Test + public void testEnrichModelInSubmit() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP_syb"); + VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", vlm1Id, "icon", + "category", "subCategory", "456", null), USER1); + String id = vspDetails.getId(); + + //upload file + InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); + UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.uploadFile(id, zis, USER1); + + //check in + vendorSoftwareProductManager.checkin(id, USER1); + //submit + try { + ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); + } catch (IOException e) { + Assert.fail(); + } + VersionedVendorSoftwareProductInfo details = + vendorSoftwareProductManager.getVspDetails(id, null, USER1); + Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = vendorSoftwareProductManager + .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1); + + ToscaServiceModel model = + (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() + .getServiceModel(id, details.getVersionInfo().getActiveVersion()); + + Map<String, CapabilityDefinition> capabilities = new HashMap<>(); + for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) { + model.getServiceTemplates(). + entrySet(). + stream(). + filter(entryValue -> entryValue.getValue() != null && + entryValue.getValue().getNode_types() != null && + entryValue.getValue(). + getNode_types(). + containsKey(component.getComponentCompositionData().getName())). + forEach(entryValue -> entryValue.getValue().getNode_types(). + values(). + stream(). + filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). + forEach(type -> type.getCapabilities(). + entrySet(). + forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), + entry.getValue())))); + + } + + Assert.assertNotNull(capabilities); + } + + @Test(dependsOnMethods = {"testEnrichModelInSubmit"}) + public void testVSPListSortedByModificationTimeDescOreder() { + vsp1 = VSPCommon + .createVspDetails(null, null, "vsp1_test", "Test-vsp", "vendorName", vlm1Id, "icon", + "category", "subCategory", "123", null); + id006 = vendorSoftwareProductManager.createNewVsp(vsp1, USER3).getId(); + + vsp2 = VSPCommon + .createVspDetails(null, null, "vsp2_test", "Test-vsp", "vendorName", vlm1Id, "icon", + "category", "subCategory", "123", null); + id007 = vendorSoftwareProductManager.createNewVsp(vsp2, USER3).getId(); + + assertVSPInWantedLocationInVSPList(id007, 0, USER3); + assertVSPInWantedLocationInVSPList(id006, 1, USER3); + } + + @Test(dependsOnMethods = {"testVSPListSortedByModificationTimeDescOreder"}) + public void testUpdatedVSPShouldBeInBeginningOfList() { + vendorSoftwareProductManager.updateVsp(vsp1, USER3); + assertVSPInWantedLocationInVSPList(id006, 0, USER3); + + vendorSoftwareProductManager + .uploadFile(id007, getFileInputStream("/vspmanager/zips/emptyComposition.zip"), USER3); + assertVSPInWantedLocationInVSPList(id007, 0, USER3); + } + + @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"}) + public void testVSPInBeginningOfListAfterCheckin() { + vendorSoftwareProductManager.checkin(id006, USER3); + assertVSPInWantedLocationInVSPList(id006, 0, USER3); + + vendorSoftwareProductManager.checkin(id007, USER3); + assertVSPInWantedLocationInVSPList(id007, 0, USER3); + } + + @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"}) + public void testVSPInBeginningOfListAfterCheckout() { + vendorSoftwareProductManager.checkout(id006, USER3); + assertVSPInWantedLocationInVSPList(id006, 0, USER3); + } + + @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"}) + public void testVSPInBeginningOfListAfterUndoCheckout() { + vendorSoftwareProductManager.checkout(id007, USER3); + assertVSPInWantedLocationInVSPList(id007, 0, USER3); + + vendorSoftwareProductManager.undoCheckout(id006, USER3); + assertVSPInWantedLocationInVSPList(id006, 0, USER3); + } + + @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"}) + public void testVSPInBeginningOfListAfterSubmit() throws IOException { + vendorSoftwareProductManager.checkin(id007, USER3); + vendorSoftwareProductManager.submit(id007, USER3); + + assertVSPInWantedLocationInVSPList(id007, 0, USER3); + } + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + vendorSoftwareProductManager.uploadFile(vspId, upload, user); + + UploadDataEntity uploadData = + vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version)); + Assert.assertNotNull(uploadData); + Assert.assertNotNull(uploadData.getContentData()); + } + + private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities, + String key, CapabilityDefinition value) { + + capabilities.put(entryValueKey + "_" + key, value); + } + + private InputStream getFileInputStream(String fileName) { + URL url = this.getClass().getResource(fileName); + try { + return url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) { + List<VersionedVendorSoftwareProductInfo> vspList = + vendorSoftwareProductManager.getVspList(null, user); + Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId); + } +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractorTest.java new file mode 100644 index 0000000000..55f30db609 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractorTest.java @@ -0,0 +1,280 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services; + +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.*; +import java.net.URL; +import java.nio.file.NotDirectoryException; +import java.util.HashMap; +import java.util.Map; + +public class CompositionDataExtractorTest { + + + private static ToscaServiceModel loadToscaServiceModel(String serviceTemplatesPath, + String globalServiceTemplatesPath, + String entryDefinitionServiceTemplate) + throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); + if (entryDefinitionServiceTemplate == null) { + entryDefinitionServiceTemplate = "MainServiceTemplate.yaml"; + } + + loadServiceTemplates(serviceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); + if (globalServiceTemplatesPath != null) { + loadServiceTemplates(globalServiceTemplatesPath, toscaExtensionYamlUtil, serviceTemplates); + } + + return new ToscaServiceModel(null, serviceTemplates, entryDefinitionServiceTemplate); + } + + private static void loadServiceTemplates(String serviceTemplatesPath, + ToscaExtensionYamlUtil toscaExtensionYamlUtil, + Map<String, ServiceTemplate> serviceTemplates) + throws IOException { + URL urlFile = CompositionDataExtractorTest.class.getResource(serviceTemplatesPath); + if (urlFile != null) { + File pathFile = new File(urlFile.getFile()); + File[] files = pathFile.listFiles(); + if (files != null) { + addServiceTemplateFiles(serviceTemplates, files, toscaExtensionYamlUtil); + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } else { + throw new NotDirectoryException(serviceTemplatesPath); + } + } + + private static void addServiceTemplateFiles(Map<String, ServiceTemplate> serviceTemplates, + File[] files, + ToscaExtensionYamlUtil toscaExtensionYamlUtil) + throws IOException { + for (File file : files) { + try (InputStream yamlFile = new FileInputStream(file)) { + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + serviceTemplates.put(file.getName(), serviceTemplateFromYaml); + try { + yamlFile.close(); + } catch (IOException ignore) { + } + } catch (FileNotFoundException e) { + throw e; + } catch (IOException e) { + throw e; + } + } + } + + @Test + public void testExtractNetworks() throws Exception { + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/extractServiceComposition/networks/", + "/extractServiceComposition/toscaGlobalServiceTemplates/", null); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData compositionData = + CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel); + Assert.assertEquals(compositionData.getComponents().size(), 0); + Assert.assertEquals(compositionData.getNetworks().size(), 7); + + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network network : compositionData.getNetworks()) { + boolean dhcp = network.isDhcp(); + switch (network.getName()) { + case "contail-net-default-true-dhcp": + Assert.assertEquals(dhcp, true); + break; + case "contail-net-dhcp-false-param": + Assert.assertEquals(dhcp, false); + break; + case "contail-net-dhcp-false": + Assert.assertEquals(dhcp, false); + break; + case "contail-net-dhcp-true-param": + Assert.assertEquals(dhcp, true); + break; + case "contail-net-dhcp-true": + Assert.assertEquals(dhcp, true); + break; + case "contail-net-dhcp-default-true-param": + Assert.assertEquals(dhcp, true); + break; + case "neutron-net-default-dhcp": + Assert.assertEquals(dhcp, true); + break; + default: + throw new Exception("Unexpected Network Name " + network.getName()); + } + + } + } + + @Test + public void testExtractOnlyComponents() throws Exception { + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/extractServiceComposition/onlyComponents/", + "/extractServiceComposition/toscaGlobalServiceTemplates/", "OnlyComponentsST.yaml"); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData compositionData = + CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel); + Assert.assertEquals(compositionData.getComponents().size(), 3); + Assert.assertEquals(compositionData.getNetworks().size(), 0); + + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component component : compositionData.getComponents()) { + switch (component.getData().getName()) { + case "org.openecomp.resource.vfc.nodes.heat.pcrf_psm": + Assert.assertNull(component.getNics()); + Assert.assertEquals(component.getData().getDisplayName(), "pcrf_psm"); + break; + case "org.openecomp.resource.vfc.nodes.heat.nova.Server": + Assert.assertNull(component.getNics()); + Assert.assertEquals(component.getData().getDisplayName(), "Server"); + break; + case "org.openecomp.resource.vfc.nodes.heat.pcm": + Assert.assertNull(component.getNics()); + Assert.assertEquals(component.getData().getDisplayName(), "pcm"); + break; + default: + throw new Exception("Unexpected ComponentData Name " + component.getData().getName()); + } + } + } + + @Test + public void testExtractComponentsWithPorts() throws Exception { + + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/extractServiceComposition/componentsWithPort/", + "/extractServiceComposition/toscaGlobalServiceTemplates/", "ComponentsWithPortST.yaml"); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData compositionData = + CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel); + + Assert.assertEquals(compositionData.getComponents().size(), 3); + Assert.assertEquals(compositionData.getNetworks().size(), 0); + + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component component : compositionData.getComponents()) { + switch (component.getData().getName()) { + case "org.openecomp.resource.vfc.nodes.heat.pcrf_psm": + Assert.assertEquals(component.getNics().size(), 1); + Assert.assertEquals(component.getNics().get(0).getName(), "psm01_port_0"); + Assert.assertNull(component.getNics().get(0).getNetworkName()); + Assert.assertEquals(component.getData().getDisplayName(), "pcrf_psm"); + break; + case "org.openecomp.resource.vfc.nodes.heat.nova.Server": + Assert.assertEquals(component.getNics().size(), 1); + Assert.assertEquals(component.getNics().get(0).getName(), "FSB1_Internal2"); + Assert.assertNull(component.getNics().get(0).getNetworkName()); + Assert.assertEquals(component.getData().getDisplayName(), "Server"); + break; + case "org.openecomp.resource.vfc.nodes.heat.pcm": + Assert.assertEquals(component.getNics().size(), 2); + Assert.assertEquals(component.getData().getDisplayName(), "pcm"); + break; + default: + throw new Exception("Unexpected ComponentData Name " + component.getData().getName()); + } + } + } + + @Test + public void testExtractFullComposition() throws Exception { + + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/extractServiceComposition/fullComposition/", + "/extractServiceComposition/toscaGlobalServiceTemplates/", null); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData compositionData = + CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel); + Assert.assertEquals(compositionData.getComponents().size(), 3); + Assert.assertEquals(compositionData.getNetworks().size(), 3); + + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component component : compositionData.getComponents()) { + switch (component.getData().getName()) { + case "org.openecomp.resource.vfc.nodes.heat.pcrf_psm": + Assert.assertEquals(component.getNics().size(), 1); + Assert.assertEquals(component.getNics().get(0).getName(), "psm01_port_0"); + Assert.assertNull(component.getNics().get(0).getNetworkName()); + Assert.assertEquals(component.getData().getDisplayName(), "pcrf_psm"); + break; + case "org.openecomp.resource.vfc.nodes.heat.nova.Server": + Assert.assertEquals(component.getNics().size(), 3); + Assert.assertEquals(component.getData().getDisplayName(), "Server"); + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic port : component.getNics()) { + switch (port.getName()) { + case "FSB1_Internal2_port": + Assert.assertEquals(port.getNetworkName(), "Internal2-net"); + break; + case "FSB1_OAM_Port": + Assert.assertNull(port.getNetworkName()); + break; + case "FSB1_Internal1_port": + Assert.assertEquals(port.getNetworkName(), "Internal1-net"); + break; + default: + throw new Exception("Unexpected Nic " + port.getName()); + } + } + break; + case "org.openecomp.resource.vfc.nodes.heat.pcm": + Assert.assertEquals(component.getNics().size(), 2); + Assert.assertEquals(component.getData().getDisplayName(), "pcm"); + break; + default: + throw new Exception("Unexpected ComponentData Name " + component.getData().getName()); + } + } + } + + @Test + public void testExtractSubstitutionComposition() throws Exception { + + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/extractServiceComposition/substitution/", + "/extractServiceComposition/toscaGlobalServiceTemplates/", null); + org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData compositionData = + CompositionDataExtractor.extractServiceCompositionData(toscaServiceModel); + Assert.assertEquals(compositionData.getComponents().size(), 2); + Assert.assertEquals(compositionData.getNetworks().size(), 4); + + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component component : compositionData.getComponents()) { + switch (component.getData().getName()) { + case "org.openecomp.resource.vfc.nodes.heat.cmaui_image": + Assert.assertEquals(component.getNics().size(), 1); + Assert.assertEquals(component.getNics().get(0).getName(), "cmaui_port_1"); + Assert.assertEquals(component.getNics().get(0).getNetworkName(), "test_net1"); + Assert.assertEquals(component.getData().getDisplayName(), "cmaui_image"); + break; + case "org.openecomp.resource.vfc.nodes.heat.abc_image": + Assert.assertEquals(component.getNics().size(), 1); + Assert.assertEquals(component.getNics().get(0).getName(), "abc_port_1"); + Assert.assertEquals(component.getNics().get(0).getNetworkName(), "test_net2"); + Assert.assertEquals(component.getData().getDisplayName(), "abc_image"); + break; + default: + throw new Exception("Unexpected ComponentData Name " + component.getData().getName()); + } + } + for (org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network network : compositionData.getNetworks()) { + boolean dhcp = network.isDhcp(); + switch (network.getName()) { + case "test_net2": + Assert.assertEquals(dhcp, true); + break; + case "test_net1": + Assert.assertEquals(dhcp, true); + break; + case "Internal1-net": // same network display twice since define in 2 nested files with the same key + Assert.assertEquals(dhcp, true); + break; + default: + throw new Exception("Unexpected Network Name " + network.getName()); + } + + } + } + + +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManagerTest.java new file mode 100644 index 0000000000..e1ddcdc975 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManagerTest.java @@ -0,0 +1,141 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.apache.commons.collections.CollectionUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.Map; + +public class CompositionEntityDataManagerTest { + + public static final String VSP1 = "vsp1"; + public static final String COMPONENT1 = "component1"; + public static final String NIC1 = "nic1"; + private static CompositionEntityDataManager compositionEntityDataManager = + new CompositionEntityDataManager(); + private static Map<CompositionEntityId, Collection<String>> errorsById; + + private static void assertValidationData(CompositionEntityValidationData validationData, + String id, CompositionEntityType type, + boolean hasErrors) { + Assert.assertNotNull(validationData); + Assert.assertEquals(validationData.getEntityId(), id); + Assert.assertEquals(validationData.getEntityType(), type); + Assert.assertTrue(CollectionUtils.isNotEmpty(validationData.getErrors()) == hasErrors); + } + + @Test(expectedExceptions = CoreException.class) + public void testAddNullEntity_negative() { + compositionEntityDataManager.addEntity(null, null); + } + + @Test + public void testAddEntity() { + compositionEntityDataManager + .addEntity(new VspQuestionnaireEntity(VSP1, new Version(0, 1)), null); + + String invalidQuestionnaireData = "{\"a\": \"b\"}"; + + ComponentEntity component = new ComponentEntity(VSP1, new Version(0, 1), COMPONENT1); + component.setQuestionnaireData(invalidQuestionnaireData); + compositionEntityDataManager.addEntity(component, null); + + org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity + nic = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(VSP1, new Version(0, 1), COMPONENT1, NIC1); + nic.setQuestionnaireData(invalidQuestionnaireData); + compositionEntityDataManager.addEntity(nic, null); + } + + @Test(dependsOnMethods = "testAddEntity") + public void testValidateEntitiesQuestionnaire() { + errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertNotNull(errorsById); + Assert.assertEquals(errorsById.size(), 2); // both component and nic data don't mach schemas + CompositionEntityId nicId = + new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(VSP1, new Version(0, 1), COMPONENT1, NIC1).getCompositionEntityId(); + Assert.assertTrue(errorsById.containsKey(nicId)); + Assert.assertTrue(errorsById.containsKey(nicId.getParentId())); + } + + @Test(dependsOnMethods = "testAddEntity") + public void testBuildTrees() { + compositionEntityDataManager.buildTrees(); + } + + @Test(dependsOnMethods = "testBuildTrees") + public void testAddErrorsToTrees() { + compositionEntityDataManager.addErrorsToTrees(errorsById); + } + + @Test(dependsOnMethods = "testAddErrorsToTrees") + public void testGetTrees() { + Collection<CompositionEntityValidationData> trees = compositionEntityDataManager.getTrees(); + Assert.assertNotNull(trees); + Assert.assertEquals(trees.size(), 1); + + CompositionEntityValidationData vspValidationData = trees.iterator().next(); + assertValidationData(vspValidationData, VSP1, CompositionEntityType.vsp, false); + Assert.assertEquals(vspValidationData.getSubEntitiesValidationData().size(), 1); + + CompositionEntityValidationData componentValidationData = + vspValidationData.getSubEntitiesValidationData().iterator().next(); + assertValidationData(componentValidationData, COMPONENT1, CompositionEntityType.component, + true); + Assert.assertEquals(componentValidationData.getSubEntitiesValidationData().size(), 1); + + CompositionEntityValidationData nicValidationData = + componentValidationData.getSubEntitiesValidationData().iterator().next(); + assertValidationData(nicValidationData, NIC1, CompositionEntityType.nic, true); + Assert.assertNull(nicValidationData.getSubEntitiesValidationData()); + } + + @Test + public void testValidateValidEntity() { + NetworkEntity networkEntity = new NetworkEntity(VSP1, new Version(0, 1), "network1"); + Network network = new Network(); + network.setName("network1 name"); + network.setDhcp(true); + networkEntity.setNetworkCompositionData(network); + + NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); + schemaTemplateInput.setManual(false); + schemaTemplateInput.setNetwork(network); + + CompositionEntityValidationData validationData = CompositionEntityDataManager + .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); + assertValidationData(validationData, "network1", CompositionEntityType.network, false); + } + + @Test + public void testValidateInvalidEntity() { + NetworkEntity networkEntity = new NetworkEntity(VSP1, new Version(0, 1), "network1"); + Network network = new Network(); + network.setName("network1 name changed"); + network.setDhcp(false); + networkEntity.setNetworkCompositionData(network); + + NetworkCompositionSchemaInput schemaTemplateInput = new NetworkCompositionSchemaInput(); + schemaTemplateInput.setManual(false); + Network origNetwork = new Network(); + origNetwork.setName("network1 name"); + origNetwork.setDhcp(true); + schemaTemplateInput.setNetwork(origNetwork); + + CompositionEntityValidationData validationData = CompositionEntityDataManager + .validateEntity(networkEntity, SchemaTemplateContext.composition, schemaTemplateInput); + assertValidationData(validationData, "network1", CompositionEntityType.network, true); + Assert.assertEquals(validationData.getErrors().size(), 2); + } +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireSchemaTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireSchemaTest.java new file mode 100644 index 0000000000..4d03b5980f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireSchemaTest.java @@ -0,0 +1,64 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.utilities.file.FileUtils; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +public class QuestionnaireSchemaTest { + + public static final String VSP1 = "vsp1"; + public static final String COMPONENT1 = "component1"; + public static final String NIC1 = "nic1"; + private static CompositionEntityDataManager compositionEntityDataManager = + new CompositionEntityDataManager(); + private static Map<CompositionEntityId, Collection<String>> errorsById; + private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity componentEntity; + private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nicEntity; + + private static String loadFileToString(String path) { + return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path))); + } + + @Test + public void testAddEntity() { + compositionEntityDataManager + .addEntity(new VspQuestionnaireEntity(VSP1, new Version(0, 1)), null); + + componentEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(VSP1, new Version(0, 1), COMPONENT1); + nicEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(VSP1, new Version(0, 1), COMPONENT1, NIC1); + compositionEntityDataManager.addEntity(componentEntity, null); + + componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/validComponent.json")); + nicEntity.setQuestionnaireData(loadFileToString("quesionnaire/validNic.json")); + compositionEntityDataManager.addEntity(nicEntity, null); + } + + @Test(dependsOnMethods = "testAddEntity") + public void testNicAndComponentValidQuestionnaire() { + errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertEquals(errorsById.size(), 0); + } + + @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire") + public void testComponentInvalidQuestionnaire() { + componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/invalidComponent.json")); + compositionEntityDataManager.addEntity(componentEntity, null); + + errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); + Assert.assertEquals(errorsById.size(), 1); + + CompositionEntityId component = errorsById.keySet().iterator().next(); + List<String> errors = (List<String>) errorsById.get(component); + Assert.assertEquals(errors.size(), 1); + Assert.assertEquals(errors.get(0), + "#/general/recovery/pointObjective: 20.0 is not lower or equal to 15"); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireValidatorTest.java new file mode 100644 index 0000000000..0dedacb34a --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/QuestionnaireValidatorTest.java @@ -0,0 +1,74 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services; + +public class QuestionnaireValidatorTest { +/* + public static QuestionnaireValidator validator = new QuestionnaireValidator(); + + @Test(expectedExceptions = CoreException.class) + public void testAddSubEntityBeforeRoot_negative() { + validator.addSubEntity(createComponent("componentId2"), CompositionEntityType.vsp); + } + + @Test(dependsOnMethods = "testAddSubEntityBeforeRoot_negative") + public void testAddRootEntity() { + validator.addRootEntity(createVspQuestionnaireEntity()); + } + + @Test(dependsOnMethods = "testAddRootEntity", expectedExceptions = CoreException.class) + public void testAddRootEntityWhenAlreadyExist_negative() { + validator.addRootEntity(createVspQuestionnaireEntity()); + } + + @Test(dependsOnMethods = "testAddRootEntity") + public void testAddSubEntity() { + validator.addSubEntity(createComponent("componentId1"), CompositionEntityType.vsp); + } + + @Test(dependsOnMethods = "testAddRootEntity", expectedExceptions = CoreException.class) + public void testAddSubEntityWithNonExistingParentType() { + validator.addSubEntity(new ComponentEntity("vspId1", new Version(0, 1), "componentId2"), CompositionEntityType.nic); + } + + @Test(dependsOnMethods = "testAddSubEntity") + public void testAddSubEntities() throws Exception { + Collection<CompositionEntity> nics = new ArrayList<>(); + nics.add(createNic("nicId1", "componentId1")); + nics.add(createNic("nicId2", "componentId1")); + nics.add(createNic("nicId3", "componentId1")); + + validator.addSubEntities(nics, CompositionEntityType.component); + } + + + @Test(dependsOnMethods = "testAddSubEntities") + public void testValidate() throws Exception { + QuestionnaireValidationResult validationResult = validator.validate(); + Assert.assertTrue(validationResult.isValid()); + } + + private static VspQuestionnaireEntity createVspQuestionnaireEntity() { + VspQuestionnaireEntity vspQuestionnaireEntity = new VspQuestionnaireEntity(); + vspQuestionnaireEntity.setId("vspId1"); + vspQuestionnaireEntity.setVersion(new Version(0, 1)); + vspQuestionnaireEntity.setQuestionnaireData("{\n" + + " \"name\": \"bla bla\"\n" + + "}"); + return vspQuestionnaireEntity; + } + + private static ComponentEntity createComponent(String componentId) { + ComponentEntity component = new ComponentEntity("vspId1", new Version(0, 1), componentId); + component.setQuestionnaireData("{\n" + + " \"name\": \"bla bla\"\n" + + "}"); + return component; + } + + private static CompositionEntity createNic(String nicId, String componentId) { + NicEntity nic = new NicEntity("vspId1", new Version(0, 1), componentId, nicId); + nic.setQuestionnaireData("{\n" + + " \"name\": \"bla bla\"\n" + + "}"); + return nic; + }*/ +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorTest.java new file mode 100644 index 0000000000..fd293c66dd --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorTest.java @@ -0,0 +1,244 @@ +package org.openecomp.sdc.vendorsoftwareproduct.services; + +import org.openecomp.core.utilities.json.JsonUtil; +import org.everit.json.schema.EmptySchema; +import org.everit.json.schema.loader.SchemaLoader; +import org.json.JSONObject; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentCompositionSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NicCompositionSchemaInput; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.Map; + +public class SchemaGeneratorTest { + + private static int getMinOfVmMax(JSONObject schemaJson) { + return schemaJson.getJSONObject("properties").getJSONObject("compute") + .getJSONObject("properties").getJSONObject("numOfVMs").getJSONObject("properties") + .getJSONObject("maximum").getInt("minimum"); + } + + private static JSONObject validateSchema(String schema) { + System.out.println(schema); + Assert.assertNotNull(schema); + Assert.assertTrue(JsonUtil.isValidJson(schema)); + JSONObject schemaJson = new JSONObject(schema); + Assert.assertFalse(SchemaLoader.load(schemaJson) instanceof EmptySchema); + return schemaJson; + } + + @Test + public void testGenerateVspQuestionnaire() { + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null); + validateSchema(schema); + } + + @Test + public void testGenerateNetworkCompositionUpload() { + Network network = new Network(); + network.setName("upload network1 name"); + network.setDhcp(true); + + NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput(); + input.setManual(false); + input.setNetwork(network); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input); + validateSchema(schema); + } + + @Test + public void testGenerateNetworkCompositionManual() { + NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput(); + input.setManual(true); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input); + + validateSchema(schema); + } + + @Test + public void testGenerateComponentQuestionnaireWithoutInput() { + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null); + validateSchema(schema); + } + + @Test + public void testGenerateComponentQuestionnaireWithMissingInput() { + ComponentQuestionnaireSchemaInput input = + new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"), + JsonUtil.json2Object("{\n" + + " \"compute\": {\n" + + " \"numOfVMs\": {\n" + + " \"blabla\": 70\n" + // no minimum + " }\n" + + " }\n" + + "}", Map.class)); + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input); + JSONObject schemaJson = validateSchema(schema); + //Assert.assertEquals(getMinOfVmMax(schemaJson), 0); + } + + @Test + public void testGenerateComponentQuestionnaireWithInvalidTypeInput() { + ComponentQuestionnaireSchemaInput input = + new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"), + JsonUtil.json2Object("{\n" + + " \"compute\": {\n" + + " \"numOfVMs\": {\n" + + " \"minimum\": \"some string instead of integer\"\n" + + // invalid minimum - string + " }\n" + + " }\n" + + "}", Map.class)); + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input); + JSONObject schemaJson = validateSchema(schema); + Assert.assertEquals(getMinOfVmMax(schemaJson), 0); + } + + @Test + public void testGenerateComponentQuestionnaireWithInvalidRangeInput() { + ComponentQuestionnaireSchemaInput input = + new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"), + JsonUtil.json2Object("{\n" + + " \"compute\": {\n" + + " \"numOfVMs\": {\n" + + " \"minimum\": 150\n" + // invalid minimum - integer out of range (0-100) + " }\n" + + " }\n" + + "}", Map.class)); + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input); + JSONObject schemaJson = validateSchema(schema); + Assert.assertEquals(getMinOfVmMax(schemaJson), 0); + } + + @Test + public void testGenerateComponentQuestionnaireWithValidInput() { + ComponentQuestionnaireSchemaInput input = + new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"), + JsonUtil.json2Object("{\n" + + " \"compute\": {\n" + + " \"numOfVMs\": {\n" + + " \"minimum\": 30\n" + // valid minimum - integer at the correct range (0-100) + " }\n" + + " }\n" + + "}", Map.class)); + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input); + JSONObject schemaJson = validateSchema(schema); + Assert.assertEquals(getMinOfVmMax(schemaJson), 30); + } + + @Test + public void testGenerateNicQuestionnaire() { + String schema = SchemaGenerator + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null); + validateSchema(schema); + } + + @Test + public void testGenerateComponentCompositionUpload() { + ComponentData component = new ComponentData(); + component.setName("upload comp1 name"); + component.setDescription("upload comp1 desc"); + + ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput(); + input.setManual(false); + input.setComponent(component); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input); + validateSchema(schema); + } + + @Test + public void testGenerateComponentCompositionManual() { + ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput(); + input.setManual(true); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input); + validateSchema(schema); + } + + @Test + public void testGenerateNicCompositionUpload() { + Nic nic = new Nic(); + nic.setName("upload nic1 name"); + nic.setDescription("upload nic1 desc"); + nic.setNetworkId("upload nic1 networkId"); + //nic.setNetworkName("upload nic1 networkName"); + nic.setNetworkType(NetworkType.External); + + NicCompositionSchemaInput input = new NicCompositionSchemaInput(); + input.setManual(false); + input.setNic(nic); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input); + validateSchema(schema); + } + + +// @Test +// public void testGenerateNicCompositionManualWithoutNetworkId() { +// Nic nic = new Nic(); +// nic.setName("upload nic1 name"); +// nic.setDescription("upload nic1 desc"); +// //nic.setNetworkName("upload nic1 networkName"); +// nic.setNetworkType(NetworkType.External); +// +// NicCompositionSchemaInput input = new NicCompositionSchemaInput(); +// input.setManual(true); +// input.setNic(nic); +// +// String schema = SchemaGenerator.generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input); +// validateSchema(schema); +// } + + @Test + public void testGenerateNicCompositionUploadWithoutNetworkId() { + Nic nic = new Nic(); + nic.setName("upload nic1 name"); + nic.setDescription("upload nic1 desc"); + //nic.setNetworkName("upload nic1 networkName"); + nic.setNetworkType(NetworkType.External); + + NicCompositionSchemaInput input = new NicCompositionSchemaInput(); + input.setManual(false); + input.setNic(nic); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input); + validateSchema(schema); + } + + @Test + public void testGenerateNicCompositionManual() { + NicCompositionSchemaInput input = new NicCompositionSchemaInput(); + input.setManual(true); + input.setNetworkIds( + Arrays.asList("manual networkId1", "manual networkId2", "manual networkId3")); + + String schema = SchemaGenerator + .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input); + validateSchema(schema); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java new file mode 100644 index 0000000000..c926977c7b --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java @@ -0,0 +1,102 @@ +package org.openecomp.sdc.vendorsoftwareproduct.tree; + +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.*; + + +public class HeatTreeManagerTest extends TreeBaseTest { + + @Test + public void testHeatTreeManager() { + + INPUT_DIR = "/tree/valid_tree/input/"; + HeatTreeManager heatTreeManager = initHeatTreeManager(); + heatTreeManager.createTree(); + Map<String, List<ErrorMessage>> errorMap = new HashMap<>(); + + List<ErrorMessage> errorList = new ArrayList<>(); + errorList.add(new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, "Missing Artifact")); + errorMap.put("missing-artifact", errorList); + errorList = new ArrayList<>(); + errorList.add(new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.WARNING, "Missing Nested File")); + errorMap.put("missingNested.yaml", errorList); + heatTreeManager.addErrors(errorMap); + HeatStructureTree tree = heatTreeManager.getTree(); + Assert.assertNotNull(tree); + } + + @Test + public void testHeatTreeManagerMissingManifest() { + + INPUT_DIR = "/tree/missing_manifest/input/"; + HeatTreeManager heatTreeManager = initHeatTreeManager(); + heatTreeManager.createTree(); + Map<String, List<ErrorMessage>> errorMap = new HashMap<>(); + + List<ErrorMessage> errorList = new ArrayList<>(); + errorList.add(new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, "Missing Artifact")); + errorMap.put("missing-artifact", errorList); + errorList = new ArrayList<>(); + errorList.add(new ErrorMessage(org.openecomp.sdc.datatypes.error.ErrorLevel.WARNING, "Missing Nested File")); + errorMap.put("missingNested.yaml", errorList); + heatTreeManager.addErrors(errorMap); + HeatStructureTree tree = heatTreeManager.getTree(); + Assert.assertNotNull(tree); + Assert.assertEquals(tree.getHEAT(), null); + + } + + + @Test + public void testResourceGroupShowsAsNestedFileInTree() throws IOException { + INPUT_DIR = "/tree/nested_resource_group"; + HeatTreeManager heatTreeManager = initHeatTreeManager(); + heatTreeManager.createTree(); + HeatStructureTree tree = heatTreeManager.getTree(); + + Set<HeatStructureTree> heat = tree.getHEAT(); + Assert.assertNotNull(heat); + + HeatStructureTree addOnHeatSubTree = + HeatStructureTree.getHeatStructureTreeByName(heat, "addOn.yml"); + Assert.assertNotNull(addOnHeatSubTree); + + Set<HeatStructureTree> addOnNestedFiles = addOnHeatSubTree.getNested(); + Assert.assertNotNull(addOnNestedFiles); + + HeatStructureTree nestedFile = + HeatStructureTree.getHeatStructureTreeByName(addOnNestedFiles, "nested.yml"); + Assert.assertNotNull(nestedFile); + } + + + @Test + public void testVolumeNestedFileIsNotUnderVolumeSubTree() { + INPUT_DIR = "/tree/nested_volume"; + HeatTreeManager heatTreeManager = initHeatTreeManager(); + heatTreeManager.createTree(); + HeatStructureTree tree = heatTreeManager.getTree(); + + Set<HeatStructureTree> heat = tree.getHEAT(); + Set<HeatStructureTree> volume = tree.getVolume(); + Assert.assertNotNull(heat); + Assert.assertNull(volume); + + HeatStructureTree baseMobtSubTree = + HeatStructureTree.getHeatStructureTreeByName(heat, "base_mobt.yaml"); + Assert.assertNotNull(baseMobtSubTree); + + Set<HeatStructureTree> baseMobtNestedFiles = baseMobtSubTree.getNested(); + Assert.assertNotNull(baseMobtNestedFiles); + + HeatStructureTree nestedVolumeFile = HeatStructureTree + .getHeatStructureTreeByName(baseMobtNestedFiles, "hot_mobt_volume_attach_nested.yaml"); + Assert.assertNotNull(nestedVolumeFile); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java new file mode 100644 index 0000000000..df6cf54058 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java @@ -0,0 +1,33 @@ +package org.openecomp.sdc.vendorsoftwareproduct.tree; + +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; +import org.openecomp.core.utilities.file.FileUtils; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; + +public class TreeBaseTest { + + String INPUT_DIR; + + + HeatTreeManager initHeatTreeManager() { + HeatTreeManager heatTreeManager = new HeatTreeManager(); + + URL url = TreeBaseTest.class.getResource(INPUT_DIR); + + File inputDir = null; + try { + inputDir = new File(url.toURI()); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + File[] files = inputDir.listFiles(); + for (File inputFile : files) { + heatTreeManager.addFile(inputFile.getName(), FileUtils.loadFileToInputStream( + INPUT_DIR.replace("/", File.separator) + File.separator + inputFile.getName())); + } + return heatTreeManager; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java new file mode 100644 index 0000000000..ee31ba4d70 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -0,0 +1,90 @@ +package org.openecomp.sdc.vendorsoftwareproduct.tree; + +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; +import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VSPCommon; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.*; +import java.net.URL; +import java.util.zip.ZipOutputStream; + +public class UploadFileTest { + + + public static final Version VERSION01 = new Version(0, 1); + private static final String USER1 = "vspTestUser1"; + public static String id001 = null; + public static String id002 = null; + public static Version activeVersion002 = null; + private static VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static VendorLicenseFacade vendorLicenseFacade = + VendorLicenseFacadeFactory.getInstance().createInterface(); + private static String vlm1Id; + + @BeforeClass + static public void init() { + + //testCreateVSP + vlm1Id = vendorLicenseFacade.createVendorLicenseModel( + VSPCommon.createVendorLicenseModel("vlmName", "vlm1Id desc", "icon1"), USER1).getId(); + VspDetails expectedVsp = VSPCommon + .createVspDetails(null, null, "VSP1", "Test-vsp", "vendorName", vlm1Id, "icon", "category", + "subCategory", "123", null); + + VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1); + id001 = createdVsp.getId(); + + VspDetails actualVsp = + vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01)); + expectedVsp.setId(id001); + expectedVsp.setVersion(VERSION01); + + + } + + @Test + public void testUploadFile() { + //vspActiveVersion = vendorSoftwareProductManager.checkout(id001, USER1); + vendorSoftwareProductManager.uploadFile(id001, getZipInputStream("/legalUpload"), USER1); + //testLegalUpload(id001, vspActiveVersion, getZipInputStream("/legalUpload"), USER1); + } + + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + vendorSoftwareProductManager.uploadFile(vspId, upload, user); + + UploadDataEntity uploadData = + vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version)); + + } + + public InputStream getZipInputStream(String name) { + URL url = this.getClass().getResource(name); + File templateDir = new File(url.getFile()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ZipOutputStream zos = new ZipOutputStream(baos); + + VSPCommon.zipDir(templateDir, "", zos, true); + try { + zos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return new ByteArrayInputStream(baos.toByteArray()); + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java new file mode 100644 index 0000000000..f1bf5682e0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java @@ -0,0 +1,167 @@ +package org.openecomp.sdc.vendorsoftwareproduct.upload.HeatCleanup; + +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.vendorsoftwareproduct.VSPCommon; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.validation.types.MessageContainerUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +public class HeatCleanupOnNewUploadTest { + private static final String USER1 = "vspTestUser1"; + + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static final ServiceModelDao serviceModelDao = + ServiceModelDaoFactory.getInstance().createInterface(); + + private static String vspId = null; + private static Version vspActiveVersion = null; + + private static void validateUploadContentExistence(boolean exist) { + UploadDataEntity uploadDataEntity = + vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, vspActiveVersion)); + Assert.assertTrue((uploadDataEntity.getContentData() != null) == exist); + Assert.assertTrue((uploadDataEntity.getValidationData() != null) == exist); + Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist); + Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist); + Assert.assertTrue((serviceModelDao.getServiceModel(vspId, vspActiveVersion) != null) == exist); + } + + private static void validateCompositionDataExistence(boolean exist) { + Assert.assertTrue(CollectionUtils + .isNotEmpty(vendorSoftwareProductDao.listNetworks(vspId, vspActiveVersion)) == exist); + Assert.assertTrue(CollectionUtils + .isNotEmpty(vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion)) == exist); + Assert.assertTrue(CollectionUtils + .isNotEmpty(vendorSoftwareProductDao.listNicsByVsp(vspId, vspActiveVersion)) == exist); + } + + private static InputStream getFileInputStream(String fileName) { + URL url = HeatCleanupOnNewUploadTest.class.getResource(fileName); + try { + return url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @BeforeClass + private void init() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSPTestEmpty"); + + VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSPTestEmpty", "Test-vsp-empty", "vendorName", "vlm1Id", + "icon", "category", "subCategory", "123", null), USER1); + vspId = vspDetails.getId(); + vspActiveVersion = vspDetails.getVersion(); + } + + @Test + public void testUploadWithComposition() { + InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); + + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(vspId, zis, USER1); + + Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success); + Assert.assertTrue(MapUtils.isEmpty( + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); + + validateUploadContentExistence(true); + validateCompositionDataExistence(true); + } + + @Test(dependsOnMethods = {"testUploadWithComposition"}) + public void testProccesesMIBsDeletionAfterNewUpload() { + InputStream zis1 = getFileInputStream("/vspmanager/zips/fullComposition.zip"); + InputStream zis2 = getFileInputStream("/vspmanager/zips/fullComposition.zip"); + InputStream mib = getFileInputStream("/vspmanager/zips/vDNS.zip"); + + vendorSoftwareProductManager.uploadFile(vspId, zis1, USER1); + List<ComponentEntity> components = + (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion); + String componentId = components.get(0).getId(); + + vendorSoftwareProductManager + .uploadComponentMib(mib, "vDNS.zip", vspId, componentId, true, USER1); + vendorSoftwareProductManager + .createProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1); + + vendorSoftwareProductManager.uploadFile(vspId, zis2, USER1); + Assert.assertTrue( + vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1).getSnmpTrap() == + null); + Assert.assertTrue(CollectionUtils + .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId))); + } + + @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"}) + public void testInvalidStructureUploadAfterFullComposition() { + InputStream zis = getFileInputStream("/vspmanager/zips/withoutManifest.zip"); + + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(vspId, zis, USER1); + Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Failure); + Assert.assertTrue(MapUtils.isNotEmpty( + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); + + validateUploadContentExistence(true); + validateCompositionDataExistence(true); + } + + @Test(dependsOnMethods = {"testInvalidStructureUploadAfterFullComposition"}) + public void testInvalidUploadAfterFullComposition() { + InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip"); + + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(vspId, zis, USER1); + Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success); + Assert.assertTrue(MapUtils.isNotEmpty( + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); + + validateUploadContentExistence(true); + validateCompositionDataExistence(false); + } + + @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"}) + public void testEmptyCompositionUploadAfterFullComposition() throws IOException { + testUploadWithComposition(); + + InputStream zis = getFileInputStream("/vspmanager/zips/emptyComposition.zip"); + UploadFileResponse uploadFileResponse = + vendorSoftwareProductManager.uploadFile(vspId, zis, USER1); + Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success); + Assert.assertTrue(MapUtils.isEmpty( + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); + + validateUploadContentExistence(true); + validateCompositionDataExistence(false); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java new file mode 100644 index 0000000000..3ec8cb2e40 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java @@ -0,0 +1,199 @@ +package org.openecomp.sdc.vendorsoftwareproduct.upload.validation; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.utils.AsdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorMessage; + +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.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.validation.errors.Messages; +import org.openecomp.core.validation.types.MessageContainerUtil; +import org.apache.commons.collections4.MapUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.io.*; +import java.net.URL; +import java.util.List; +import java.util.Map; + +public class UploadFileValidationTest { + + private static final String USER1 = "UploadFileValidationTest"; + private static final String EMPTY_ZIP_FILE = "/validation/zips/emptyZip.zip"; + private static final String MISSING_MANIFEST_IN_ZIP_FILE = + "/validation/zips/missingManifestInZip.zip"; + private static final String ZIP_FILE_WITH_FOLDER = "/validation/zips/zipFileWithFolder.zip"; + private static VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static String vspId; + + 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() { + VspDetails vspDetails = new VspDetails(); + vspDetails.setVendorName("vspName_" + CommonMethods.nextUuId()); + vspId = vendorSoftwareProductManager.createNewVsp(vspDetails, USER1).getId(); + + UniqueValueUtil + .deleteUniqueValue(org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP_syb_upload_various"); + UniqueValueUtil + .deleteUniqueValue(org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "vsp_syb_upload_no_error"); + UniqueValueUtil + .deleteUniqueValue(org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "vsp_syb"); + } + + @Test + public void testUploadZipNull() { + UploadFileResponse response = vendorSoftwareProductManager.uploadFile(vspId, null, USER1); + Assert.assertEquals(response.getErrors().size(), 1); + Assert.assertTrue(response.getErrors().containsKey(AsdcCommon.UPLOAD_FILE)); + Assert.assertEquals(response.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(), + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()); + } + + @Test(dependsOnMethods = "testUploadZipNull") + public void testUploadEmptyFile() { + UploadFileResponse response = vendorSoftwareProductManager + .uploadFile(vspId, new ByteArrayInputStream("".getBytes()), USER1); + Assert.assertEquals(response.getErrors().size(), 1); + Assert.assertTrue(response.getErrors().containsKey(AsdcCommon.UPLOAD_FILE)); + Assert.assertEquals(response.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(), + Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()); + } + + @Test(dependsOnMethods = "testUploadEmptyFile") + public void testUploadEmptyZip() { + UploadFileResponse response = + vendorSoftwareProductManager.uploadFile(vspId, getFileInputStream(EMPTY_ZIP_FILE), USER1); + Assert.assertEquals(response.getErrors().size(), 1); + Assert.assertTrue(response.getErrors().containsKey(AsdcCommon.UPLOAD_FILE)); + Assert.assertEquals(response.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(), + Messages.INVALID_ZIP_FILE.getErrorMessage()); + } + + @Test(dependsOnMethods = "testUploadEmptyZip") + public void testUploadMissingManifestInZip() { + UploadFileResponse response = vendorSoftwareProductManager + .uploadFile(vspId, getFileInputStream(MISSING_MANIFEST_IN_ZIP_FILE), USER1); + Assert.assertEquals(response.getErrors().size(), 1); + Assert.assertTrue(response.getErrors().containsKey(AsdcCommon.MANIFEST_NAME)); + Assert.assertEquals(response.getErrors().get(AsdcCommon.MANIFEST_NAME).get(0).getMessage(), + Messages.MANIFEST_NOT_EXIST.getErrorMessage()); + } + + @Test(dependsOnMethods = "testUploadMissingManifestInZip") + public void testUploadZipWithFolder() { + UploadFileResponse response = vendorSoftwareProductManager + .uploadFile(vspId, getFileInputStream(ZIP_FILE_WITH_FOLDER), USER1); + Assert.assertEquals(response.getErrors().size(), 1); + Assert.assertTrue(response.getErrors().containsKey(AsdcCommon.UPLOAD_FILE)); + Assert.assertEquals(response.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(), + Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage()); + } + + @Test(dependsOnMethods = "testUploadZipWithFolder") + public void testUploadVariousZips() { + + File[] files = getFileList("/validation/zips/various"); + InputStream is; + for (File file : files) { + if (file.isFile()) { + UploadFileResponse response = null; + try { + + is = new FileInputStream(file); + response = vendorSoftwareProductManager.uploadFile(vspId, is, USER1); + + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (CoreException ce) { + throw new RuntimeException("failed upload:" + file.getName(), ce); + } catch (RuntimeException re) { + + throw new RuntimeException("failed upload:" + file.getName(), re); + } + System.out.println("zip:" + file.getName() + " Errors:" + calculateNumberOfMessages( + MessageContainerUtil.getMessageByLevel(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, response.getErrors())) + + " Warnings:" + calculateNumberOfMessages( + MessageContainerUtil.getMessageByLevel(org.openecomp.sdc.datatypes.error.ErrorLevel.WARNING, response.getErrors()))); + } + } + } + + @Test(dependsOnMethods = "testUploadVariousZips") + public void testUploadNoErrorVariousZips() { + + + File[] files = getFileList("/validation/zips/various/noError"); + InputStream is; + for (File file : files) { + if (file.isFile()) { + try { + is = new FileInputStream(file); + UploadFileResponse response = vendorSoftwareProductManager.uploadFile(vspId, is, USER1); + Map<String, List<ErrorMessage>> errors = response.getErrors(); + Assert.assertTrue( + MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel( + org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, errors))); + + + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (CoreException ce) { + Assert.fail("failed upload:" + file.getName() + " exception:" + ce.getMessage()); + + } catch (RuntimeException re) { + Assert.fail("failed upload:" + file.getName() + " exception:" + re.getMessage()); + } + } + } + } + + private InputStream getFileInputStream(String fileName) { + URL url = this.getClass().getResource(fileName); + try { + return url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private File[] getFileList(String dir) { + URL url = UploadFileValidationTest.class.getResource(dir); + + String path = url.getPath(); + File pathFile = new File(path); + return pathFile.listFiles(); + + + } + + private int calculateNumberOfMessages(Map<String, List<ErrorMessage>> messages) { + int sum = 0; + for (List<ErrorMessage> errors : messages.values()) { + sum += errors.size(); + } + return sum; + } + + +} |