diff options
author | Avi Ziv <avi.ziv@amdocs.com> | 2017-07-18 19:45:38 +0300 |
---|---|---|
committer | Avi Ziv <avi.ziv@amdocs.com> | 2017-07-18 19:45:38 +0300 |
commit | b8e2faf476202b6ffe61bc3a9a37df1304881d40 (patch) | |
tree | f78b8c0517d8e16c5ae610bf8b49f68ea8a312a1 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test | |
parent | 75aacbbe1acf78fa53378f07f0a8c7769449a17e (diff) |
[SDC] Onboarding 1710 rebase.
Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535
Signed-off-by: Avi Ziv <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test')
22 files changed, 3317 insertions, 221 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComputeTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComputeTest.java new file mode 100644 index 0000000000..ab7a70b6a7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ComputeTest.java @@ -0,0 +1,293 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_COMPUTE_NAME_NOT_ALLOWED; + +import org.openecomp.core.utilities.CommonMethods; +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.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class ComputeTest { + + /*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 VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory + .getInstance().createInterface(); + + private static String vsp1Id; + private static String vsp2Id; + private static String comp1 = "{\"displayName\": \"VFC_Manual\", " + + "\"description\": \"desc manual\"}"; + private static String compute1 = "{\"name\": \"Compute_A\", " + + "\"description\": \"desc manual compute\"}"; + private static String computeDelete = "{\"name\": \"Compute_Delete\", " + + "\"description\": \"desc manual compute delete\"}"; + + private static String comp1Id; + private static String compute1Id; + private ComputeEntity createdCompute; + + static ComponentEntity createComponent(String vspId, Version version, String compId) { + ComponentEntity componentEntity = new 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; + } + + static ComputeEntity createComputeEntity(String vspId, String componentId, String data ){ + ComputeEntity comp = new ComputeEntity(); + comp.setVspId(vspId); + comp.setComponentId(componentId); + comp.setCompositionData(data); + return comp; + } + + @BeforeClass + private void init() { + VspDetails + vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null, + VSPCommon.OnboardingMethod.HEAT.name()), USER1 + ); + vsp1Id = vsp1.getId(); //HEAT onboarded + + VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3", + "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon + .OnboardingMethod.Manual.name()), USER1); + vsp2Id = vsp2.getId(); //MANUAL onboarded + + ComponentEntity component = new ComponentEntity(); + component.setVspId(vsp2Id); + component.setCompositionData(comp1); + ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(component, USER1); + comp1Id = createdComp.getId(); + } + + @Test + public void testListWhenNone() { + + final Collection<ListComputeResponse> listComputeResponses = + vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1); + Assert.assertEquals(listComputeResponses.size(), 0); + } + + @Test + public void testCreateComputeInHeatOnboardedVsp_negative() { + ComputeEntity comp = createComputeEntity(vsp1Id,comp1Id,compute1); + try { + createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1); + Assert.fail(); + } + catch(CoreException exception){ + Assert.assertEquals(exception.code().id(),ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + } + + @Test(dependsOnMethods = "testListWhenNone") + public void testCreateCompute() { + ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1); + + createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1); + compute1Id = createdCompute.getId(); + Assert.assertNotNull(compute1Id); + Assert.assertNotNull(createdCompute.getCompositionData()); + Assert.assertNotNull( + vendorSoftwareProductManager.getCompute(vsp2Id, VERSION01, comp1Id,compute1Id, + USER1).getData()); + } + + @Test(dependsOnMethods = "testCreateCompute") + public void testCreateComputeNegative() { + ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1); + + try { + ComputeEntity createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1); + Assert.fail(); + } + catch (CoreException exception) { + Assert.assertEquals(exception.code().id(),DUPLICATE_COMPUTE_NAME_NOT_ALLOWED); + } + } + + @Test + public void testGetNonExistingComponentId_negative() { + testGet_negative(vsp1Id, null, "non existing component id", compute1Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, comp1Id, compute1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testGetNonExistingComputeId_negative() { + testGet_negative(vsp1Id, null, comp1Id, "non existing compute id", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreateCompute") + public void testGetCompute() { + testGet(vsp2Id, VERSION01, comp1Id, compute1Id, USER1, createdCompute); + } + + + @Test(dependsOnMethods = "testCreateCompute") + public void testListCompute() { + + final Collection<ListComputeResponse> actual = + vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1); + Assert.assertEquals(actual.size(), 1); + actual.forEach(listComputeResponse -> { + Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), false); + } ); + } + + + @Test(dependsOnMethods = "testListCompute") + public void testListComputeAssociatedWithDeployment() { + + //Create DF and associate compute1Id CF to it + String deployment1Id = null; + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id, + VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("DF_testListComputeAssociatedWithDeployment"); + deploymentFlavor.setDescription("creating a deployment flavor with compute flavor association"); + ComponentComputeAssociation association = new ComponentComputeAssociation(); + association.setComponentId(comp1Id); + association.setComputeFlavorId(compute1Id); + List<ComponentComputeAssociation> associations = new ArrayList<ComponentComputeAssociation>(); + associations.add(association); + deploymentFlavor.setComponentComputeAssociations(associations); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + + DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + Assert.assertEquals((createddeployment.getId() != null), true); + deployment1Id = createddeployment.getId(); + + final Collection<ListComputeResponse> actual = + vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1); + Assert.assertEquals(actual.size(), 1); + actual.forEach(listComputeResponse -> { + Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), true); + } ); + } + + @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 + public void testDelete() { + ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,computeDelete); + + ComputeEntity created = vendorSoftwareProductManager.createCompute(comp, USER1); + + vendorSoftwareProductManager.deleteCompute(vsp2Id,comp1Id,created.getId(),USER1); + testGet_negative(vsp2Id,null, comp1Id, created.getId(),USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteNonExistingComputeId_negative() { + testDelete_negative(vsp2Id,comp1Id,"InvalidComputeId",USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteNonExistingComponentId_negative() { + testDelete_negative(vsp2Id,"InvalidComponentId",compute1Id,USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteNonExistingVspId_negative() { + testDelete_negative("InvalidVspId",comp1Id,compute1Id,USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST); + } + + private void testGet(String vspId, Version version, String componentId, String computeId, String + user, ComputeEntity expected) { + CompositionEntityResponse<ComputeData> + response = vendorSoftwareProductManager.getCompute(vspId, null, componentId, computeId, + user); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData(), expected.getComputeCompositionData()); + Assert.assertNotNull(response.getSchema()); + } + + private void testGet_negative(String vspId, Version version, String componentId, String computeId, + String user, String expectedErrorCode) { + try { + vendorSoftwareProductManager.getCompute(vspId, version, componentId, computeId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, String componentId, String computeId, String user, + String expectedErrorCode){ + try { + vendorSoftwareProductManager.deleteCompute(vspId, componentId, computeId, user); + Assert.fail(); + } + catch(CoreException exception){ + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testUpdate_negative(String vspId, String componentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager + .updateComponent(new ComponentEntity(vspId, null, componentId), user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + }*/ +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/DeploymentFlavorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/DeploymentFlavorTest.java new file mode 100644 index 0000000000..e3fa0a8480 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/DeploymentFlavorTest.java @@ -0,0 +1,432 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID; +import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST; +import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND; + +import org.openecomp.core.utilities.CommonMethods; +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.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class DeploymentFlavorTest { + /*private static final String USER1 = "deploymentTestUser1"; + private static final String USER2 = "deploymentTestUser2"; + private static final Version VERSION01 = new Version(0, 1); + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + + private static String vsp1Id; + private static String vsp2Id; + private static String vsp3Id; + private static String component11Id; + private static String component21Id; + private static String deployment1Id = "deployment1"; + private static String deployment2Id = "deployment2"; + + @BeforeClass + private void init() { + List<String> featureGroups = new ArrayList<>(); + featureGroups.add("fg01"); + featureGroups.add("fg02"); + vsp1Id = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", featureGroups, + VSPCommon.OnboardingMethod. + Manual.name()), USER1).getId(); + 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, + VSPCommon.OnboardingMethod.Manual.name()), USER1).getId(); + component21Id = ComponentsTest.createComponent(vsp2Id, VERSION01, "component21").getId(); + + vsp3Id = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3forDeployment", + "vendorName1", + "vlm1Id", "icon", "category", "subCategory", "123", null, + VSPCommon.OnboardingMethod.HEAT.name()), USER1).getId(); + } + + static DeploymentFlavorEntity createDeploymentFlavor(String vspId, Version version, String deploymentFlavorId) { + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel(deploymentFlavorId + " name"); + deploymentFlavor.setDescription(deploymentFlavorId + " desc"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager + .createDeploymentFlavor(deploymentFlavorEntity, USER1); + deployment2Id = createdDeployment.getId(); + return deploymentFlavorEntity; + } + + @Test + public void testCreate() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentcreatewithoutFG"); + deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " + + "association"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + Assert.assertEquals((createddeployment.getId() != null), true); + deployment1Id = createddeployment.getId(); + } + + @Test(dependsOnMethods = "testCreate") + public void testUniqueModelCreate() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentcreatewithoutFG"); + deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " + + "association"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED); + } + } + + @Test + public void testInvalidFeatureGroup() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestInvalidFeatureGroup"); + deploymentFlavor.setDescription("creating a deployment flavor with invalid FG and without any" + + " " + + "association"); + deploymentFlavor.setFeatureGroupId("fg01"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), FEATURE_GROUP_NOT_EXIST_FOR_VSP); + } + } + + @Test + public void testInvalidAssociation() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("testInvalidAssociation"); + deploymentFlavor.setDescription("creating a deployment flavor with wrong association with " + + "null compute flavor id"); + List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>(); + ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation(); + componentComputeAssociation.setComputeFlavorId("72138712"); + componentComputeAssociationList.add(componentComputeAssociation); + deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), INVALID_COMPONENT_COMPUTE_ASSOCIATION); + } + + } + + @Test + public void testInvalidComputeFlavorIdAssociation() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("testInvalidComputeFlavorIdAssociation"); + deploymentFlavor.setDescription("creating a deployment flavor with wrong compute flavor id in" + + " assocation"); + List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>(); + ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation(); + componentComputeAssociation.setComponentId(component21Id); + componentComputeAssociation.setComputeFlavorId("123123"); + componentComputeAssociationList.add(componentComputeAssociation); + deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), INVALID_COMPUTE_FLAVOR_ID); + } + + } + + @Test + public void testInvalidVfcIdAssociation() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("testInvalidVfcIdAssociation"); + deploymentFlavor.setDescription("creating a deployment flavor with invalid vfcid association"); + List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>(); + ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation(); + componentComputeAssociation.setComponentId("WRONGVFCID"); + componentComputeAssociation.setComputeFlavorId("123123"); + componentComputeAssociationList.add(componentComputeAssociation); + deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + } + + @Test + public void testNegativeforVspHeatOnboarded() { + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp3Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentcreatewithoutFG"); + deploymentFlavor.setDescription("creating a deployment flavor for VSP onboarded with HEAT"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + try { + vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), + CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + } + + @Test + public void testGetNegative_InvalidVspId(){ + testGetNegative("InvalidVspId", VERSION01, deployment1Id, USER1, VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testGetNegative_InvalidDeploymentFlavorId(){ + testGetNegative(vsp1Id, VERSION01, deployment1Id, USER1, VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGet(){ + DeploymentFlavorEntity expected = createDeploymentFlavor(vsp1Id, VERSION01,deployment2Id); + testGet(vsp1Id, VERSION01, deployment2Id, USER1, expected); + } + + private void testGet(String vspId, Version version, String componentId, String user, + DeploymentFlavorEntity expected) { + CompositionEntityResponse<DeploymentFlavor> response = vendorSoftwareProductManager + .getDeploymentFlavor(vspId, null, componentId, user); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData().getDescription(), + expected.getDeploymentFlavorCompositionData().getDescription()); + Assert.assertEquals(response.getData().getModel(), + expected.getDeploymentFlavorCompositionData().getModel()); + Assert.assertEquals(response.getData().getFeatureGroupId(), + expected.getDeploymentFlavorCompositionData().getFeatureGroupId()); + Assert.assertEquals(response.getData().getComponentComputeAssociations(), + expected.getDeploymentFlavorCompositionData().getComponentComputeAssociations()); + Assert.assertNotNull(response.getSchema()); + } + + private void testGetNegative(String vspId, Version version, String deploymentFlavorId, String User, + String expectedErrorCode){ + try{ + vendorSoftwareProductManager.getDeploymentFlavor(vspId, version, deploymentFlavorId, User); + Assert.fail(); + } catch (CoreException exception){ + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + @Test + public void testUpdateNegative_InvalidVspId(){ + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity("InvalidVspId", + VERSION01,deployment2Id); + DeploymentFlavor deploymentFlavorData = new DeploymentFlavor(); + deploymentFlavorData.setModel(deployment2Id); + deploymentFlavorData.setDescription("updating a deployment flavor with invalid VspId and without any" + + "association"); + deploymentFlavorData.setFeatureGroupId("fg01"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData); + + testUpdateNegative(deploymentFlavorEntity, USER1, VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testUpdateNegative_InvalidDeploymentFlavorId(){ + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp1Id, + VERSION01,"InvalidDeploymentFlavorId"); + testUpdateNegative(deploymentFlavorEntity, USER1, VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test(dependsOnMethods = "testCreate") + public void testUpdateNegative_InvalidFeatureGroup(){ + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id, + VERSION01,deployment1Id); + DeploymentFlavor deploymentFlavorData = new DeploymentFlavor(); + deploymentFlavorData.setModel("TestDeploymentCreateWithoutFG"); + deploymentFlavorData.setDescription("updating a deployment flavor with invalid FeatureGroupId and without any" + + "association"); + deploymentFlavorData.setFeatureGroupId("fg01"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData); + String expectedError = "#/featureGroupId: " + +deploymentFlavorData.getFeatureGroupId()+" is not a valid value. Possible values: "; + + final CompositionEntityValidationData validationData = vendorSoftwareProductManager + .updateDeploymentFlavor(deploymentFlavorEntity, USER1); + final Collection<String> errors = validationData.getErrors(); + final Object[] objects = errors.toArray(); + Assert.assertEquals(errors.size(), 1); + Assert.assertEquals(objects[0], expectedError); + } + + @Test(dependsOnMethods = "testCreate") + public void testUpdateNegative_InvalidComputeFlavorIdAssociation(){ + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id, + VERSION01,deployment1Id); + DeploymentFlavor deploymentFlavorData = new DeploymentFlavor(); + deploymentFlavorData.setModel("TestDeploymentcreatewithInvalidComputFlavorId"); + deploymentFlavorData.setDescription("updating a deployment flavor with wrong compute flavor id in" + + " assocation"); + List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>(); + ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation(); + componentComputeAssociation.setComponentId(component21Id); + componentComputeAssociation.setComputeFlavorId("123123"); + componentComputeAssociationList.add(componentComputeAssociation); + deploymentFlavorData.setComponentComputeAssociations(componentComputeAssociationList); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData); + + testUpdateNegative(deploymentFlavorEntity, USER1, INVALID_COMPUTE_FLAVOR_ID); + } + + @Test + public void testUpdate(){ + //Creating a separate deployment flavor for testing deletion + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp1Id, VERSION01, deployment2Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentCreateforUpdate"); + deploymentFlavor.setDescription("creating a deployment flavor for updation"); + deploymentFlavor.setFeatureGroupId("fg01"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + deployment2Id = createdDeployment.getId(); + + final DeploymentFlavor deploymentFlavorCompositionData = createdDeployment.getDeploymentFlavorCompositionData(); + deploymentFlavorCompositionData.setModel("TestDeploymentCreateforUpdate"); //no change + deploymentFlavorCompositionData.setDescription("updating deployment flavor"); //allow change + deploymentFlavorCompositionData.setFeatureGroupId("fg01"); //no change + createdDeployment.setDeploymentFlavorCompositionData(deploymentFlavorCompositionData); + + vendorSoftwareProductManager.updateDeploymentFlavor(createdDeployment, USER1); + CompositionEntityResponse<DeploymentFlavor> deploymentFlavorCompositionEntityResponse = vendorSoftwareProductManager + .getDeploymentFlavor(vsp1Id, VERSION01, deployment2Id, USER1); + final DeploymentFlavor data = deploymentFlavorCompositionEntityResponse.getData(); + + Assert.assertEquals( + data.getDescription(),createdDeployment.getDeploymentFlavorCompositionData().getDescription()); + } + + @Test + public void testUpdateVspWithNoFeatureGroup(){ + //Creating a separate deployment flavor for testing deletion + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentCreateforUpdate"); + deploymentFlavor.setDescription("creating a deployment flavor for updation"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager + .createDeploymentFlavor(deploymentFlavorEntity, USER1); + deployment1Id = createdDeployment.getId(); + + final DeploymentFlavor deploymentFlavorCompositionData = createdDeployment.getDeploymentFlavorCompositionData(); + deploymentFlavorCompositionData.setModel("TestDeploymentCreateforUpdate"); //no change + deploymentFlavorCompositionData.setDescription("updating deployment flavor"); //allow change + createdDeployment.setDeploymentFlavorCompositionData(deploymentFlavorCompositionData); + + vendorSoftwareProductManager.updateDeploymentFlavor(createdDeployment, USER1); + CompositionEntityResponse<DeploymentFlavor> deploymentFlavorCompositionEntityResponse = + vendorSoftwareProductManager.getDeploymentFlavor(vsp2Id, VERSION01, deployment1Id, USER1); + final DeploymentFlavor data = deploymentFlavorCompositionEntityResponse.getData(); + + Assert.assertEquals(data.getDescription(),createdDeployment.getDeploymentFlavorCompositionData() + .getDescription()); + } + + private void testUpdateNegative(DeploymentFlavorEntity deploymentFlavorEntity, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager + .updateDeploymentFlavor(deploymentFlavorEntity, user); + System.out.print("updated"); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + @Test + public void testDelete(){ + //Creating a separate deployment flavor for testing deletion + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment2Id); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel("TestDeploymentcreateWithoutFG"); + deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " + + "association"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor + (deploymentFlavorEntity, USER1); + deployment2Id = createddeployment.getId(); + vendorSoftwareProductManager.deleteDeploymentFlavor(vsp2Id, deployment2Id, USER1); + testDeleteNegative(vsp2Id, deployment2Id, USER1, + VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteNegative_InvalidVspId(){ + testDeleteNegative("InvalidVspId", deployment2Id, USER1, + VERSIONABLE_ENTITY_NOT_EXIST); + } + + @Test + public void testDeleteNegative_NonExistingDeploymentFlavorId(){ + testDeleteNegative(vsp2Id, "NonExistingDeploymentFlavorId", USER1, + VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + private void testDeleteNegative(String vspId, String deploymentId, String user, + String expectedErrorCode) { + try { + vendorSoftwareProductManager + .deleteDeploymentFlavor(vspId, deploymentId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + }*/ +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java new file mode 100644 index 0000000000..afd797573a --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java @@ -0,0 +1,463 @@ +package org.openecomp.sdc.vendorsoftwareproduct; + +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCode; +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.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.ImageErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; +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.QuestionnaireResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.image.ImageDetails; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collection; + +public class ImagesTest { + + /*private static final String USER1 = "imageTestUser1"; + private static final String USER2 = "imageTestUser2"; + private static final Version VERSION01 = new Version(0, 1); + private static final VendorSoftwareProductManager vendorSoftwareProductManager = + new VendorSoftwareProductManagerImpl(); + private static final VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory + .getInstance().createInterface(); + + private static String image1Id; + + + private static String comp1 = "{\"displayName\": \"VFC_Manual\", " + + "\"description\": \"desc manual\"}"; + + private static String vsp1Id; + private static String vsp2Id; + private static String vsp3Id; + private static String comp1Id; + + private static String image2Id; + + @BeforeClass + private void init() { + VspDetails + vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null, + VSPCommon.OnboardingMethod.Manual.name()), USER1 + ); + vsp1Id = vsp1.getId(); + + VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod. + Manual.name()), USER1); + vsp2Id = vsp2.getId(); + + VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon + .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3", + "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon + .OnboardingMethod.HEAT.name()), USER1); + vsp3Id = vsp3.getId(); + + ComponentEntity comp = new ComponentEntity(); + comp.setVspId(vsp2Id); + comp.setCompositionData(comp1); + ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1); + comp1Id = createdComp.getId(); + } + + @Test + public void testListImagesNonExistingVspId_negative() { + testList_negative("non existing vsp id", null, image1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, + "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); + } + + @Test + public void testListImagesNonExistingVfcId_negative() { + testList_negative(vsp1Id, VERSION01, "444", USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product " + + "with id "+vsp1Id+ " and version "+VERSION01); + } + + @Test + public void testListImages() { + createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki"); + createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi"); + final Collection<ImageEntity> imageEntities = + vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id, USER1); + System.out.println("size::"+imageEntities.size()); + } + + @Test + public void testCreateNonExistingVspId_negative() { + testCreate_negative(new ImageEntity("non existing vsp id", null, null, null), USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, + "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist."); + } + + @Test + public void testCreateNonExistingVfcId_negative() { + testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null), USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product " + + "with id "+vsp1Id + " and version "+VERSION01); + } + + @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative") + public void testCreateOnAvailableVsp_negative() { + vendorSoftwareProductManager.checkin(vsp1Id, USER1); + testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER1, + VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY, + "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not" + + " checked out."); + } + + @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative") + public void testCreateOnVspOtherUser_negative() { + vendorSoftwareProductManager.checkout(vsp1Id, USER1); + testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER2, + VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER, + "Versionable entity VendorSoftwareProduct with id " +vsp1Id+ + " can not be edited since it is locked by other user "+ USER1+ "."); + } + + @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative") + public void testOnUndoCheckoutImagesDeleted() { + + ComponentEntity comp = new ComponentEntity(); + comp.setVspId(vsp1Id); + comp.setCompositionData(comp1); + ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1); + String compId = createdComp.getId(); + + vendorSoftwareProductManager.checkin(vsp1Id, USER1); + vendorSoftwareProductManager.checkout(vsp1Id, USER1); + + for(int i = 1; i<=3; i++) { + ImageEntity imageEntity = new ImageEntity(); + imageEntity.setVspId(vsp1Id); + imageEntity.setComponentId(compId); + Image image = new Image(); + image.setFileName(i + "testimage.aki"); + //image.setVersion("9.2.0"); + image.setDescription("riverbed image"); + //image.setFormat("aki"); + //image.setMd5("233343DDDD"); + imageEntity.setImageCompositionData(image); + ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1); + } + + Collection<ImageEntity> imageEntities = + vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1); + + Assert.assertEquals(imageEntities.size(), 3); + + vendorSoftwareProductManager.undoCheckout(vsp1Id, USER1); + + imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1); + + Assert.assertEquals(imageEntities.size(), 0); + } + + @Test + public void testCreateOnHeatVsp_negative() { + final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder = + NotSupportedHeatOnboardMethodErrorBuilder + .getAddImageNotSupportedHeatOnboardMethodErrorBuilder(); + testCreate_negative(new ImageEntity(vsp3Id, null, null, null), USER1, + addImageNotSupportedHeatOnboardMethodErrorBuilder.id(), + addImageNotSupportedHeatOnboardMethodErrorBuilder.message() + ); + } + + @Test(dependsOnMethods = "testListImages") + public void testCreateImage() { + ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2"); + Assert.assertNotNull(image1Id); + Assert.assertNotNull(createdImage.getCompositionData()); + Assert.assertNotNull( + vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id, + USER1).getData()); + } + + @Test(dependsOnMethods = "testCreateImage") + public void testCreateDupImageNameForSameComponent_negative() { + ImageEntity createdImage = null; + try { + createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2"); + Assert.fail(); + } + catch(CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes. + DUPLICATE_IMAGE_NAME_NOT_ALLOWED); + Assert.assertEquals(exception.getMessage(), + String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " + + "exists for component with ID "+comp1Id)+"."); + } + } + + @Test + public void testGet() { + ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2"); + testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId(), USER1, createdImage); + } + + @Test + public void testGetNonExistingVspId_negative() { + testGet_negative("non existing vsp id", null, null, image1Id, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, + "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); + } + + @Test + public void testGetNonExistingVfcId_negative() { + testGet_negative(vsp1Id, VERSION01, "111", null, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product " + + "with id "+vsp1Id + " and version "+VERSION01); + } + + @Test + public void testUpdateNonExistingVspId_negative() { + ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id); + + testUpdate_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, + "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); + } + + @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative") + public void testUpdateNonExistingVfcId_negative() { + ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null); + + testUpdate_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product " + + "with id "+vsp1Id + " and version "+VERSION01); + } + + @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative") + public void testUpdateNonExistingImageId_negative() { + ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222"); + + testUpdate_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component Image with Id 222 does not exist for Vendor " + + "Software Product with id "+vsp2Id+ " and version "+VERSION01 ); + } + + @Test(dependsOnMethods = "testCreateImage") + public void testUpdate() { + ImageEntity imageEntity = createImageEntity("testimage1","qcow2"); + testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity ); + + final Image imageCompositionData = imageEntity.getImageCompositionData(); + //imageCompositionData.setVersion("10.0"); + imageCompositionData.setDescription("updated image"); + + vendorSoftwareProductManager.updateImage(imageEntity, USER1); + + testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity ); + image2Id = imageEntity.getId(); + } + + @Test(dependsOnMethods = "testUpdate") + public void testUpdateNegative_UniqueName() { + final CompositionEntityResponse<Image> image = + vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, + image2Id, USER1); + final Image data = image.getData(); + + final Image imageCompositionData = data; + imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2"); + + ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id ); + entity.setImageCompositionData(imageCompositionData); + testUpdate_negative(entity, USER1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder( + "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id() + ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id) + .message() ); + } + + @Test(dependsOnMethods = "testUpdateNegative_UniqueName") + public void testDeleteImage() { + CompositionEntityResponse<Image> image = + vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id, USER1); + + Assert.assertNotNull(image.getData()); + + vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id, USER1); + + testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " + + "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 ); + + } + + @Test + public void testDeleteNonExistingVspId_negative() { + ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id); + + testDelete_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, + "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); + } + + @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative") + public void testDeleteNonExistingVfcId_negative() { + ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null); + + testDelete_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product " + + "with id "+vsp1Id + " and version "+VERSION01); + } + + @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative") + public void testDeleteNonExistingImageId_negative() { + ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222"); + + testDelete_negative(imageEntity, USER1, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND, + "Vendor Software Product Component Image with Id 222 does not exist for Vendor " + + "Software Product with id "+vsp2Id+ " and version "+VERSION01 ); + } + + @Test + public void testUpdateandGetQuestionnaire() { + ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi"); + vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(), + "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}", + USER1); + + final QuestionnaireResponse imageQuestionnaire = + vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id, + imageEntity.getId(), USER1); + + String imageDetails = imageQuestionnaire.getData(); + Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat()); + Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion()); + Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5()); + } + + @Test + public void testUpdateQuestionnaireInvalidFormat_negative() { + ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi"); + try { + vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(), + "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}", + USER1); + Assert.fail(); + } + catch(CoreException exception) { + Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT"); + Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected " + + "attribute value."); + } + } + + private ImageEntity createImageEntity(String fileName, String format) { + ImageEntity imageEntity = new ImageEntity(); + imageEntity.setVspId(vsp2Id); + imageEntity.setComponentId(comp1Id); + Image image = new Image(); + image.setFileName(fileName); + //image.setVersion("9.2.0"); + image.setDescription("riverbed image"); + //image.setFormat(format); + // image.setMd5("233343DDDD"); + imageEntity.setImageCompositionData(image); + + ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1); + image1Id = createdImage.getId(); + return createdImage; + } + + private void testGet(String vspId, Version version, String componentId, String imageId, String + user, ImageEntity expected) { + CompositionEntityResponse<Image> + response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId, user); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData(). + getFileName()); + Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData(). + getDescription()); + Assert.assertNotNull(response.getSchema()); + } + + private void testCreate_negative(ImageEntity image, String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + vendorSoftwareProductManager.createImage(image, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testGet_negative(String vspId, Version version, String componentId, String imageId, + String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testList_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + vendorSoftwareProductManager.listImages(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testUpdate_negative(ImageEntity imageEntity, + String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + + vendorSoftwareProductManager.updateImage(imageEntity, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testDelete_negative(ImageEntity imageEntity, + String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + + vendorSoftwareProductManager.updateImage(imageEntity, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + }*/ +}
\ 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/VSPFullTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java index d4dea70f2f..be2de13c16 100644 --- 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 @@ -20,43 +20,6 @@ package org.openecomp.sdc.vendorsoftwareproduct; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.io.IOUtils; -import org.openecomp.core.enrichment.types.ArtifactType; -import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.core.utilities.CommonMethods; -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.FeatureGroupEntity; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; -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.NicEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; -import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo; -import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -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 { /* @@ -71,7 +34,7 @@ public class VSPFullTest { private static VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance().createInterface(); private OrchestrationTemplateCandidateManager candidateManager; - private MibManager mibManager; + private MonitoringUploadsManager mibManager; private NicManager nicManager; @Test @@ -106,7 +69,7 @@ public class VSPFullTest { mibManager .upload(zis1, "MMSC.zip", vspId, VERSION01, components.iterator().next().getId(), - ArtifactType.SNMP_TRAP, + MonitoringUploadType.SNMP_TRAP, USER1); //check in diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java index 34af0e67b2..7cfcb05589 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentManagerImplTest.java @@ -8,6 +8,7 @@ import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.vendorsoftwareproduct.NicManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; @@ -24,6 +25,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -47,6 +49,8 @@ public class ComponentManagerImplTest { private CompositionEntityDataManager compositionEntityDataManagerMock; @Mock private NicManager nicManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDao; @InjectMocks @Spy private ComponentManagerImpl componentManager; @@ -95,25 +99,102 @@ public class ComponentManagerImplTest { /* @Test public void testCreate() { COMP1_ID = testCreate(VSP_ID); + }*/ + @Test + public void testCreate() { + ComponentEntity expected = new ComponentEntity(VSP_ID, null, null); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + expected.setComponentCompositionData(compData); + + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<ComponentEntity> vspComponentList = new ArrayList<>(); + doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(expected).when(compositionEntityDataManagerMock).createComponent(anyObject()); + + ComponentEntity created = componentManager.createComponent(expected, USER); + Assert.assertNotNull(created); + //expected.setId(created.getId()); + //expected.setVersion(VERSION); + + //ComponentEntity actual = componentDaoMock.getComponent(VSP_ID, VERSION, created.getId()); + + //Assert.assertEquals(actual, expected); + //return created.getId(); + } + + @Test + public void testCreateWithVspCompListMoreThanOne() { + ComponentEntity expected = new ComponentEntity(VSP_ID, null, null); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + expected.setComponentCompositionData(compData); + + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<ComponentEntity> vspComponentList = new ArrayList<>(); + vspComponentList.add(expected); + doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + + try { + ComponentEntity created = componentManager.createComponent(expected, USER); + } catch (CoreException exception) { + Assert.assertEquals("Creation of only one VFC per VSP allowed.", exception.code().message()); + Assert.assertEquals(VendorSoftwareProductErrorCodes.VSP_VFC_COUNT_EXCEED, + exception.code().id()); } + } - private String testCreate(String VSP_ID) { - ComponentEntity expected = new ComponentEntity(VSP_ID, null, null); - ComponentData compData = new ComponentData(); - compData.setName("comp1 name"); - compData.setDescription("comp1 desc"); - expected.setComponentCompositionData(compData); + @Test + public void testUpdateComp() { + ComponentEntity expected = new ComponentEntity(VSP_ID, null, COMP1_ID); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + expected.setComponentCompositionData(compData); + + doReturn(expected).when(componentDaoMock).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<ComponentEntity> vspComponentList = new ArrayList<>(); + vspComponentList.add(expected); + doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(new CompositionEntityValidationData(null,null)).when(compositionEntityDataManagerMock) + .validateEntity(anyObject(),anyObject(),anyObject()); + + CompositionEntityValidationData created = componentManager.updateComponent(expected, USER); + Assert.assertNotNull(created); + } - ComponentEntity created = componentManager.createComponent(expected, USER); - Assert.assertNotNull(created); - expected.setId(created.getId()); - expected.setVersion(VERSION); + @Test + public void testUpdateCompWithSameVfcDisplayName() { + ComponentEntity expected = new ComponentEntity(VSP_ID, null, COMP1_ID); + ComponentData compData = new ComponentData(); + compData.setName("comp1 name"); + compData.setDescription("comp1 desc"); + compData.setDisplayName("comp1 displayname"); + expected.setComponentCompositionData(compData); - ComponentEntity actual = componentDaoMock.getComponent(VSP_ID, VERSION, created.getId()); + doReturn(expected).when(componentDaoMock).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<ComponentEntity> vspComponentList = new ArrayList<>(); + vspComponentList.add(expected); + ComponentEntity expected2 = new ComponentEntity(VSP_ID+"2", null, COMP1_ID+"2"); + expected2.setComponentCompositionData(compData); + vspComponentList.add(expected2); + doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(new CompositionEntityValidationData(null,null)).when(compositionEntityDataManagerMock) + .validateEntity(anyObject(),anyObject(),anyObject()); - Assert.assertEquals(actual, expected); - return created.getId(); - }*/ + try { + CompositionEntityValidationData created = componentManager.updateComponent(expected, USER); + } catch (CoreException exception) { + Assert.assertEquals("VFC with specified name already present in given VSP.", + exception.code().message()); + Assert.assertEquals(VendorSoftwareProductErrorCodes.VSP_VFC_DUPLICATE_NAME, + exception.code().id()); + } + } /* @Test public void testCreateWithExistingName_negative() { @@ -133,7 +214,7 @@ public class ComponentManagerImplTest { @Test public void testCreateOnUploadVsp_negative() { testCreate_negative(new ComponentEntity(VSP_ID, VERSION, null), USER, - VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + VendorSoftwareProductErrorCodes.VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @Test @@ -159,6 +240,8 @@ public class ComponentManagerImplTest { compData.setName(COMP1_ID + " name"); // no change compData.setDisplayName(COMP1_ID + " display name"); // no change compData.setVfcCode(COMP1_ID + " display name"); // no change + compData.setNfcCode(COMP1_ID + " display name"); // no change + compData.setNfcFunction(COMP1_ID + " display name"); // no change compData.setDescription(COMP1_ID + " desc updated"); // allowed change component.setComponentCompositionData(compData); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java new file mode 100644 index 0000000000..c8f473c8c7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java @@ -0,0 +1,377 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl; + +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ValidationErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.ComputeManager; +import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.DuplicateComputeInComponentErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.*; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Created by DIVESHM on 5/16/2017. + */ + + +public class ComputeManagerImplTest { + + private static final String COMPUTE_NOT_EXIST_MSG = + "Vendor Software Product COMPUTE with Id compute1 does not exist for Vendor Software Product with " + + "id VSP_ID and version 0.1"; + + private static final String USER = "computeTestUser"; + private static final String VSP_ID = "VSP_ID"; + private static final Version VERSION = new Version(0, 1); + private static final String COMPONENT_ID = "COMPONENT_ID"; + private static final String COMPUTE1_ID = "compute1"; + private static final String COMPUTE2_ID = "compute2"; + + @Mock + private ComputeDao computeDao; + + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + + @Mock + private NetworkManager networkManagerMock; + + @Mock + private VendorSoftwareProductInfoDao vspInfoDao; + + @Mock + private ComputeEntity computeEntity; + + @Mock + private ListComputeResponse listComputeResponse; + + @Mock + private DeploymentFlavorEntity deploymentFlavorEntity; + + @Mock + private DeploymentFlavorDao deploymentFlavorDao; + + @Mock + private ComponentComputeAssociation componentComputeAssociation; + + @Mock + DeploymentFlavor deploymentFlavor; + + @InjectMocks + @Spy + private ComputeManagerImpl computeManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testListWhenNone() { + Collection<ListComputeResponse> computes = computeManager.listCompute(VSP_ID, VERSION, COMPONENT_ID, USER); + Assert.assertEquals(computes.size(), 0); + } + + @Test + public void testList(){ + doReturn(Arrays.asList( + createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID), + createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE2_ID))) + .when(computeDao).list(anyObject()); + + + Collection<ListComputeResponse> computes = computeManager.listCompute(VSP_ID, VERSION, COMPONENT_ID, USER); + Assert.assertEquals(computes.size(), 2); + for (ListComputeResponse compute : computes) { + Assert.assertEquals(compute.getComputeEntity().getComputeCompositionData().getName(), + COMPUTE1_ID.equals(compute.getComputeEntity().getId()) + ? "compute1name" + : "compute2name"); + }; + } + + @Test + public void testCreateOnNotManualCompute_negative() { + + testCreate_negative(new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, null), USER, + VendorSoftwareProductErrorCodes.ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + + @Test + public void testCreateManualCompute() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + computeManager.createCompute(expected, USER); + verify(compositionEntityDataManagerMock).createCompute(expected); + verify(compositionEntityDataManagerMock).createCompute(expected); + } + + @Test + public void testCreateManualImageWithDuplicateName() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + ComputeEntity expectedDiffName = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + ComputeData computeData = expectedDiffName.getComputeCompositionData(); + computeData.setName(COMPUTE1_ID + "Name"); + expectedDiffName.setComputeCompositionData(computeData); + List<ComputeEntity> vfcImageList = new ArrayList<ComputeEntity>(); + vfcImageList.add(expectedDiffName); + doReturn(vfcImageList).when(computeDao).list(anyObject()); + + try { + computeManager.createCompute(expected, USER); + Assert.fail(); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_COMPUTE_NAME_NOT_ALLOWED, + ex.code().id()); + } + } + + + @Test + public void testUpdateNonExistingComputeId_negative() { + + testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testUpdateCompute() { + doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) + .when(computeDao).get(anyObject()); + + doReturn(new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID)) + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); + + ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + ComputeData computeData = new ComputeData(); + computeData.setName(COMPUTE1_ID + "name"); + computeData.setDescription(COMPUTE1_ID + "desc updated"); + computeEntity.setComputeCompositionData(computeData); + + CompositionEntityValidationData validationData = + computeManager.updateCompute(computeEntity, USER); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + verify(computeDao).update(computeEntity); + } + + @Test + public void testIllegalComputeUpdate() { + doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) + .when(computeDao).get(anyObject()); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + CompositionEntityValidationData toBeReturned = + new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID); + toBeReturned.setErrors(Arrays.asList("error1", "error2")); + doReturn(toBeReturned) + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); + + ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + ComputeData computeData = new ComputeData(); + computeData.setName(COMPUTE1_ID + " name updated"); + computeData.setDescription(COMPUTE1_ID + " desc updated"); + computeEntity.setComputeCompositionData(computeData); + + CompositionEntityValidationData validationData = computeManager.updateCompute(computeEntity, USER); + Assert.assertNotNull(validationData); + Assert.assertEquals(validationData.getErrors().size(), 2); + + verify(computeDao, never()).update(computeEntity); + } + + @Test + public void testUpdateHEATComputeName() throws Exception { + doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) + .when(computeDao).get(anyObject()); + ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + ComputeData computeData = new ComputeData(); + computeData.setName(COMPUTE1_ID + " name updated"); + computeData.setDescription(COMPUTE1_ID + " desc updated"); + computeEntity.setComputeCompositionData(computeData); + + try { + computeManager.updateCompute(computeEntity, USER); + } + catch (CoreException ex) { + Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_COMPUTE_NOT_ALLOWED); + } + + } + + @Test + public void testUpdateManualComputeQuestionnaire() throws Exception { + String json = "{\"md5\" :\"FFDSD33SS\"}"; + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(new ComputeEntity(null,null,null,null)).when(computeDao).get(anyObject()); + + computeManager.updateComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, json, USER); + verify(computeDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, json); + } + + @Test + public void testGetNonExistingComputeId_negative() { + testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing compute id", USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGet() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(expected).when(computeDao).get(anyObject()); + String compositionSchema = "schema string"; + doReturn(compositionSchema).when(computeManager).getComputeCompositionSchema(anyObject()); + + CompositionEntityResponse<ComputeData> response = + computeManager.getCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData().getName(), expected.getComputeCompositionData().getName()); + Assert.assertEquals(response.getData().getDescription(), expected.getComputeCompositionData(). + getDescription()); + Assert.assertEquals(response.getSchema(), compositionSchema); + } + + @Test + public void testGetQuestionnaire() throws Exception { + ComputeEntity compute = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + compute.setQuestionnaireData("{}"); + doReturn(compute).when(computeDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + + String schema = "schema string"; + + + doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + + QuestionnaireResponse questionnaire = + computeManager.getComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER); + + Assert.assertNotNull(questionnaire); + Assert.assertEquals(questionnaire.getData(), compute.getQuestionnaireData()); + Assert.assertEquals(questionnaire.getSchema(), schema); + Assert.assertNull(questionnaire.getErrorMessage()); + } + + @Test + public void testDeleteOnNotManualCompute() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(expected).when(computeDao).get(anyObject()); + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + @Test + public void testDeleteOnManualCompute() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(expected).when(computeDao).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + computeManager.deleteCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER); + verify(computeDao).delete(anyObject()); + } + + @Test + public void testDeleteOnNotExistCompute() { + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } + + + private void testDelete_negative(String vspId, Version version, String componentId, String computeId, + String user, + String expectedErrorCode) { + try { + computeManager.deleteCompute(vspId, version, componentId, computeId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String componentId, String computeId, + String user, String expectedErrorCode) { + try { + computeManager.getCompute(vspId, version, componentId, computeId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testList_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + computeManager.listCompute(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + + + private void testUpdate_negative(String vspId, Version version, String componentId, String computeId, + String user, String expectedErrorCode) { + try { + computeManager.updateCompute(new ComputeEntity(vspId, version, componentId, computeId), user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testCreate_negative(ComputeEntity computeEntity1, String user, String expectedErrorCode) { + try { + computeManager.createCompute(computeEntity1, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + static ComputeEntity createCompute(String vspId, Version version, String compId, String computeId){ + ComputeEntity computeEntity1 = new ComputeEntity(vspId, version, compId, computeId); + ComputeData computeData = new ComputeData(); + computeData.setName(computeId+"name"); + computeData.setDescription(computeId+"desc"); + computeEntity1.setComputeCompositionData(computeData); + return computeEntity1; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeplomentFlavorManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeplomentFlavorManagerImplTest.java new file mode 100644 index 0000000000..e082b25435 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeplomentFlavorManagerImplTest.java @@ -0,0 +1,409 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl; + + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +public class DeplomentFlavorManagerImplTest { + private static final String USER = "depFlavorTestUser"; + private static final String VSP_ID = "VSP_ID"; + private static final Version VERSION = new Version(0, 1); + private static final String COMPONENT_ID = "COMPONENT_ID"; + private static final String DF1_ID = "df1"; + private static final String DF2_ID = "df2"; + + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDao; + @Mock + DeploymentFlavorDao deploymentFlavorDaoMock; + @Mock + ComponentDao componentDaoMock; + @Mock + ComputeDao computeDaoMock; + @InjectMocks + @Spy + private DeploymentFlavorManagerImpl deploymentFlavorManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testListWhenNone() { + final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = + deploymentFlavorManager.listDeploymentFlavors(VSP_ID, VERSION, USER); + Assert.assertEquals(deploymentFlavorEntities.size(), 0); + } + + @Test + public void testCreateOnNotManual_negative() { + + testCreate_negative(new DeploymentFlavorEntity(VSP_ID, VERSION, null), USER, + VendorSoftwareProductErrorCodes.CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + + @Test + public void testCreateManualDepFlavor() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected); + } + + @Test + public void testCreateManualDepFlavorWithDuplicateName() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + DeploymentFlavorEntity expectedDiffName = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + DeploymentFlavor deploymentFlavor = expectedDiffName.getDeploymentFlavorCompositionData(); + deploymentFlavor.setModel(DF1_ID + " Name"); + expectedDiffName.setDeploymentFlavorCompositionData(deploymentFlavor); + List<DeploymentFlavorEntity> list = new ArrayList<DeploymentFlavorEntity>(); + list.add(expectedDiffName); + doReturn(list).when(deploymentFlavorDaoMock).list(anyObject()); + + try { + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + Assert.fail(); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED, + ex.code().id()); + } + } + + @Test + public void testCreateManualDepFlavorWithFGNotInVSP() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + final DeploymentFlavor deploymentFlavor = + JsonUtil.json2Object(expected.getCompositionData(), DeploymentFlavor.class); + deploymentFlavor.setFeatureGroupId("fg3"); + expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + List<String> featureGrps = new ArrayList<String>(); + featureGrps.add("fg1"); + featureGrps.add("fg2"); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + vspDetails.setFeatureGroups(featureGrps); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + + try { + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + Assert.fail(); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP, + ex.code().id()); + } + } + + @Test + public void testCreateManualDepFlavorWithNullCompInAssociation() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + final DeploymentFlavor deploymentFlavor = + JsonUtil.json2Object(expected.getCompositionData(), DeploymentFlavor.class); + ComponentComputeAssociation association = new ComponentComputeAssociation(); + association.setComponentId(null); + association.setComputeFlavorId("CF1"); + List<ComponentComputeAssociation> list = new ArrayList<ComponentComputeAssociation>(); + list.add(association); + deploymentFlavor.setComponentComputeAssociations(list); + expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + try { + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION, + ex.code().id()); + Assert.assertEquals("Invalid request,for valid association please provide ComponentId for Compute Flavor", + ex.getMessage()); + } + } + + @Test + public void testCreateManualDepFlavorWithInvalidComputeInAssociation() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + final DeploymentFlavor deploymentFlavor = + JsonUtil.json2Object(expected.getCompositionData(), DeploymentFlavor.class); + ComponentComputeAssociation association = new ComponentComputeAssociation(); + association.setComponentId(COMPONENT_ID); + association.setComputeFlavorId("CF1"); + List<ComponentComputeAssociation> list = new ArrayList<ComponentComputeAssociation>(); + list.add(association); + deploymentFlavor.setComponentComputeAssociations(list); + expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, USER); + doReturn(component).when(componentDaoMock).get(anyObject()); + + doReturn(null).when(computeDaoMock).get(anyObject()); + + try { + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID, + ex.code().id()); + } + } + + @Test + public void testCreateManualDepFlavorWithDuplicateVfcAssociation() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + final DeploymentFlavor deploymentFlavor = + JsonUtil.json2Object(expected.getCompositionData(), DeploymentFlavor.class); + ComponentComputeAssociation association = new ComponentComputeAssociation(); + association.setComponentId(COMPONENT_ID); + association.setComputeFlavorId("CF1"); + List<ComponentComputeAssociation> list = new ArrayList<ComponentComputeAssociation>(); + list.add(association); + list.add(association); + deploymentFlavor.setComponentComputeAssociations(list); + expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, USER); + doReturn(component).when(componentDaoMock).get(anyObject()); + + ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, "CF1"); + doReturn(computeEntity).when(computeDaoMock).get(anyObject()); + + try { + deploymentFlavorManager.createDeploymentFlavor(expected, USER); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED, + ex.code().id()); + } + } + + @Test + public void testList() { + + doReturn(Arrays.asList( + createDeploymentFlavor(VSP_ID, VERSION, DF1_ID), + createDeploymentFlavor(VSP_ID, VERSION, DF2_ID))) + .when(deploymentFlavorDaoMock).list(anyObject()); + + + final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = + deploymentFlavorManager.listDeploymentFlavors(VSP_ID, VERSION, USER); + Assert.assertEquals(deploymentFlavorEntities.size(), 2); + for (DeploymentFlavorEntity deploymentFlavorEntity : deploymentFlavorEntities) { + Assert.assertEquals(deploymentFlavorEntity.getDeploymentFlavorCompositionData().getModel() + , DF1_ID.equals(deploymentFlavorEntity.getId()) ? DF1_ID+" name" : DF2_ID+" name" ); + } + } + + @Test + public void testUpdateHeatDepFlavor() { + testUpdate_negative(VSP_ID, VERSION, DF1_ID, USER, + VendorSoftwareProductErrorCodes.EDIT_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + + @Test + public void testUpdateNonExistingManualDepFlavorId_negative() { + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + testUpdate_negative(VSP_ID, VERSION, DF1_ID, USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testManualUpdateDepFlavor() { + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + doReturn(createDeploymentFlavor(VSP_ID, VERSION, DF1_ID)) + .when(deploymentFlavorDaoMock).get(anyObject()); + + doReturn(new CompositionEntityValidationData(CompositionEntityType.image, DF1_ID)) + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(VSP_ID, VERSION, DF1_ID); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel(DF1_ID + " name"); + deploymentFlavor.setDescription(DF1_ID + " desc updated"); + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + + CompositionEntityValidationData validationData = + deploymentFlavorManager.updateDeploymentFlavor(deploymentFlavorEntity, USER); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + verify(deploymentFlavorDaoMock).update(deploymentFlavorEntity); + } + + @Test + public void testGetNonExistingDepFlavorId_negative() { + testGet_negative(VSP_ID, VERSION, "non existing image id", USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGet() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject()); + + VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); + doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + + CompositionEntityResponse<DeploymentFlavor> response = + deploymentFlavorManager.getDeploymentFlavor(VSP_ID, VERSION, DF1_ID, USER); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData().getModel(), expected.getDeploymentFlavorCompositionData(). + getModel()); + Assert.assertEquals(response.getData().getDescription(), expected.getDeploymentFlavorCompositionData(). + getDescription()); + } + + @Test + public void testDeleteDepFlavorOnHEAT() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject()); + testDelete_negative(VSP_ID, VERSION, DF1_ID, USER, + VendorSoftwareProductErrorCodes.DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + + @Test + public void testDeleteOnNotExistImage() { + testDelete_negative(VSP_ID, VERSION, DF1_ID, USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteOnManualImage() { + DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + deploymentFlavorManager.deleteDeploymentFlavor(VSP_ID, VERSION, DF1_ID, USER); + verify(deploymentFlavorDaoMock).delete(anyObject()); + } + + private void testList_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + deploymentFlavorManager.listDeploymentFlavors(vspId, version, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testCreate_negative(DeploymentFlavorEntity deploymentFlavorEntity, String user, String + expectedErrorCode) { + try { + deploymentFlavorManager.createDeploymentFlavor(deploymentFlavorEntity, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, Version version, String deploymentFlavorId, + String user, + String expectedErrorCode) { + try { + deploymentFlavorManager.deleteDeploymentFlavor(vspId, version, deploymentFlavorId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + static DeploymentFlavorEntity createDeploymentFlavor(String vspId, Version version, String deploymentFlavorId) { + + DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); + DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); + deploymentFlavor.setModel(deploymentFlavorId + " name"); + deploymentFlavor.setDescription(deploymentFlavorId + " desc"); + + deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); + return deploymentFlavorEntity; + } + + private void testUpdate_negative(String vspId, Version version, String + deploymentFlavorId, String user, String expectedErrorCode) { + try { + deploymentFlavorManager + .updateDeploymentFlavor(new DeploymentFlavorEntity(vspId, version, deploymentFlavorId), user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String deploymentFlavorId, + String user, String expectedErrorCode) { + try { + deploymentFlavorManager.getDeploymentFlavor(vspId, version, deploymentFlavorId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java new file mode 100644 index 0000000000..ec676e517b --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java @@ -0,0 +1,374 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl; + + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +public class ImageManagerImplTest { + + private static final String IMAGE_NOT_EXIST_MSG = + "Vendor Software Product Image with Id image1 does not exist for Vendor Software Product with" + + " " + + "id VSP_ID and version 0.1"; + + private static final String USER = "imageTestUser"; + private static final String VSP_ID = "VSP_ID"; + private static final Version VERSION = new Version(0, 1); + private static final String COMPONENT_ID = "COMPONENT_ID"; + private static final String IMAGE1_ID = "image1"; + private static final String IMAGE2_ID = "image2"; + + @Mock + private ImageDao imageDao; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDao; + @InjectMocks + @Spy + private ImageManagerImpl imageManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testListWhenNone() { + final Collection<ImageEntity> imageEntities = + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); + Assert.assertEquals(imageEntities.size(), 0); + } + + @Test + public void testList() { + + doReturn(Arrays.asList( + createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID), + createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE2_ID))) + .when(imageDao).list(anyObject()); + + + final Collection<ImageEntity> images = + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); + Assert.assertEquals(images.size(), 2); + for (ImageEntity image : images) { + Assert.assertEquals(image.getImageCompositionData().getFileName(), + IMAGE1_ID.equals(image.getId()) ? IMAGE1_ID+" name" : IMAGE2_ID+" name" ); + } + } + + @Test + public void testCreateOnNotManualImage_negative() { + + testCreate_negative(new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, null), USER, + VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + + @Test + public void testCreateManualImage() { + ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + imageManager.createImage(expected, USER); + verify(compositionEntityDataManagerMock).createImage(expected); + verify(compositionEntityDataManagerMock).createImage(expected); + } + + @Test + public void testCreateManualImageWithDuplicateName() { + ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + ImageEntity expectedDiffName = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + Image image = expectedDiffName.getImageCompositionData(); + image.setFileName(IMAGE1_ID + " Name"); + expectedDiffName.setImageCompositionData(image); + List<ImageEntity> vfcImageList = new ArrayList<ImageEntity>(); + vfcImageList.add(expectedDiffName); + doReturn(vfcImageList).when(imageDao).list(anyObject()); + try { + imageManager.createImage(expected, USER); + Assert.fail(); + } + catch (CoreException ex) { + Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_NAME_NOT_ALLOWED, + ex.code().id()); + } + } + + @Test + public void testUpdateNonExistingImageId_negative() { + testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testUpdateImage() { + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) + .when(imageDao).get(anyObject()); + + doReturn(new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID)) + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); + + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + Image imageData = new Image(); + imageData.setFileName(IMAGE1_ID + " name"); + imageData.setDescription(IMAGE1_ID + " desc updated"); + imageEntity.setImageCompositionData(imageData); + + CompositionEntityValidationData validationData = + imageManager.updateImage(imageEntity, USER); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + verify(imageDao).update(imageEntity); + } + + @Test + public void testIllegalImageUpdate() { + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) + .when(imageDao).get(anyObject()); + + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + + CompositionEntityValidationData toBeReturned = + new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); + toBeReturned.setErrors(Arrays.asList("error1", "error2")); + doReturn(toBeReturned) + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); + + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + Image imageData = new Image(); + imageData.setFileName(IMAGE1_ID + " name updated"); + imageData.setDescription(IMAGE1_ID + " desc updated"); + imageEntity.setImageCompositionData(imageData); + + CompositionEntityValidationData validationData = imageManager.updateImage(imageEntity, USER); + Assert.assertNotNull(validationData); + Assert.assertEquals(validationData.getErrors().size(), 2); + + verify(imageDao, never()).update(imageEntity); + } + + @Test + public void testUpdateHEATImageFileName() throws Exception { + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) + .when(imageDao).get(anyObject()); + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + Image imageData = new Image(); + imageData.setFileName(IMAGE1_ID + " name updated"); + imageData.setDescription(IMAGE1_ID + " desc updated"); + imageEntity.setImageCompositionData(imageData); + + try { + imageManager.updateImage(imageEntity, USER); + } + catch (CoreException ex) { + Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED); + } + + } + + @Test + public void testGetNonExistingImageId_negative() { + testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing image id", USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testGet() { + ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + doReturn(expected).when(imageDao).get(anyObject()); + String compositionSchema = "schema string"; + doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(anyObject()); + + CompositionEntityResponse<Image> response = + imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + Assert.assertEquals(response.getId(), expected.getId()); + Assert.assertEquals(response.getData().getFileName(), expected.getImageCompositionData(). + getFileName()); + Assert.assertEquals(response.getData().getDescription(), expected.getImageCompositionData(). + getDescription()); + Assert.assertEquals(response.getSchema(), compositionSchema); + } + + @Test + public void testDeleteOnNotManualImage() { + ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + doReturn(expected).when(imageDao).get(anyObject()); + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, + VendorSoftwareProductErrorCodes.DELETE_IMAGE_NOT_ALLOWED); + } + + @Test + public void testDeleteOnNotExistImage() { + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } + + @Test + public void testDeleteOnManualImage() { + ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + doReturn(expected).when(imageDao).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + imageManager.deleteImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + verify(imageDao).delete(anyObject()); + } + + @Test + public void testGetQuestionnaire() throws Exception { + ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + image.setQuestionnaireData("{}"); + doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + + String schema = "schema string"; + doReturn(schema).when(imageManager).getImageQuestionnaireSchema(anyObject()); + + QuestionnaireResponse questionnaire = + imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + Assert.assertNotNull(questionnaire); + Assert.assertEquals(questionnaire.getData(), image.getQuestionnaireData()); + Assert.assertEquals(questionnaire.getSchema(), schema); + Assert.assertNull(questionnaire.getErrorMessage()); + } + + @Test + public void testUpdateManualImageQuestionnaire() throws Exception { + String json = "{\"md5\" :\"FFDSD33SS\"}"; + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(new ImageEntity()).when(imageDao).get(anyObject()); + + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json, USER); + verify(imageDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); + } + + @Test + public void testUpdateHEATImageQuestionnaireWithFormat() throws Exception { + String json = "{\"format\" :\"qcow2\"}"; + ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + image.setQuestionnaireData(json); + doReturn(image).when(imageDao).get(anyObject()); + + doReturn(false).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + + String updJson = "{\"format\" :\"aki\"}"; + try { + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson, + USER); + Assert.fail(); + } + catch(CoreException ex) { + Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED); + } + } + + @Test + public void testUpdateHEATImageQuestionnaireWithInvalidFormat() throws Exception { + String json = "{\"format\" :\"qcow2\"}"; + ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); + image.setQuestionnaireData(json); + doReturn(image).when(imageDao).get(anyObject()); + + String updJson = "{\"format\" :\"a22\"}"; + try { + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson, + USER); + Assert.fail(); + } + catch(CoreException ex) { + Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.VFC_IMAGE_INVALID_FORMAT); + } + } + + private void testList_negative(String vspId, Version version, String componentId, String user, + String expectedErrorCode, String expectedErrorMsg) { + try { + imageManager.listImages(vspId, version, componentId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } + } + + private void testCreate_negative(ImageEntity image, String user, String expectedErrorCode) { + try { + imageManager.createImage(image, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testDelete_negative(String vspId, Version version, String componentId, String nicId, + String user, + String expectedErrorCode) { + try { + imageManager.deleteImage(vspId, version, componentId, nicId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + static ImageEntity createImage(String vspId, Version version, String compId, String imageId) { + ImageEntity imageEntity = new ImageEntity(vspId, version, compId, imageId); + Image imageData = new Image(); + imageData.setFileName(imageId + " name"); + imageData.setDescription(imageId + " desc"); + imageEntity.setImageCompositionData(imageData); + return imageEntity; + } + + private void testUpdate_negative(String vspId, Version version, String componentId, String + imageId, String user, String expectedErrorCode) { + try { + imageManager.updateImage(new ImageEntity(vspId, version, componentId, imageId), user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + + private void testGet_negative(String vspId, Version version, String componentId, String imageId, + String user, String expectedErrorCode) { + try { + imageManager.getImage(vspId, version, componentId, imageId, user); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + } + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ManualVspToscaManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ManualVspToscaManagerImplTest.java new file mode 100644 index 0000000000..4bbbec166e --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ManualVspToscaManagerImplTest.java @@ -0,0 +1,562 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl; + +import static org.openecomp.sdc.generator.util.GeneratorConstants.ALLOWED_FLAVORS_PROPERTY; +import static org.openecomp.sdc.generator.util.GeneratorConstants.PORT_NODE_TEMPLATE_ID_SUFFIX; +import static org.openecomp.sdc.tosca.services.ToscaConstants.BINDING_REQUIREMENT_ID; +import static org.openecomp.sdc.tosca.services.ToscaConstants.COUNT_PROPERTY_NAME; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.generator.core.utils.GeneratorUtils; +import org.openecomp.sdc.generator.datatypes.tosca.ComputeFlavor; +import org.openecomp.sdc.generator.datatypes.tosca.DeploymentFlavorModel; +import org.openecomp.sdc.generator.datatypes.tosca.LicenseFlavor; +import org.openecomp.sdc.generator.datatypes.tosca.MultiFlavorVfcImage; +import org.openecomp.sdc.generator.datatypes.tosca.VendorInfo; +import org.openecomp.sdc.generator.datatypes.tosca.VspModelInfo; +import org.openecomp.sdc.generator.util.GeneratorConstants; +import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; +import org.openecomp.sdc.tosca.datatypes.model.PropertyType; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ManualVspToscaManagerImplTest { + + private static final String COMPONENT_ID = "Component_id"; + private static final String COMPONENT_NAME = "Component_name"; + private static final String SP_PART_NUMBER_1 = "Part_number_123"; + private static final String FEATURE_GROUP_ID_1 = "Feature_Group_id_1"; + private static final String MANUFACTURER_REF_1 = "Manufacturer_Ref_1"; + private static final String VENDOR_MODEL_1 = "VLM_1"; + private static final int NUM_CPUS_1 = 1; + private static final String DISK_SIZE_1 = "2GB"; + private static final String MEM_SIZE_1 = "8GB"; + + private static final String SP_PART_NUMBER_2 = "Part_number_345"; + private static final String FEATURE_GROUP_ID_2 = "Feature_Group_id_2"; + private static final String MANUFACTURER_REF_2 = "Manufacturer_Ref_2"; + private static final String VENDOR_MODEL_2 = "VLM_2"; + private static final int NUM_CPUS_2 = 4; + private static final String DISK_SIZE_2 = "3GB"; + private static final String MEM_SIZE_2 = "2GB"; + + private static final String IMAGE_VERSION_1 = "3.16.1"; + private static final String IMAGE_HASH_1 = "65edfgye3256hjutve"; + private static final String IMAGE_FILE_NAME_1 = "image-file-name1"; + private static final String IMAGE_FILE_FORMAT_1 = "qcow2"; + private static final String IMAGE_VERSION_2 = "3.1.9"; + private static final String IMAGE_HASH_2 = "84rtedfe3256hjutaw"; + private static final String IMAGE_FILE_NAME_2 = "image-file-name1"; + private static final String IMAGE_FILE_FORMAT_2 = "iso"; + + private ManualVspToscaManager manualVspToscaManager = new ManualVspToscaManagerImpl(); + + @Test + public void testGenerateToscaInvalidVspId() { + VspModelInfo emptyVspCollectedData = new VspModelInfo(); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(emptyVspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(19, toscaServiceModel.getServiceTemplates().size()); + } + + @Test + public void testGenerateToscaNoComponent() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setReleaseVendor("Vendor-1"); + vspCollectedData.setComponents(null); + vspCollectedData.setMultiFlavorVfcImages(null); + vspCollectedData.setAllowedFlavors(getDeploymentFlavorData()); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(19, toscaServiceModel.getServiceTemplates().size()); + } + + @Test + public void testGenerateToscaReleaseVendorNotPresent() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(getVfcImageData()); + vspCollectedData.setAllowedFlavors(getDeploymentFlavorData()); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String entryDefinitionServiceTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate mainServiceTemplate = serviceTemplates.get(entryDefinitionServiceTemplate); + Assert.assertNotNull(mainServiceTemplate); + Assert.assertNull(mainServiceTemplate.getMetadata().get("releaseVendor")); + } + + @Test + public void testGenerateToscaNoImages() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(null); + vspCollectedData.setAllowedFlavors(getDeploymentFlavorData()); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String entryDefinitionServiceTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate mainServiceTemplate = serviceTemplates.get(entryDefinitionServiceTemplate); + Assert.assertNotNull(mainServiceTemplate); + String componentName = vspCollectedData.getComponents().get(COMPONENT_ID); + Assert.assertNull(mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VFC_NODE_TEMPLATE_ID_SUFFIX) + .getProperties()); + } + + @Test + public void testGenerateToscaNoPorts() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(getVfcImageData()); + vspCollectedData.setAllowedFlavors(getDeploymentFlavorData()); + vspCollectedData.setNics(null); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String componentName = vspCollectedData.getComponents().get(COMPONENT_ID); + String substitutionServiceTemplateFileName = + componentName + GeneratorConstants.TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX; + ServiceTemplate substitutionServiceTemplate = + serviceTemplates.get(substitutionServiceTemplateFileName); + Assert.assertNotNull(substitutionServiceTemplate); + //Only component node template should be present since there are no ports + Assert.assertEquals(1, substitutionServiceTemplate.getTopology_template().getNode_templates() + .size()); + } + + @Test + public void testGenerateToscaNoManufacturerRefNumAndFeatureGroup() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setReleaseVendor("Vendor-1"); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(getVfcImageData()); + Map<String, DeploymentFlavorModel> deploymentFlavorData = getDeploymentFlavorData(); + deploymentFlavorData.get(SP_PART_NUMBER_1).getVendor_info() + .setManufacturer_reference_number(null); + deploymentFlavorData.get(SP_PART_NUMBER_1).getLicense_flavor().setFeature_group_uuid(null); + vspCollectedData.setAllowedFlavors(deploymentFlavorData); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String entryDefinitionServiceTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate mainServiceTemplate = serviceTemplates.get(entryDefinitionServiceTemplate); + Assert.assertNotNull(mainServiceTemplate); + String componentName = vspCollectedData.getComponents().get(COMPONENT_ID); + Map<String, DeploymentFlavorModel> actualDeploymentFlavor = (Map<String, DeploymentFlavorModel>) + mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX) + .getProperties().get(ALLOWED_FLAVORS_PROPERTY); + Assert.assertNull(actualDeploymentFlavor.get(SP_PART_NUMBER_1).getVendor_info() + .getManufacturer_reference_number()); + Assert.assertNull(actualDeploymentFlavor.get(SP_PART_NUMBER_1).getLicense_flavor() + .getFeature_group_uuid()); + } + + @Test + public void testGenerateToscaNoDeploymentFlavor() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setReleaseVendor("Vendor-1"); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(getVfcImageData()); + vspCollectedData.setAllowedFlavors(null); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String entryDefinitionServiceTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate mainServiceTemplate = serviceTemplates.get(entryDefinitionServiceTemplate); + Assert.assertNotNull(mainServiceTemplate); + String componentName = vspCollectedData.getComponents().get(COMPONENT_ID); + Assert.assertNull(mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX) + .getProperties()); + } + + @Test + public void testGenerateToscaCompleteData() { + VspModelInfo vspCollectedData = new VspModelInfo(); + vspCollectedData.setReleaseVendor("Vendor-1"); + vspCollectedData.setComponents(getComponentData()); + vspCollectedData.setMultiFlavorVfcImages(getVfcImageData()); + vspCollectedData.setAllowedFlavors(getDeploymentFlavorData()); + vspCollectedData.setNics(getComponentNics()); + ToscaServiceModel toscaServiceModel = + manualVspToscaManager.generateToscaModel(vspCollectedData); + Assert.assertNotNull(toscaServiceModel); + Assert.assertNotNull(toscaServiceModel.getServiceTemplates()); + //Service model should contain only the packed global types + Assert.assertEquals(22, toscaServiceModel.getServiceTemplates().size()); + Map<String, ServiceTemplate> serviceTemplates = toscaServiceModel.getServiceTemplates(); + String entryDefinitionServiceTemplate = toscaServiceModel.getEntryDefinitionServiceTemplate(); + ServiceTemplate mainServiceTemplate = serviceTemplates.get(entryDefinitionServiceTemplate); + Assert.assertNotNull(mainServiceTemplate); + String componentName = vspCollectedData.getComponents().get(COMPONENT_ID); + + Assert.assertNotNull(mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VFC_NODE_TEMPLATE_ID_SUFFIX)); + Assert.assertNotNull(mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VNF_NODE_TEMPLATE_ID_SUFFIX)); + //Validate vnf configuration node template + validateVnfConfigurationNodeTemplate(mainServiceTemplate, componentName); + //Validate vfc node template + validateVfcNodeTemplateinMainServiceTemplate(mainServiceTemplate, componentName); + //Validate vnf node template + validateVnfNodeTemplate(mainServiceTemplate, componentName); + + //Validate substitution service template + ServiceTemplate substitutionServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(componentName + GeneratorConstants.TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX); + List<Nic> nics = vspCollectedData.getNics().get(COMPONENT_ID); + validateSubstitutionServiceTemplate(substitutionServiceTemplate, nics, componentName); + + //Validate global substitution service template + ServiceTemplate globalSubstitutionServiceTemplate = toscaServiceModel.getServiceTemplates() + .get(ToscaUtil.getServiceTemplateFileName(GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME)); + validateGlobalSubstitutionServiceTemplate(globalSubstitutionServiceTemplate, nics, + componentName); + } + + private void validateVnfConfigurationNodeTemplate(ServiceTemplate mainServiceTemplate, + String componentName) { + NodeTemplate vnfConfigNodeTemplate = + mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX); + Assert.assertNotNull(vnfConfigNodeTemplate); + Assert.assertEquals(ToscaNodeType.VNF_CONFIG_NODE_TYPE, vnfConfigNodeTemplate.getType()); + Map<String, DeploymentFlavorModel> allowedFlavors = (Map<String, DeploymentFlavorModel>) + vnfConfigNodeTemplate.getProperties().get(GeneratorConstants.ALLOWED_FLAVORS_PROPERTY); + Map<String, DeploymentFlavorModel> deploymentFlavorData = getDeploymentFlavorData(); + Assert.assertNotNull(allowedFlavors); + Assert.assertEquals(deploymentFlavorData.size(), allowedFlavors.size()); + Assert.assertEquals(deploymentFlavorData, allowedFlavors); + } + + private void validateVfcNodeTemplateinMainServiceTemplate(ServiceTemplate mainServiceTemplate, + String componentName) { + NodeTemplate vfcNodeTemplate = + mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VFC_NODE_TEMPLATE_ID_SUFFIX); + Assert.assertNotNull(vfcNodeTemplate); + Assert.assertEquals(ToscaNodeType.MULTIFLAVOR_VFC_NODE_TYPE, vfcNodeTemplate.getType()); + Map<String, MultiFlavorVfcImage> vfcImages = (Map<String, MultiFlavorVfcImage>) + vfcNodeTemplate.getProperties().get(GeneratorConstants.IMAGES_PROPERTY); + Assert.assertNotNull(vfcImages); + Assert.assertEquals(2, vfcImages.size()); + MultiFlavorVfcImage image1 = vfcImages.get(IMAGE_VERSION_1); + MultiFlavorVfcImage expectedImage1 = getImageData(IMAGE_VERSION_1, IMAGE_HASH_1, + IMAGE_FILE_NAME_1, "md5", IMAGE_FILE_FORMAT_1); + Assert.assertEquals(expectedImage1, image1); + MultiFlavorVfcImage image2 = vfcImages.get(IMAGE_VERSION_2); + MultiFlavorVfcImage expectedImage2 = getImageData(IMAGE_VERSION_2, IMAGE_HASH_2, + IMAGE_FILE_NAME_2, "md5", IMAGE_FILE_FORMAT_2); + Assert.assertEquals(expectedImage2, image2); + } + + private void validateVnfNodeTemplate(ServiceTemplate mainServiceTemplate, + String componentName) { + NodeTemplate vnfNodeTemplate = + mainServiceTemplate.getTopology_template().getNode_templates() + .get(componentName + GeneratorConstants.VNF_NODE_TEMPLATE_ID_SUFFIX); + Assert.assertNotNull(vnfNodeTemplate); + Assert.assertEquals(ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE + "." + componentName, + vnfNodeTemplate.getType()); + Assert.assertNotNull(vnfNodeTemplate.getDirectives()); + Assert.assertEquals(true, vnfNodeTemplate.getDirectives().contains(ToscaConstants + .NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE)); + + Map<String, Object> serviceTemplateFilterProperty = (Map<String, Object>) vnfNodeTemplate + .getProperties().get(SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + Assert.assertNotNull(serviceTemplateFilterProperty); + String substituteServiceTemplate = serviceTemplateFilterProperty + .get(SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME).toString(); + String expectedServiceTemplateName = componentName + GeneratorConstants + .TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX; + Assert.assertEquals(expectedServiceTemplateName, substituteServiceTemplate); + int count = (int) serviceTemplateFilterProperty.get(COUNT_PROPERTY_NAME); + Assert.assertEquals(1, count); + } + + private void validateSubstitutionServiceTemplate(ServiceTemplate substitutionServiceTemplate, + List<Nic> nics, + String componentName) { + Assert.assertNotNull(substitutionServiceTemplate); + int expectedNumberOfNodeTemplates = nics.size() + 1; //1 component node template + Map<String, NodeTemplate> substitutionNodeTemplates = + substitutionServiceTemplate.getTopology_template().getNode_templates(); + Assert.assertEquals(expectedNumberOfNodeTemplates, substitutionNodeTemplates.size()); + NodeTemplate componentNodeTemplate = substitutionNodeTemplates.get(componentName); + Assert.assertNotNull(componentNodeTemplate); + Assert.assertEquals(ToscaNodeType.VFC_NODE_TYPE_PREFIX + componentName, componentNodeTemplate + .getType()); + for (Nic nic : nics) { + String nicName = nic.getName(); + NodeTemplate nicNodeTemplate = + substitutionNodeTemplates.get(nicName + PORT_NODE_TEMPLATE_ID_SUFFIX); + validateNicNodeTemplate(nicNodeTemplate, componentName); + } + SubstitutionMapping substitutionMappings = + substitutionServiceTemplate.getTopology_template().getSubstitution_mappings(); + validateSubstitutionMappings(substitutionMappings, nics, componentName); + } + + private void validateNicNodeTemplate(NodeTemplate nicNodeTemplate, + String componentName) { + Assert.assertNotNull(nicNodeTemplate); + Assert.assertEquals(ToscaNodeType.NETWORK_PORT, nicNodeTemplate.getType()); + List<Map<String, RequirementAssignment>> nicNodeTemplateRequirements = + nicNodeTemplate.getRequirements(); + Assert.assertNotNull(nicNodeTemplateRequirements); + Assert.assertEquals(1, nicNodeTemplateRequirements.size()); + RequirementAssignment expectedRequirementAssignment = new RequirementAssignment(); + expectedRequirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE); + expectedRequirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO); + expectedRequirementAssignment.setNode(componentName); + Assert.assertEquals(true, new ToscaAnalyzerServiceImpl() + .isRequirementExistInNodeTemplate(nicNodeTemplate, BINDING_REQUIREMENT_ID, + expectedRequirementAssignment)); + } + + private void validateSubstitutionMappings(SubstitutionMapping substitutionMappings, + List<Nic> nics, + String componentName) { + Assert.assertEquals(ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE + "." + componentName, + substitutionMappings.getNode_type()); + Map<String, List<String>> capabilities = substitutionMappings.getCapabilities(); + validateSubstitutionCapabilities(capabilities, componentName); + Map<String, List<String>> requirements = substitutionMappings.getRequirements(); + validateSubstitutionRequirements(requirements, nics); + } + + private void validateSubstitutionCapabilities(Map<String, List<String>> capabilities, + String componentName) { + List<String> supportedCapabilities = GeneratorUtils.supportedCapabilities; + Assert.assertEquals(supportedCapabilities.size(), capabilities.size()); + for (String capability : supportedCapabilities) { + String expectedCapabilityId = capability + "_" + componentName; + Assert.assertEquals(true, capabilities.containsKey(expectedCapabilityId)); + List<String> expectedCapabilityValue = new ArrayList<>(2); + expectedCapabilityValue.add(componentName); + expectedCapabilityValue.add(capability); + List<String> actualCapabilityValue = capabilities.get(expectedCapabilityId); + Assert.assertEquals(expectedCapabilityValue, actualCapabilityValue); + } + } + + private void validateSubstitutionRequirements(Map<String, List<String>> requirements, + List<Nic> nics) { + List<String> supportedRequirements = GeneratorUtils.supportedRequirements; + for(Nic nic : nics) { + String nicNodeTemplateId = nic.getName() + PORT_NODE_TEMPLATE_ID_SUFFIX; + for (String requirement : supportedRequirements) { + String expectedRequirementId = requirement + "_" + nicNodeTemplateId; + Assert.assertEquals(true, requirements.containsKey(expectedRequirementId)); + List<String> expectedRequirementValue = new ArrayList<>(2); + expectedRequirementValue.add(nicNodeTemplateId); + expectedRequirementValue.add(requirement); + List<String> actualRequirementValue = requirements.get(expectedRequirementId); + Assert.assertEquals(expectedRequirementValue, actualRequirementValue); + } + } + } + + private void validateGlobalSubstitutionServiceTemplate(ServiceTemplate + globalSubstitutionServiceTemplate, + List<Nic> nics, + String componentName) { + Assert.assertNotNull(globalSubstitutionServiceTemplate); + Map<String, NodeType> nodeTypes = globalSubstitutionServiceTemplate.getNode_types(); + Assert.assertEquals(1, nodeTypes.size()); + NodeType deploymentFlavorNodeType = + nodeTypes.get(ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE + "." + componentName); + Assert.assertNotNull(deploymentFlavorNodeType); + Map<String, PropertyDefinition> properties = deploymentFlavorNodeType.getProperties(); + Assert.assertNotNull(properties); + PropertyDefinition numCpusProperty = properties.get(GeneratorConstants.NUM_CPUS); + Assert.assertNotNull(numCpusProperty); + Assert.assertEquals(PropertyType.INTEGER.getDisplayName(), numCpusProperty.getType()); + Assert.assertEquals(true, numCpusProperty.getRequired()); + + PropertyDefinition diskSizeProperty = properties.get(GeneratorConstants.DISK_SIZE); + Assert.assertNotNull(diskSizeProperty); + Assert.assertEquals(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(), diskSizeProperty.getType()); + Assert.assertEquals(true, diskSizeProperty.getRequired()); + + PropertyDefinition memSizeProperty = properties.get(GeneratorConstants.MEM_SIZE); + Assert.assertNotNull(memSizeProperty); + Assert.assertEquals(PropertyType.SCALAR_UNIT_SIZE.getDisplayName(), memSizeProperty.getType()); + Assert.assertEquals(true, memSizeProperty.getRequired()); + + List<Map<String, RequirementDefinition>> requirements = + deploymentFlavorNodeType.getRequirements(); + List<String> supportedRequirements = GeneratorUtils.supportedRequirements; + for (Nic nic : nics) { + boolean found = false; + String nicNodeTemplateId = nic.getName() + PORT_NODE_TEMPLATE_ID_SUFFIX; + for (String requirementId : supportedRequirements) { + String expectedRequirementId = requirementId + "_" + nicNodeTemplateId; + for (Map<String, RequirementDefinition> requirement : requirements) { + if (requirement.containsKey(expectedRequirementId)) { + found = true; + break; + } + } + } + Assert.assertEquals(true, found); + } + + Map<String, CapabilityDefinition> capabilities = deploymentFlavorNodeType.getCapabilities(); + List<String> supportedCapabilities = GeneratorUtils.supportedCapabilities; + for (String capabilityId : supportedCapabilities) { + String expectedCapabilityId = capabilityId + "_" + componentName; + Assert.assertEquals (true, capabilities.containsKey(expectedCapabilityId)); + } + } + + private Map<String, String> getComponentData() { + Map<String, String> componentData = new HashMap<>(); + componentData.put(COMPONENT_ID, COMPONENT_NAME); + return componentData; + } + + private Map<String, List<MultiFlavorVfcImage>> getVfcImageData() { + Map<String, List<MultiFlavorVfcImage>> imageData = new HashMap<>(); + List<MultiFlavorVfcImage> images = new ArrayList<>(2); + MultiFlavorVfcImage image1 = getImageData(IMAGE_VERSION_1, IMAGE_HASH_1, IMAGE_FILE_NAME_1, + "md5", IMAGE_FILE_FORMAT_1); + MultiFlavorVfcImage image2 = getImageData(IMAGE_VERSION_2, IMAGE_HASH_2, IMAGE_FILE_NAME_2, + "md5", IMAGE_FILE_FORMAT_2); + images.add(image1); + images.add(image2); + imageData.put(COMPONENT_ID, images); + return imageData; + } + + private Map<String, DeploymentFlavorModel> getDeploymentFlavorData() { + Map<String, DeploymentFlavorModel> deploymentFlavorData = new HashMap<>(); + ComputeFlavor computeFlavor1 = getComputeFlavorData(NUM_CPUS_1, DISK_SIZE_1, MEM_SIZE_1); + LicenseFlavor licenseFlavor1 = getLicenseFlavor(FEATURE_GROUP_ID_1); + VendorInfo vendorInfo1 = getVendorInfo(MANUFACTURER_REF_1, VENDOR_MODEL_1); + DeploymentFlavorModel deploymentFlavor1 = getDeploymentFlavorModel(SP_PART_NUMBER_1, + computeFlavor1, vendorInfo1, licenseFlavor1); + + ComputeFlavor computeFlavor2 = getComputeFlavorData(NUM_CPUS_2, DISK_SIZE_2, MEM_SIZE_2); + LicenseFlavor licenseFlavor2 = getLicenseFlavor(FEATURE_GROUP_ID_2); + VendorInfo vendorInfo2 = getVendorInfo(MANUFACTURER_REF_2, VENDOR_MODEL_2); + + DeploymentFlavorModel deploymentFlavor2 = getDeploymentFlavorModel(SP_PART_NUMBER_2, + computeFlavor2, vendorInfo2, licenseFlavor2); + + deploymentFlavorData.put(SP_PART_NUMBER_1, deploymentFlavor1); + deploymentFlavorData.put(SP_PART_NUMBER_2, deploymentFlavor2); + return deploymentFlavorData; + } + + private DeploymentFlavorModel getDeploymentFlavorModel(String spPartNumber, ComputeFlavor + computeFlavor, VendorInfo vendorInfo, LicenseFlavor licenseFlavor) { + DeploymentFlavorModel deploymentFlavor = new DeploymentFlavorModel(); + deploymentFlavor.setSp_part_number(spPartNumber); + deploymentFlavor.setCompute_flavor(computeFlavor); + deploymentFlavor.setLicense_flavor(licenseFlavor); + deploymentFlavor.setVendor_info(vendorInfo); + return deploymentFlavor; + } + + private ComputeFlavor getComputeFlavorData(int numCpus, String diskSize, String memSize ) { + ComputeFlavor computeFlavor = new ComputeFlavor(); + computeFlavor.setNum_cpus(numCpus); + computeFlavor.setDisk_size(diskSize); + computeFlavor.setMem_size(memSize); + return computeFlavor; + } + + private VendorInfo getVendorInfo(String manufacturerRefNumber, String vlmId) { + VendorInfo vendorInfo = new VendorInfo(); + vendorInfo.setManufacturer_reference_number(manufacturerRefNumber); + vendorInfo.setVendor_model(vlmId); + return vendorInfo; + } + + private LicenseFlavor getLicenseFlavor(String featureGroupId) { + LicenseFlavor licenseFlavor = new LicenseFlavor(); + licenseFlavor.setFeature_group_uuid(featureGroupId); + return licenseFlavor; + } + + private MultiFlavorVfcImage getImageData(String imageVersion, String fileHash, String fileName, + String fileHashType, String fileFormat) { + MultiFlavorVfcImage image = new MultiFlavorVfcImage(); + image.setSoftware_version(imageVersion); + image.setFile_hash(fileHash); + image.setFile_hash_type(fileHashType); + image.setFile_name(fileName+"-"+IMAGE_VERSION_2+"."+fileFormat); + return image; + } + + private Map<String, List<Nic>> getComponentNics() { + Map<String, List<Nic>> nicData = new HashMap<>(); + List<Nic> nicList = new ArrayList<>(2); + Nic nic1 = new Nic(); + nic1.setName("Nic_1"); + + Nic nic2 = new Nic(); + nic2.setName("Nic_2"); + + nicList.add(nic1); + nicList.add(nic2); + nicData.put(COMPONENT_ID, nicList); + return nicData; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MibManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MibManagerImplTest.java deleted file mode 100644 index 54e979cdaf..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MibManagerImplTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.openecomp.sdc.vendorsoftwareproduct.impl; - -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.core.enrichment.types.ArtifactType; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.vendorsoftwareproduct.dao.MibDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.MibEntity; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Arrays; -import java.util.Optional; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -public class MibManagerImplTest { - - private static final String USER1 = "ComponentsUploadTestUser"; - private static final String COMPONENT_ID = "COMPONENT_ID"; - private static final String VSP_ID = "vspId"; - private static final Version VERSION = new Version(0, 1); - private static final String trapFileName = "MMSC.zip"; - private static final String pollFileName = "MNS OAM FW.zip"; - private static final String notZipFileName = "notZipFile"; - private static final String zipWithFoldersFileName = "zipFileWithFolder.zip"; - private static final String emptyZipFileName = "emptyZip.zip"; - private static final String ZIP_DIR = "/vspmanager/zips/"; - - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private MibDao mibDaoMock; - @InjectMocks - private MibManagerImpl mibManager; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test(expectedExceptions = CoreException.class) - public void testUploadEmptyZip() { - InputStream zis = getFileInputStream(ZIP_DIR + emptyZipFileName); - mibManager.upload(zis, emptyZipFileName, VSP_ID, VERSION, COMPONENT_ID, - ArtifactType.SNMP_TRAP, USER1); - } - - @Test - public void testUploadInvalidZip() { - URL url = this.getClass().getResource("/notZipFile"); - try { - mibManager - .upload(url.openStream(), notZipFileName, VSP_ID, VERSION, COMPONENT_ID, - ArtifactType.SNMP_TRAP, USER1); - Assert.fail(); - } catch (Exception exception) { - Assert.assertEquals(exception.getMessage(), "Invalid zip file"); - } - } - - @Test - public void testUploadZipWithFolders() { - InputStream zis = getFileInputStream(ZIP_DIR + zipWithFoldersFileName); - - try { - mibManager - .upload(zis, zipWithFoldersFileName, VSP_ID, VERSION, COMPONENT_ID, - ArtifactType.SNMP_TRAP, USER1); - Assert.fail(); - } catch (Exception exception) { - Assert.assertEquals(exception.getMessage(), "Zip file should not contain folders"); - } - } - - - @Test - public void testListMibFilenames() { - MibEntity artifact1 = - new MibEntity(VSP_ID, VERSION, COMPONENT_ID, "artifact1"); - artifact1.setType(ArtifactType.SNMP_TRAP); - artifact1.setArtifactName(trapFileName); - - MibEntity artifact2 = - new MibEntity(VSP_ID, VERSION, COMPONENT_ID, "artifact2"); - artifact2.setType(ArtifactType.SNMP_POLL); - artifact2.setArtifactName(pollFileName); - - doReturn(Arrays.asList(artifact1, artifact2)) - .when(mibDaoMock).list(anyObject()); - - MibUploadStatus mibUploadStatus = - mibManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID, USER1); - - Assert.assertEquals(mibUploadStatus.getSnmpTrap(), trapFileName); - Assert.assertEquals(mibUploadStatus.getSnmpPoll(), pollFileName); - } - - @Test (expectedExceptions = CoreException.class) - public void testDeleteComponentMibWhenNone() { - doReturn(Optional.empty()).when(mibDaoMock).getByType(any()); - mibManager.delete(VSP_ID, VERSION, COMPONENT_ID, ArtifactType.SNMP_POLL, USER1); - - verify(mibDaoMock, never()).delete(anyObject()); - } - - @Test - public void testDeleteComponentMib() { - doReturn(Optional.of(new MibEntity(VSP_ID, VERSION, COMPONENT_ID, "artifactId"))).when - (mibDaoMock).getByType(anyObject()); - - mibManager.delete(VSP_ID, VERSION, COMPONENT_ID, ArtifactType.SNMP_POLL, USER1); - - verify(mibDaoMock).delete(anyObject()); - } - - - private InputStream getFileInputStream(String fileName) { - URL url = this.getClass().getResource(fileName); - try { - return url.openStream(); - } catch (IOException exception) { - exception.printStackTrace(); - return null; - } - } -} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImplTest.java new file mode 100644 index 0000000000..534c630e40 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImplTest.java @@ -0,0 +1,164 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.core.enrichment.types.MonitoringUploadType; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Arrays; +import java.util.Optional; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +public class MonitoringUploadsManagerImplTest { + + private static final String USER1 = "ComponentsUploadTestUser"; + private static final String COMPONENT_ID = "COMPONENT_ID"; + private static final String VSP_ID = "vspId"; + private static final Version VERSION = new Version(0, 1); + private static final String trapFileName = "MMSC.zip"; + private static final String pollFileName = "MNS OAM FW.zip"; + private static final String vesFileName = "vesTest-yml_only.zip"; + private static final String invalidVesFileName = "invalid_ves_file.zip"; + private static final String notZipFileName = "notZipFile"; + private static final String zipWithFoldersFileName = "zipFileWithFolder.zip"; + private static final String emptyZipFileName = "emptyZip.zip"; + private static final String ZIP_DIR = "/vspmanager/zips/"; + + @Mock + private ComponentArtifactDao componentArtifactDaoMock; + @InjectMocks + private MonitoringUploadsManagerImpl moitoringUploadsManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test(expectedExceptions = CoreException.class) + public void testUploadEmptyZip() { + InputStream zis = getFileInputStream(ZIP_DIR + emptyZipFileName); + moitoringUploadsManager.upload(zis, emptyZipFileName, VSP_ID, VERSION, COMPONENT_ID, + MonitoringUploadType.SNMP_TRAP, USER1); + } + + @Test + public void testUploadInvalidZip() { + URL url = this.getClass().getResource("/notZipFile"); + try { + moitoringUploadsManager + .upload(url.openStream(), notZipFileName, VSP_ID, VERSION, COMPONENT_ID, + MonitoringUploadType.VES_EVENTS, USER1); + Assert.fail(); + } catch (Exception exception) { + Assert.assertEquals(exception.getMessage(), "Invalid zip file"); + } + } + + @Test + public void testUploadZipWithFolders() { + InputStream zis = getFileInputStream(ZIP_DIR + zipWithFoldersFileName); + + try { + moitoringUploadsManager + .upload(zis, zipWithFoldersFileName, VSP_ID, VERSION, COMPONENT_ID, + MonitoringUploadType.SNMP_TRAP, USER1); + Assert.fail(); + } catch (Exception exception) { + Assert.assertEquals(exception.getMessage(), "Zip file should not contain folders"); + } + } + + @Test + public void testUploadVEsEventZipWithNonYamlFiles() { + InputStream zis = getFileInputStream(ZIP_DIR + invalidVesFileName); + + try { + moitoringUploadsManager + .upload(zis, invalidVesFileName, VSP_ID, VERSION, COMPONENT_ID, + MonitoringUploadType.VES_EVENTS, USER1); + Assert.fail(); + } catch (Exception exception) { + Assert.assertEquals(exception.getMessage(), + "Wrong VES EVENT Artifact was uploaded - all files contained in Artifact must be YAML " + + "files (using .yaml/.yml extensions)"); + } + } + + + @Test + public void testListMonitoringFilenames() { + ComponentMonitoringUploadEntity artifact1 = + new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifact1"); + artifact1.setType(MonitoringUploadType.SNMP_TRAP); + artifact1.setArtifactName(trapFileName); + + ComponentMonitoringUploadEntity artifact2 = + new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifact2"); + artifact2.setType(MonitoringUploadType.SNMP_POLL); + artifact2.setArtifactName(pollFileName); + + ComponentMonitoringUploadEntity artifact3 = + new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifact3"); + artifact3.setType(MonitoringUploadType.VES_EVENTS); + artifact3.setArtifactName(vesFileName); + + doReturn(Arrays.asList(artifact1, artifact2, artifact3)) + .when(componentArtifactDaoMock).list(anyObject()); + + MonitoringUploadStatus monitoringUploadStatus = + moitoringUploadsManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID, USER1); + + Assert.assertEquals(monitoringUploadStatus.getSnmpTrap(), trapFileName); + Assert.assertEquals(monitoringUploadStatus.getSnmpPoll(), pollFileName); + Assert.assertEquals(monitoringUploadStatus.getVesEvent(), vesFileName); + } + + @Test (expectedExceptions = CoreException.class) + public void testDeleteComponentMibWhenNone() { + doReturn(Optional.empty()).when(componentArtifactDaoMock).getByType(any()); + moitoringUploadsManager + .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL, USER1); + + verify(componentArtifactDaoMock, never()).delete(anyObject()); + } + + @Test + public void testDeleteComponentMonitoringUpload() { + doReturn(Optional + .of(new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifactId"))) + .when + (componentArtifactDaoMock).getByType(anyObject()); + + moitoringUploadsManager + .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL, USER1); + + verify(componentArtifactDaoMock).delete(anyObject()); + } + + + private InputStream getFileInputStream(String fileName) { + URL url = this.getClass().getResource(fileName); + try { + return url.openStream(); + } catch (IOException exception) { + exception.printStackTrace(); + return null; + } + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java index a143fd36e8..b2cfba7672 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java @@ -7,14 +7,17 @@ import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; @@ -22,6 +25,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -29,6 +33,7 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class NicManagerImplTest { private static final String NIC_NOT_EXIST_MSG = @@ -50,6 +55,8 @@ public class NicManagerImplTest { private CompositionEntityDataManager compositionEntityDataManagerMock; @Mock private NetworkManager networkManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDao; @InjectMocks @Spy private NicManagerImpl nicManager; @@ -87,6 +94,112 @@ public class NicManagerImplTest { } } + @Test + public void testCreate() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + Nic nic = nicEntity.getNicCompositionData(); + nic.setNetworkType(NetworkType.Internal); + nicEntity.setNicCompositionData(nic); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<NicEntity> nicEntities = new ArrayList<>(); + doReturn(nicEntities).when(nicDao).list(anyObject()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + + NicEntity created = nicManager.createNic(nicEntity,USER); + Assert.assertNotNull(created); + } + + @Test + public void testCreateWithDupNicName() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + Nic nic = nicEntity.getNicCompositionData(); + nic.setNetworkType(NetworkType.Internal); + nicEntity.setNicCompositionData(nic); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<NicEntity> nicEntities = new ArrayList<>(); + + NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + Nic newNameNic = nicEntityDiffName.getNicCompositionData(); + newNameNic.setName(NIC1_ID + " Name"); + nicEntityDiffName.setNicCompositionData(newNameNic); + nicEntities.add(nicEntityDiffName); + doReturn(nicEntities).when(nicDao).list(anyObject()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + + try { + NicEntity created = nicManager.createNic(nicEntity,USER); + } catch (CoreException exception) { + Assert.assertEquals("Invalid request, NIC with name "+ nic.getName() + + " already exist for component with ID "+ nicEntity.getComponentId() +".", + exception.code().message()); + Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_NIC_NAME_NOT_ALLOWED, + exception.code().id()); + } + } + + @Test + public void testCreateWithExternalNetworkType() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + Nic nic = nicEntity.getNicCompositionData(); + nic.setNetworkType(NetworkType.External); + nicEntity.setNicCompositionData(nic); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<NicEntity> nicEntities = new ArrayList<>(); + doReturn(nicEntities).when(nicDao).list(anyObject()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + + try { + NicEntity created = nicManager.createNic(nicEntity,USER); + } catch (CoreException exception) { + Assert.assertEquals("Invalid request,NetworkId not allowed for External Networks", + exception.code().message()); + Assert.assertEquals(VendorSoftwareProductErrorCodes.NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK, + exception.code().id()); + } + } + + @Test + public void testCreateWithNetworkDesc() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + Nic nic = nicEntity.getNicCompositionData(); + nic.setNetworkType(NetworkType.Internal); + nic.setNetworkDescription(NIC1_ID); + nicEntity.setNicCompositionData(nic); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + Collection<NicEntity> nicEntities = new ArrayList<>(); + doReturn(nicEntities).when(nicDao).list(anyObject()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + + try { + NicEntity created = nicManager.createNic(nicEntity,USER); + } catch (CoreException exception) { + Assert.assertEquals("Invalid request, Network Description not allowed for Internal Networks", + exception.code().message()); + Assert.assertEquals(VendorSoftwareProductErrorCodes + .NETWORK_DESCRIPTION_NOT_ALLOWED_FOR_INTERNAL_NETWORK,exception.code().id()); + } + } + + @Test + public void testDeleteNic() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + doReturn(nicEntity).when(nicDao).get(anyObject()); + + nicManager.deleteNic(VSP_ID,new Version(0,1),COMPONENT_ID,NIC1_ID,USER); + + } + + @Test + public void testUpdateNicQuestionnaire() { + NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); + + doReturn(nicEntity).when(nicDao).get(anyObject()); + + nicManager.updateNicQuestionnaire(VSP_ID,new Version(0,1),COMPONENT_ID,NIC1_ID,"Ques",USER); + + } + // @Test(dependsOnMethods = "testListWhenNone") // public void testCreate() { // NIC1_ID = testCreate(VSP_ID, COMPONENT_ID, NETWORK1_ID, NETWORK1_ID.getNetworkCompositionData().getName()); @@ -122,7 +235,7 @@ public class NicManagerImplTest { public void testCreateOnUploadVsp_negative() { testCreate_negative(new NicEntity(VSP_ID, VERSION, COMPONENT_ID, null), USER, - VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + VendorSoftwareProductErrorCodes.ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @Test @@ -230,7 +343,7 @@ public class NicManagerImplTest { @Test public void testDeleteOnUploadVsp_negative() { testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER, - VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + VendorSoftwareProductErrorCodes.DELETE_NIC_NOT_ALLOWED); } @Test(expectedExceptions = CoreException.class, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 5a2f76b6fa..f79a56bebf 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -20,8 +20,6 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; @@ -29,7 +27,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; -import org.openecomp.core.enrichment.types.ArtifactType; import org.openecomp.core.factory.impl.AbstractFactoryBase; import org.openecomp.core.model.dao.EnrichedServiceModelDao; import org.openecomp.core.model.dao.ServiceModelDao; @@ -48,7 +45,8 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService; -import org.openecomp.sdc.vendorsoftwareproduct.MibManager; +import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager; +import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; @@ -105,9 +103,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -/** - * Created by TALIO on 4/23/2016 - */ public class VendorSoftwareProductManagerImplTest { private static final String INVALID_VERSION_MSG = "Invalid requested version."; @@ -147,6 +142,8 @@ public class VendorSoftwareProductManagerImplTest { private PackageInfoDao packageInfoDao; @Mock private VendorSoftwareProductInfoDao vspInfoDaoMock; + @Mock + private ManualVspToscaManager manualVspToscaManager; @Spy @@ -154,7 +151,7 @@ public class VendorSoftwareProductManagerImplTest { private VendorSoftwareProductManagerImpl vendorSoftwareProductManager; private OrchestrationTemplateCandidateManager candidateManager; - private MibManager mibManager; + private MonitoringUploadsManager monitoringUploadsManager; @Captor private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; @@ -467,6 +464,7 @@ public class VendorSoftwareProductManagerImplTest { VSP_ID, USER1, VersionableEntityAction.Read); VspDetails vsp = new VspDetails(VSP_ID, VERSION01); + vsp.setOnboardingMethod("Manual"); doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01); @@ -757,20 +755,21 @@ public class VendorSoftwareProductManagerImplTest { return fileNames; } - + /* + //Disabled for sonar null pointer issue for componentEntities private Pair<String, String> uploadMib(String vspId, String user, String filePath, String fileName) { List<ComponentEntity> componentEntities = null; //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user); - mibManager.upload(getFileInputStream(filePath), + monitoringUploadsManager.upload(getFileInputStream(filePath), fileName, vspId, - VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL, user); + VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user); //TODO: add validate of addActionLog() func call return new ImmutablePair<>(componentEntities.get(0).getId(), componentEntities.get(0).getComponentCompositionData() .getDisplayName()); - } + }*/ private void createPackageFromUpload(String vspId, String user, String filePath) throws IOException { @@ -901,6 +900,7 @@ public class VendorSoftwareProductManagerImplTest { vspDetails.setVlmVersion(new Version(1, 0)); vspDetails.setLicenseAgreement(licenseAgreement); vspDetails.setFeatureGroups(featureGroups); + vspDetails.setOnboardingMethod("HEAT"); return vspDetails; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java index 134dbfb5d4..3d98ab76c6 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -92,6 +92,8 @@ public class CandidateServiceImplTest { vspDetails.setName("vspTest"); vspDetails.setDescription("Test description"); vspDetails.setVersion(new Version(0, 1)); + //vspDetails.setOnboardingMethod(VSPCommon.OnboardingMethod.HEAT.name()); + vspDetails.setOnboardingMethod("HEAT"); FilesDataStructure structure = JsonUtil.json2Object(getExpectedJson(), FilesDataStructure.class); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java index d6060e6114..a85153ecef 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java @@ -26,7 +26,7 @@ import org.mockito.MockitoAnnotations; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaUtil; -import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; +import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/schemagenerator/SchemaGeneratorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/schemagenerator/SchemaGeneratorTest.java index fdbf400406..33cf18c463 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/schemagenerator/SchemaGeneratorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/schemagenerator/SchemaGeneratorTest.java @@ -252,12 +252,16 @@ public class SchemaGeneratorTest { } @Test - public void testGenerateNicCompositionManual() { + public void testGenerateNicCompositionManual() {Nic nic = new Nic(); + nic.setName("upload nic1 name"); + nic.setDescription("upload nic1 desc"); + nic.setNetworkType(NetworkType.Internal); NicCompositionSchemaInput input = new NicCompositionSchemaInput(); + input.setManual(true); input.setNetworkIds( Arrays.asList("manual networkId1", "manual networkId2", "manual networkId3")); - + input.setNic(nic); 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/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 index e1073db941..4d925c00cd 100644 --- 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 @@ -72,7 +72,8 @@ public class HeatCleanupOnNewUploadTest {/* VspDetails vspDetails = vendorSoftwareProductManager.createVsp(VSPCommon .createVspDetails(null, null, "VSPTestEmpty", "Test-vsp-empty", "vendorName", "vlm1Id", - "icon", "category", "subCategory", "123", null), USER1); + "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.HEAT.name()), + USER1); vspId = vspDetails.getId(); vspActiveVersion = vspDetails.getVersion(); } @@ -106,7 +107,7 @@ public class HeatCleanupOnNewUploadTest {/* String componentId = components.get(0).getId(); vendorSoftwareProductManager - .upload(mib, "vDNS.zip", vspId, componentId, ArtifactType.SNMP_TRAP, USER1); + .upload(mib, "vDNS.zip", vspId, componentId, MonitoringUploadType.SNMP_TRAP, USER1); vendorSoftwareProductManager .createProcess(new ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/invalidComponent.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/invalidComponent.json index 9b10297572..be9e13adde 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/invalidComponent.json +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/invalidComponent.json @@ -6,9 +6,6 @@ "drivers": ",Lz-m3R7iwRREmjBA3Ss6b0K8YBcH4SS66UJSG8OGTlaMs6Be" }, "image": { - "ephemeralDiskSizePerVM": 8, - "format": "iso", - "bootDiskSizePerVM": 100, "providedBy": "Vendor" }, "dnsConfiguration": "dolore adipisicing proident aute amet", diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/schema/componentQuestionnaire.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/schema/componentQuestionnaire.json index e0bd377e26..7870df8ab2 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/schema/componentQuestionnaire.json +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/schema/componentQuestionnaire.json @@ -157,11 +157,12 @@ "MemoryRAM": { "type": "string", "enum": [ + "1 GB", "2 GB", "4 GB", "8 GB" ], - "default": "2 GB" + "default": "1 GB" } }, "additionalProperties": false diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/validComponent.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/validComponent.json index 4e9e9aa6c0..316d8c5bed 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/validComponent.json +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/quesionnaire/validComponent.json @@ -6,9 +6,6 @@ "drivers": ",Lz-m3R7iwRREmjBA3Ss6b0K8YBcH4SS66UJSG8OGTlaMs6Be" }, "image": { - "ephemeralDiskSizePerVM": 8, - "format": "iso", - "bootDiskSizePerVM": 100, "providedBy": "Vendor" }, "dnsConfiguration": "dolore adipisicing proident aute amet", diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation/zips/various/vesTest-yml_only.zip b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation/zips/various/vesTest-yml_only.zip Binary files differnew file mode 100644 index 0000000000..8522252232 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation/zips/various/vesTest-yml_only.zip diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager/zips/invalid_ves_file.zip b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager/zips/invalid_ves_file.zip Binary files differnew file mode 100644 index 0000000000..d96a5b6e16 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager/zips/invalid_ves_file.zip |