diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test')
27 files changed, 1525 insertions, 2168 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 index ab7a70b6a7..3df06ba8eb 100644 --- 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 @@ -1,33 +1,5 @@ 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"; 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 index 45ba4fb434..77c81111a5 100644 --- 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 @@ -1,33 +1,5 @@ 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.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"; 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 index 5dcb7f9b62..d78f4045b6 100644 --- 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 @@ -21,50 +21,48 @@ import static org.mockito.Mockito.verify; public class ImagesTest { - private static String VSP_ID = "VSP_ID"; - private static String COMP_ID = "COMP_ID"; - private static String ID = "ID"; - private static String USER = "USER"; - public static final Version VERSION01 = new Version(0, 1); + private static String VSP_ID = "VSP_ID"; + private static String COMP_ID = "COMP_ID"; + private static String ID = "ID"; + public static final Version VERSION01 = new Version("version_id"); - @Mock - private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; + @Mock + private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; - @Mock - private CompositionEntityDataManager compositionEntityDataManager; + @Mock + private CompositionEntityDataManager compositionEntityDataManager; - @InjectMocks - @Spy - private ImageManagerImpl imageManager; + @InjectMocks + @Spy + private ImageManagerImpl imageManager; - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } - @Test - public void createImage() - { - ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); - doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + @Test + public void createImage() { + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); + doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); - imageManager.createImage(imageEntity, USER); - verify(compositionEntityDataManager).createImage(imageEntity); - } + imageManager.createImage(imageEntity); + verify(compositionEntityDataManager).createImage(imageEntity); + } - @Test - public void createImageHeat() - { - ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); - - try { - imageManager.createImage(imageEntity, USER); - Assert.fail(); - } catch (CoreException exception) { - Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); - } + @Test + public void createImageHeat() { + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + + try { + imageManager.createImage(imageEntity); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), + VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); } + } /*private static final String USER1 = "imageTestUser1"; private static final String USER2 = "imageTestUser2"; private static final Version VERSION01 = new Version(0, 1); @@ -93,40 +91,40 @@ public class ImagesTest { vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null, - VSPCommon.OnboardingMethod.Manual.name()), USER1 + VSPCommon.OnboardingMethod.Manual.name())1 ); 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); + Manual.name())1); 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); + .OnboardingMethod.HEAT.name())1); vsp3Id = vsp3.getId(); ComponentEntity comp = new ComponentEntity(); comp.setVspId(vsp2Id); comp.setCompositionData(comp1); - ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1); + ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1); comp1Id = createdComp.getId(); } @Test public void testListImagesNonExistingVspId_negative() { - testList_negative("non existing vsp id", null, image1Id, USER1, + testList_negative("non existing vsp id", null, image1Id1, 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, + testList_negative(vsp1Id, VERSION01, "444"1, 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); @@ -137,20 +135,20 @@ public class ImagesTest { 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); + vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1); System.out.println("size::"+imageEntities.size()); } @Test public void testCreateNonExistingVspId_negative() { - testCreate_negative(new ImageEntity("non existing vsp id", null, null, null), USER1, + testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1, 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, + testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1, 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); @@ -158,8 +156,8 @@ public class ImagesTest { @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative") public void testCreateOnAvailableVsp_negative() { - vendorSoftwareProductManager.checkin(vsp1Id, USER1); - testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER1, + vendorSoftwareProductManager.checkin(vsp1Id1); + testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1, VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY, "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not" + " checked out."); @@ -167,8 +165,8 @@ public class ImagesTest { @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative") public void testCreateOnVspOtherUser_negative() { - vendorSoftwareProductManager.checkout(vsp1Id, USER1); - testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER2, + vendorSoftwareProductManager.checkout(vsp1Id1); + testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2, 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+ "."); @@ -180,11 +178,11 @@ public class ImagesTest { ComponentEntity comp = new ComponentEntity(); comp.setVspId(vsp1Id); comp.setCompositionData(comp1); - ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1); + ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1); String compId = createdComp.getId(); - vendorSoftwareProductManager.checkin(vsp1Id, USER1); - vendorSoftwareProductManager.checkout(vsp1Id, USER1); + vendorSoftwareProductManager.checkin(vsp1Id1); + vendorSoftwareProductManager.checkout(vsp1Id1); for(int i = 1; i<=3; i++) { ImageEntity imageEntity = new ImageEntity(); @@ -197,17 +195,17 @@ public class ImagesTest { //image.setFormat("aki"); //image.setMd5("233343DDDD"); imageEntity.setImageCompositionData(image); - ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1); + ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1); } Collection<ImageEntity> imageEntities = - vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1); + vendorSoftwareProductManager.listImages(vsp1Id, null, compId1); Assert.assertEquals(imageEntities.size(), 3); - vendorSoftwareProductManager.undoCheckout(vsp1Id, USER1); + vendorSoftwareProductManager.undoCheckout(vsp1Id1); - imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1); + imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1); Assert.assertEquals(imageEntities.size(), 0); } @@ -217,7 +215,7 @@ public class ImagesTest { final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder = NotSupportedHeatOnboardMethodErrorBuilder .getAddImageNotSupportedHeatOnboardMethodErrorBuilder(); - testCreate_negative(new ImageEntity(vsp3Id, null, null, null), USER1, + testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1, addImageNotSupportedHeatOnboardMethodErrorBuilder.id(), addImageNotSupportedHeatOnboardMethodErrorBuilder.message() ); @@ -252,19 +250,19 @@ public class ImagesTest { @Test public void testGet() { ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2"); - testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId(), USER1, createdImage); + testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage); } @Test public void testGetNonExistingVspId_negative() { - testGet_negative("non existing vsp id", null, null, image1Id, USER1, + testGet_negative("non existing vsp id", null, null, image1Id1, 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, + testGet_negative(vsp1Id, VERSION01, "111", null1, 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); @@ -274,7 +272,7 @@ public class ImagesTest { public void testUpdateNonExistingVspId_negative() { ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id); - testUpdate_negative(imageEntity, USER1, + testUpdate_negative(imageEntity1, VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); } @@ -283,7 +281,7 @@ public class ImagesTest { public void testUpdateNonExistingVfcId_negative() { ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null); - testUpdate_negative(imageEntity, USER1, + testUpdate_negative(imageEntity1, 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); @@ -293,7 +291,7 @@ public class ImagesTest { public void testUpdateNonExistingImageId_negative() { ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222"); - testUpdate_negative(imageEntity, USER1, + testUpdate_negative(imageEntity1, 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 ); @@ -308,7 +306,7 @@ public class ImagesTest { //imageCompositionData.setVersion("10.0"); imageCompositionData.setDescription("updated image"); - vendorSoftwareProductManager.updateImage(imageEntity, USER1); + vendorSoftwareProductManager.updateImage(imageEntity1); testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity ); image2Id = imageEntity.getId(); @@ -318,7 +316,7 @@ public class ImagesTest { public void testUpdateNegative_UniqueName() { final CompositionEntityResponse<Image> image = vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, - image2Id, USER1); + image2Id1); final Image data = image.getData(); final Image imageCompositionData = data; @@ -326,7 +324,7 @@ public class ImagesTest { ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id ); entity.setImageCompositionData(imageCompositionData); - testUpdate_negative(entity, USER1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder( + testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder( "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id() ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id) .message() ); @@ -335,13 +333,13 @@ public class ImagesTest { @Test(dependsOnMethods = "testUpdateNegative_UniqueName") public void testDeleteImage() { CompositionEntityResponse<Image> image = - vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id, USER1); + vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1); Assert.assertNotNull(image.getData()); - vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id, USER1); + vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1); - testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id, USER1, + testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1, 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 ); @@ -352,7 +350,7 @@ public class ImagesTest { public void testDeleteNonExistingVspId_negative() { ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id); - testDelete_negative(imageEntity, USER1, + testDelete_negative(imageEntity1, VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST, "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." ); } @@ -361,7 +359,7 @@ public class ImagesTest { public void testDeleteNonExistingVfcId_negative() { ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null); - testDelete_negative(imageEntity, USER1, + testDelete_negative(imageEntity1, 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); @@ -371,7 +369,7 @@ public class ImagesTest { public void testDeleteNonExistingImageId_negative() { ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222"); - testDelete_negative(imageEntity, USER1, + testDelete_negative(imageEntity1, 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 ); @@ -386,7 +384,7 @@ public class ImagesTest { final QuestionnaireResponse imageQuestionnaire = vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id, - imageEntity.getId(), USER1); + imageEntity.getId()1); String imageDetails = imageQuestionnaire.getData(); Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat()); @@ -422,7 +420,7 @@ public class ImagesTest { // image.setMd5("233343DDDD"); imageEntity.setImageCompositionData(image); - ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1); + ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1); image1Id = createdImage.getId(); return createdImage; } @@ -430,7 +428,7 @@ public class ImagesTest { 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); + response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId); Assert.assertEquals(response.getId(), expected.getId()); Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData(). getFileName()); @@ -442,7 +440,7 @@ public class ImagesTest { private void testCreate_negative(ImageEntity image, String user, String expectedErrorCode, String expectedErrorMsg) { try { - vendorSoftwareProductManager.createImage(image, user); + vendorSoftwareProductManager.createImage(image); Assert.fail(); } catch (CoreException exception) { Assert.assertEquals(exception.code().id(), expectedErrorCode); @@ -454,7 +452,7 @@ public class ImagesTest { String user, String expectedErrorCode, String expectedErrorMsg) { try { - vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId, user); + vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId); Assert.fail(); } catch (CoreException exception) { Assert.assertEquals(exception.code().id(), expectedErrorCode); @@ -465,7 +463,7 @@ public class ImagesTest { private void testList_negative(String vspId, Version version, String componentId, String user, String expectedErrorCode, String expectedErrorMsg) { try { - vendorSoftwareProductManager.listImages(vspId, version, componentId, user); + vendorSoftwareProductManager.listImages(vspId, version, componentId); Assert.fail(); } catch (CoreException exception) { Assert.assertEquals(exception.code().id(), expectedErrorCode); @@ -478,7 +476,7 @@ public class ImagesTest { String expectedErrorCode, String expectedErrorMsg) { try { - vendorSoftwareProductManager.updateImage(imageEntity, user); + vendorSoftwareProductManager.updateImage(imageEntity); Assert.fail(); } catch (CoreException exception) { Assert.assertEquals(exception.code().id(), expectedErrorCode); @@ -491,7 +489,7 @@ public class ImagesTest { String expectedErrorCode, String expectedErrorMsg) { try { - vendorSoftwareProductManager.updateImage(imageEntity, user); + vendorSoftwareProductManager.updateImage(imageEntity); 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/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index b544d13ec7..e8e0f2c92b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -30,12 +30,10 @@ import org.mockito.MockitoAnnotations; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.validation.util.MessageContainerUtil; -import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; @@ -54,16 +52,11 @@ import java.io.InputStream; import java.util.List; import java.util.Objects; -import static org.mockito.Mockito.verify; -import static org.mockito.Matchers.eq; - public class QuestionnaireDataServiceTest { public static final Version VERSION = new Version(0, 1); private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl(); @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock private CandidateService candidateServiceMock; @Mock private HealingManager healingManagerMock; @@ -73,8 +66,6 @@ public class QuestionnaireDataServiceTest { private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; @Mock private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private ActivityLogManager activityLogManagerMock; @Captor private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; @@ -82,7 +73,7 @@ public class QuestionnaireDataServiceTest { @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; - private final UploadFileTest uploadFileTest = new UploadFileTest(); + private UploadFileTest uploadFileTest = new UploadFileTest(); private static String vspId; private static Version vspActiveVersion; @@ -110,31 +101,27 @@ public class QuestionnaireDataServiceTest { // TODO: 3/15/2017 fix and enable //@Test public void testQuestionnaireDataAfterIllegalUpload() throws IOException { - try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) { - UploadFileResponse uploadFileResponse = candidateManager - .upload(vspId, VERSION, zipInputStream, USER1, "zip", "missingYml"); + UploadFileResponse uploadFileResponse = + candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml"); } - InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); } private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath, - int listSizeToCheck) throws IOException { + int listSizeToCheck) + throws IOException { try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) { - UploadFileResponse uploadFileResponse = candidateManager - .upload(vspId, VERSION, - zipInputStream, USER1, "zip", "file"); - - candidateManager.process(vspId, VERSION, USER1); + UploadFileResponse uploadFileResponse = + candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file"); + candidateManager.process(vspId, VERSION); Assert.assertTrue(MapUtils.isEmpty( MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); } - InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); Assert.assertNotNull(informationArtifactData); @@ -143,11 +130,6 @@ public class QuestionnaireDataServiceTest { informationArtifactData.getComponentQuestionnaires(); Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck); - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(),eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION.getMajor()+1)); - Assert.assertTrue(activityLogEntity.isSuccess()); - return informationArtifactData; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentDependencyModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentDependencyModelTest.java index c3f78b6cb0..a2cbaa7eb6 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentDependencyModelTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComponentDependencyModelTest.java @@ -6,136 +6,217 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; -import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentDependencyModelErrorBuilder; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; -import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.when; + public class ComponentDependencyModelTest { - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); + private static final String VSP_ID = "vsp_id"; + private static final Version VERSION = new Version("version_id"); + private static final String COMP_DEP_ID = "comp_dep_id"; + + private static final String COMP_ID_1 = "comp_id_1"; + private static final String COMP_ID_2 = "comp_id_2"; + private static final String COMP_ID_3 = "comp_id_3"; + private static final String COMP_ID_4 = "comp_id_4"; @Spy @InjectMocks private ComponentDependencyModelManagerImpl componentDependencyModelManager; @Mock - private VendorSoftwareProductManager vendorSoftwareProductManager; - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDao; - @Mock - private ComponentDao componentDao; - @Mock private ComponentManager componentManager; + @Mock + private ComponentDependencyModelDao componentDependencyModelDao; - private static String vsp1Id; - private static String sourceComp1Id; - private static String sourceComp2Id; - private static String sourceComp3Id; - private static String sourceComp4Id; - private static final String USER1 = "TestUser1"; - private static final String USER2 = "TestUser2"; - private static final Version VERSION01 = new Version(0, 1); - private static String modelId = "model1"; - - - @BeforeClass + @BeforeMethod private void init() { MockitoAnnotations.initMocks(this); } - public static VspDetails createVspDetails(String id, Version version, String name, String desc, - String vendorName, String vlm, String icon, - String category, String subCategory, - String licenseAgreement, List<String> featureGroups - ) { - VspDetails vspDetails = new VspDetails(id, version); - vspDetails.setName(name); - vspDetails.setDescription(desc); - vspDetails.setIcon(icon); - vspDetails.setCategory(category); - vspDetails.setSubCategory(subCategory); - vspDetails.setVendorName(vendorName); - vspDetails.setVendorId(vlm); - vspDetails.setVlmVersion(new Version(1, 0)); - vspDetails.setLicenseAgreement(licenseAgreement); - vspDetails.setFeatureGroups(featureGroups); - return vspDetails; + @Test + public void testListDependency() { + List<ComponentDependencyModelEntity> entities = new ArrayList<>(); + entities.add(createModelEntity(COMP_ID_1, COMP_ID_2)); + entities.add(createModelEntity(COMP_ID_3, COMP_ID_4)); + + Mockito.when(componentDependencyModelDao + .list(new ComponentDependencyModelEntity(VSP_ID, VERSION, null))) + .thenReturn(entities); + + Collection<ComponentDependencyModelEntity> list = + componentDependencyModelManager.list(VSP_ID, VERSION); + + Mockito.verify(componentDependencyModelDao, Mockito.times(1)) + .list(new ComponentDependencyModelEntity(VSP_ID, VERSION, null)); + + Assert.assertEquals(2, list.size()); + } + + @Test + public void testCreateDependency() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_2); + + componentDependencyModelManager.createComponentDependency(modelEntity, VSP_ID, VERSION); + Mockito.verify(componentDependencyModelDao, Mockito.times(1)).create(modelEntity); + } + + @Test + public void testCreateDependencyNegative_SameSourceTarget() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_1); + testCreateDependency_negative(modelEntity, VSP_ID, VERSION, + ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().id(), + ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().message()); } @Test - public void testCreateNegative_NoSourceId() { - List<ComponentDependencyModelEntity> entities = new ArrayList<ComponentDependencyModelEntity>(); - entities.add(createModelEntity(null, sourceComp2Id)); - testCreate_negative(entities, vsp1Id, VERSION01, USER1, + public void testCreateDependencyNegative_NoSourceId() { + + ComponentDependencyModelEntity modelEntity = createModelEntity(null, COMP_ID_1); + testCreateDependency_negative(modelEntity, VSP_ID, VERSION, ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().message()); - entities.clear(); - entities.add(createModelEntity("", sourceComp2Id)); - testCreate_negative(entities, vsp1Id, VERSION01, USER1, + + ComponentDependencyModelEntity modelEntity1 = createModelEntity("", COMP_ID_1); + testCreateDependency_negative(modelEntity1, VSP_ID, VERSION, ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().message()); } @Test - public void testCreateNegative_SameSourceTarget() { - List<ComponentDependencyModelEntity> entities = new ArrayList<ComponentDependencyModelEntity>(); - entities.add(createModelEntity("sourceComp1Id", "sourceComp1Id")); - testCreate_negative(entities, vsp1Id, VERSION01, USER1, + public void testUpdateDependency() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_2); + modelEntity.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + + componentDependencyModelManager.update(modelEntity); + Mockito.verify(componentDependencyModelDao, Mockito.times(1)).update(modelEntity); + } + + @Test + public void testUpdateDependencyNegative_NoSourceId() { + + ComponentDependencyModelEntity modelEntity = createModelEntity(null, COMP_ID_1); + modelEntity.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + + testUpdateDependency_negative(modelEntity, + ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), + ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().message()); + + ComponentDependencyModelEntity modelEntity1 = createModelEntity("", COMP_ID_1); + modelEntity1.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity1); + + testUpdateDependency_negative(modelEntity1, + ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), + ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().message()); + } + + @Test + public void testUpdateDependencyNegative_SameSourceTarget() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_1); + modelEntity.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + testUpdateDependency_negative(modelEntity, ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().id(), ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().message()); } @Test - public void testCreate() { - List<ComponentDependencyModelEntity> entities = new ArrayList<ComponentDependencyModelEntity>(); - entities.add(createModelEntity("sourceComp1Id", "sourceComp2Id")); - entities.add(createModelEntity("sourceComp3Id", "sourceComp4Id")); - - componentDependencyModelManager.createComponentDependencyModel(entities, vsp1Id, VERSION01, - USER1); - Mockito.verify(vendorSoftwareProductDao, Mockito.times(1)).createComponentDependencyModel - (entities, vsp1Id, - VERSION01); + public void testDeleteDependency() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_2); + modelEntity.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + + componentDependencyModelManager.delete(VSP_ID, VERSION, COMP_DEP_ID); + Mockito.verify(componentDependencyModelDao, Mockito.times(1)).delete(modelEntity); + } + + @Test + public void testDeleteInvalidDependency() { + ComponentDependencyModelEntity delModelEntity = + createModelEntity(COMP_ID_1, COMP_ID_2); + delModelEntity.setId(COMP_DEP_ID); + + try { + componentDependencyModelManager.delete(VSP_ID, VERSION, COMP_DEP_ID); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), "VERSIONABLE_SUB_ENTITY_NOT_FOUND"); + Assert.assertEquals(exception.getMessage(), + String.format("Vendor Software Product Component Dependency Model with Id %s " + + "does not exist for Vendor Software Product with id %s and version %s", + COMP_DEP_ID, VSP_ID, VERSION.getId())); + } + } + + + @Test + public void testGetDependency() { + ComponentDependencyModelEntity modelEntity = + createModelEntity(COMP_ID_1, COMP_ID_2); + modelEntity.setId(COMP_DEP_ID); + + when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + + ComponentDependencyModelEntity retrieved = + componentDependencyModelManager.get(VSP_ID, VERSION, COMP_DEP_ID); + + Assert.assertEquals(retrieved.getSourceComponentId(), COMP_ID_1); + } private ComponentDependencyModelEntity createModelEntity(String sourceId, String targetId) { ComponentDependencyModelEntity entity = - new ComponentDependencyModelEntity(vsp1Id, VERSION01, modelId); + new ComponentDependencyModelEntity(VSP_ID, VERSION, COMP_DEP_ID); entity.setSourceComponentId(sourceId); entity.setTargetComponentId(targetId); entity.setRelation("dependsOn"); return entity; } - private Collection<ComponentDependencyModelEntity> getDependencyModel(String vspId, - Version version, - String user) { - return componentDependencyModelManager.list(vspId, version, user); + private void testCreateDependency_negative(ComponentDependencyModelEntity entity, String vspId, + Version version, String expectedErrorCode, + String expectedErrorMsg) { + try { + componentDependencyModelManager.createComponentDependency(entity, vspId, version); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); + Assert.assertEquals(exception.getMessage(), expectedErrorMsg); + } } - private void testCreate_negative(List<ComponentDependencyModelEntity> entities, String vspId, - Version version, String user, - String expectedErrorCode, String expectedErrorMsg) { + private void testUpdateDependency_negative(ComponentDependencyModelEntity entity, + String expectedErrorCode, String expectedErrorMsg) { try { - componentDependencyModelManager.createComponentDependencyModel(entities, vspId, version, - user); + componentDependencyModelManager.update(entity); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); Assert.assertEquals(exception.getMessage(), expectedErrorMsg); } 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 ee8295cafc..c7aa81873b 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 @@ -2,12 +2,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.NicManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; @@ -37,16 +34,13 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; public class ComponentManagerImplTest { - - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); - - private static final String COMP_NOT_EXIST_MSG = - "Vendor Software Product Component with Id 1 does not exist for Vendor Software Product with id VSP_ID and version 0.1"; - private static final String USER = "componentsTestUser"; private static final String VSP_ID = "VSP_ID"; - private static final Version VERSION = new Version(0, 1); - private static final String COMP1_ID = "1"; - private static final String COMP2_ID = "2"; + private static final Version VERSION = new Version("version_id"); + private static final String COMP1_ID = "comp1"; + private static final String COMP2_ID = "comp2"; + private static final String COMP_NOT_EXIST_MSG = + "Vendor Software Product Component with Id comp1 does not exist " + + "for Vendor Software Product with id VSP_ID and version version_id"; @Mock private ComponentDao componentDaoMock; @@ -67,20 +61,15 @@ public class ComponentManagerImplTest { @Test public void testListWhenNone() { - Collection<ComponentEntity> components = - componentManager.listComponents(VSP_ID, VERSION, USER); + Collection<ComponentEntity> components = componentManager.listComponents(VSP_ID, VERSION); Assert.assertEquals(components.size(), 0); } @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = "Vendor Software Product Component with Id dummyComponentId " + - "does not exist for Vendor Software Product with id dummyVsp and version 1.0") + expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) public void validateExceptionWhenTryingToRetriveNotExistingComponentEntity() { - Version version = Mockito.mock(Version.class); - doReturn("1.0").when(version).toString(); doReturn(null).when(componentDaoMock).get(anyObject()); - componentManager.validateComponentExistence("dummyVsp", version, "dummyComponentId", - "dummyUser"); + componentManager.validateComponentExistence(VSP_ID, VERSION, COMP1_ID); } @Test @@ -90,21 +79,20 @@ public class ComponentManagerImplTest { createComponent(VSP_ID, VERSION, COMP2_ID))) .when(componentDaoMock).list(anyObject()); - Collection<ComponentEntity> actual = - componentManager.listComponents(VSP_ID, VERSION, USER); + Collection<ComponentEntity> actual = componentManager.listComponents(VSP_ID, VERSION); Assert.assertEquals(actual.size(), 2); } @Test public void testDeleteListOnUploadVsp_negative() { - testDeleteList_negative(VSP_ID, VERSION, USER, + testDeleteList_negative(VSP_ID, VERSION, VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } -/* @Test - public void testCreate() { - COMP1_ID = testCreate(VSP_ID); - }*/ + /* @Test + public void testCreate() { + COMP1_ID = testCreate(VSP_ID); + }*/ @Test public void testCreate() { ComponentEntity expected = new ComponentEntity(VSP_ID, null, null); @@ -113,12 +101,12 @@ public class ComponentManagerImplTest { compData.setDescription("comp1 desc"); expected.setComponentCompositionData(compData); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + 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); + ComponentEntity created = componentManager.createComponent(expected); Assert.assertNotNull(created); //expected.setId(created.getId()); //expected.setVersion(VERSION); @@ -137,15 +125,14 @@ public class ComponentManagerImplTest { compData.setDescription("comp1 desc"); expected.setComponentCompositionData(compData); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + 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) { - log.debug("",exception); + ComponentEntity created = componentManager.createComponent(expected); + } 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()); @@ -161,14 +148,14 @@ public class ComponentManagerImplTest { expected.setComponentCompositionData(compData); doReturn(expected).when(componentDaoMock).get(anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(),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()); + doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); - CompositionEntityValidationData created = componentManager.updateComponent(expected, USER); + CompositionEntityValidationData created = componentManager.updateComponent(expected); Assert.assertNotNull(created); } @@ -182,20 +169,19 @@ public class ComponentManagerImplTest { expected.setComponentCompositionData(compData); doReturn(expected).when(componentDaoMock).get(anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(),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"); + 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()); + doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); try { - CompositionEntityValidationData created = componentManager.updateComponent(expected, USER); - } catch (CoreException exception) { - log.debug("",exception); + CompositionEntityValidationData created = componentManager.updateComponent(expected); + } catch (CoreException exception) { Assert.assertEquals("VFC with specified name already present in given VSP.", exception.code().message()); Assert.assertEquals(VendorSoftwareProductErrorCodes.VSP_VFC_DUPLICATE_NAME, @@ -220,7 +206,7 @@ public class ComponentManagerImplTest { @Test public void testCreateOnUploadVsp_negative() { - testCreate_negative(new ComponentEntity(VSP_ID, VERSION, null), USER, + testCreate_negative(new ComponentEntity(VSP_ID, VERSION, null), VendorSoftwareProductErrorCodes.VFC_ADD_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @@ -229,7 +215,7 @@ public class ComponentManagerImplTest { String componentId = "non existing component id"; doReturn(null).when(componentDaoMock).get(anyObject()); - testUpdate_negative(VSP_ID, VERSION, componentId, USER, + testUpdate_negative(VSP_ID, VERSION, componentId, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -254,7 +240,7 @@ public class ComponentManagerImplTest { CompositionEntityValidationData validationData = - componentManager.updateComponent(component, USER); + componentManager.updateComponent(component); Assert.assertTrue(validationData == null || validationData.getErrors() == null); verify(componentDaoMock).update(component); } @@ -277,7 +263,7 @@ public class ComponentManagerImplTest { component.setComponentCompositionData(compData); CompositionEntityValidationData validationData = - componentManager.updateComponent(component, USER); + componentManager.updateComponent(component); Assert.assertNotNull(validationData); Assert.assertEquals(validationData.getErrors().size(), 2); @@ -289,7 +275,7 @@ public class ComponentManagerImplTest { String componentId = "non existing component id"; doReturn(null).when(componentDaoMock).get(anyObject()); - testGet_negative(VSP_ID, VERSION, componentId, USER, + testGet_negative(VSP_ID, VERSION, componentId, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -300,7 +286,7 @@ public class ComponentManagerImplTest { doReturn("schema string").when(componentManager).getComponentCompositionSchema(anyObject()); - testGet(VSP_ID, VERSION, COMP1_ID, USER, expected); + testGet(VSP_ID, VERSION, COMP1_ID, expected); } @@ -329,14 +315,14 @@ public class ComponentManagerImplTest { @Test public void testDeleteOnUploadVsp_negative() { - testDelete_negative(VSP_ID, VERSION, COMP1_ID, USER, + testDelete_negative(VSP_ID, VERSION, COMP1_ID, VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) public void testGetNonExistingComponentQuestionnaire() throws Exception { - componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID, USER); + componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); } @Test @@ -347,7 +333,7 @@ public class ComponentManagerImplTest { doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject()); QuestionnaireResponse questionnaire = - componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID, USER); + componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); Assert.assertNotNull(questionnaire); Assert.assertEquals(questionnaire.getData(), null); Assert.assertEquals(questionnaire.getSchema(), schema); @@ -372,13 +358,13 @@ public class ComponentManagerImplTest { nicEntity2.setNicCompositionData(nic2); doReturn(Arrays.asList(nicEntity1, nicEntity2)) - .when(nicManagerMock).listNics(VSP_ID, VERSION, COMP1_ID, USER); + .when(nicManagerMock).listNics(VSP_ID, VERSION, COMP1_ID); String schema = "schema string"; doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject()); QuestionnaireResponse questionnaire = - componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID, USER); + componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); Assert.assertNotNull(questionnaire); Assert.assertEquals(questionnaire.getData(), component.getQuestionnaireData()); Assert.assertEquals(questionnaire.getSchema(), schema); @@ -389,7 +375,7 @@ public class ComponentManagerImplTest { expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) public void testUpdateNonExistingComponentQuestionnaire() throws Exception { doReturn(null).when(componentDaoMock).get(anyObject()); - componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data", USER); + componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data"); } @Test @@ -397,7 +383,7 @@ public class ComponentManagerImplTest { ComponentEntity component = createComponent(VSP_ID, VERSION, COMP1_ID); doReturn(component).when(componentDaoMock).get(anyObject()); - componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data", USER); + componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data"); verify(componentDaoMock) .updateQuestionnaireData(VSP_ID, VERSION, COMP1_ID, "questionnaire data"); @@ -417,79 +403,72 @@ public class ComponentManagerImplTest { Assert.assertEquals(actual.size(), 0); }*/ - private void testGet(String vspId, Version version, String componentId, String user, + private void testGet(String vspId, Version version, String componentId, ComponentEntity expected) { CompositionEntityResponse<ComponentData> - response = componentManager.getComponent(vspId, version, componentId, user); + response = componentManager.getComponent(vspId, version, componentId); Assert.assertEquals(response.getId(), expected.getId()); Assert.assertEquals(response.getData(), expected.getComponentCompositionData()); Assert.assertNotNull(response.getSchema()); } - private void testCreate_negative(ComponentEntity component, String user, + private void testCreate_negative(ComponentEntity component, String expectedErrorCode) { try { - componentManager.createComponent(component, user); + componentManager.createComponent(component); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testGet_negative(String vspId, Version version, String componentId, String user, + private void testGet_negative(String vspId, Version version, String componentId, String expectedErrorCode) { try { - componentManager.getComponent(vspId, version, componentId, user); + componentManager.getComponent(vspId, version, componentId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testUpdate_negative(String vspId, Version version, String componentId, String user, + private void testUpdate_negative(String vspId, Version version, String componentId, String expectedErrorCode) { try { - componentManager - .updateComponent(new ComponentEntity(vspId, version, componentId), user); + componentManager.updateComponent(new ComponentEntity(vspId, version, componentId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testList_negative(String vspId, Version version, String user, + private void testList_negative(String vspId, Version version, String expectedErrorCode) { try { - componentManager.listComponents(vspId, version, user); + componentManager.listComponents(vspId, version); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testDeleteList_negative(String vspId, Version version, String user, + private void testDeleteList_negative(String vspId, Version version, String expectedErrorCode) { try { - componentManager.deleteComponents(vspId, version, user); + componentManager.deleteComponents(vspId, version); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testDelete_negative(String vspId, Version version, String componentId, String user, + private void testDelete_negative(String vspId, Version version, String componentId, String expectedErrorCode) { try { - componentManager.deleteComponent(vspId, version, componentId, user); + componentManager.deleteComponent(vspId, version, componentId); Assert.fail(); } catch (CoreException exception) { - log.debug("",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/ComputeManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImplTest.java index eda5693cce..9058a73632 100644 --- 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 @@ -1,378 +1,348 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -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 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.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.NetworkManager; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; 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.ComputeEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; 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.ListComputeResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; -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.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.BeforeMethod; import org.testng.annotations.Test; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; -public class ComputeManagerImplTest { +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); +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 COMPUTE_NOT_EXIST_MSG = + "Vendor Software Product COMPUTE with Id compute1 does not exist for Vendor Software Product with " + + "id VSP_ID and version version_id"; - 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"; + private static final String VSP_ID = "VSP_ID"; + private static final Version VERSION = new Version("version_id"); + 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); + MockitoAnnotations.initMocks(this); } - @Test + @Test public void testListWhenNone() { - Collection<ListComputeResponse> computes = computeManager.listCompute(VSP_ID, VERSION, COMPONENT_ID, USER); + Collection<ListComputeResponse> computes = + computeManager.listComputes(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(computes.size(), 0); } @Test - public void testList(){ - doReturn(Arrays.asList( + 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()); - + .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 testCreateManualComputeWithDuplicateName() { - 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); - expectedDiffName.setId(COMPUTE1_ID + "Name"); - 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) { - log.debug("",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); + Collection<ListComputeResponse> computes = + computeManager.listComputes(VSP_ID, VERSION, COMPONENT_ID); + 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 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 testCreateOnNotManualCompute_negative() { + testCreate_negative(new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, null), + VendorSoftwareProductErrorCodes.ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } - @Test - public void testIllegalComputeUpdate() { - doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) - .when(computeDao).get(anyObject()); + @Test + public void testCreateManualCompute() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doNothing().when(computeManager) + .validateUniqueName(VSP_ID, VERSION, COMPONENT_ID, + expected.getComputeCompositionData().getName()); + doNothing().when(computeManager) + .createUniqueName(VSP_ID, VERSION, COMPONENT_ID, + expected.getComputeCompositionData().getName()); + String questionnaireSchema = "{}"; + doReturn(questionnaireSchema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + + computeManager.createCompute(expected); + verify(computeDao).create(expected); + } - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + @Test(expectedExceptions = CoreException.class) + public void testCreateManualComputeWithDuplicateName() { + ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + 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()); + doThrow(new CoreException( + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) + .when(computeManager).validateUniqueName(VSP_ID, VERSION, COMPONENT_ID, + expected.getComputeCompositionData().getName()); - 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); + computeManager.createCompute(expected); + } - CompositionEntityValidationData validationData = computeManager.updateCompute(computeEntity, USER); - Assert.assertNotNull(validationData); - Assert.assertEquals(validationData.getErrors().size(), 2); + @Test + public void testUpdateNonExistingComputeId_negative() { + testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } - verify(computeDao, never()).update(computeEntity); - } + @Test + public void testUpdateCompute() { + ComputeEntity retrieved = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + doReturn(retrieved).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); + + doNothing().when(computeManager) + .updateUniqueName(VSP_ID, VERSION, COMPONENT_ID, retrieved.getComputeCompositionData().getName(), + computeData.getName()); + + CompositionEntityValidationData validationData = + computeManager.updateCompute(computeEntity); + Assert.assertTrue(validationData == null || validationData.getErrors() == null); + verify(computeDao).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) { - log.debug("",ex); - Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_COMPUTE_NOT_ALLOWED); - } + @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); + 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); + } 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()); + @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); + verify(computeDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, json); + } - 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", + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + } - @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); + 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 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); - @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"; - String schema = "schema string"; + doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + QuestionnaireResponse questionnaire = + computeManager.getComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + Assert.assertNotNull(questionnaire); + Assert.assertEquals(questionnaire.getData(), compute.getQuestionnaireData()); + Assert.assertEquals(questionnaire.getSchema(), schema); + Assert.assertNull(questionnaire.getErrorMessage()); + } - QuestionnaireResponse questionnaire = - computeManager.getComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, USER); + @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, + VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); + } - Assert.assertNotNull(questionnaire); - Assert.assertEquals(questionnaire.getData(), compute.getQuestionnaireData()); - Assert.assertEquals(questionnaire.getSchema(), schema); - Assert.assertNull(questionnaire.getErrorMessage()); - } + @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()); + doNothing().when(computeManager).deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, + expected.getComputeCompositionData().getName()); + + computeManager.deleteCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); + verify(computeDao).delete(anyObject()); + } - @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 testDeleteOnNotExistCompute() { + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, + 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 expectedErrorCode) { + try { + computeManager.deleteCompute(vspId, version, componentId, computeId); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), expectedErrorCode); } + } - - 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) { - log.debug("",exception); - Assert.assertEquals(exception.code().id(), expectedErrorCode); - } + private void testGet_negative(String vspId, Version version, String componentId, String computeId, + String expectedErrorCode) { + try { + computeManager.getCompute(vspId, version, componentId, computeId); + 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) { - log.debug("",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) { - log.debug("",exception); - Assert.assertEquals(exception.code().id(), expectedErrorCode); - Assert.assertEquals(exception.getMessage(), expectedErrorMsg); - } + private void testList_negative(String vspId, Version version, String componentId, + String expectedErrorCode, String expectedErrorMsg) { + try { + computeManager.listComputes(vspId, version, componentId); + 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) { - log.debug("",exception); + private void testUpdate_negative(String vspId, Version version, String componentId, + String computeId, String expectedErrorCode) { + try { + computeManager.updateCompute(new ComputeEntity(vspId, version, componentId, computeId)); + 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) { - log.debug("",exception); - Assert.assertEquals(exception.code().id(), expectedErrorCode); - } + private void testCreate_negative(ComputeEntity computeEntity1, String expectedErrorCode) { + try { + computeManager.createCompute(computeEntity1); + 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; + private 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 deleted file mode 100644 index 598b97b34e..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeplomentFlavorManagerImplTest.java +++ /dev/null @@ -1,463 +0,0 @@ -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.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 testCreateManualDepFlavorWithIncorrectNameFormat() { - 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(expectedDiffName, USER); - Assert.fail(); - } - catch (CoreException ex) { - Assert.assertEquals(VendorSoftwareProductErrorCodes.DEPLOYMENT_FLAVOR_NAME_FORMAT_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 testManualUpdateDepFlavorIncorrectNameFormat() { - 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); - - try { - deploymentFlavorManager.updateDeploymentFlavor(deploymentFlavorEntity, USER); - Assert.fail(); - } - catch (CoreException ex) { - Assert.assertEquals(VendorSoftwareProductErrorCodes.DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED, - ex.code().id()); - } - } - - @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 { - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); - DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); - deploymentFlavor.setModel("Name"); - deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); - deploymentFlavorManager - .updateDeploymentFlavor(deploymentFlavorEntity, 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/DeploymentFlavorManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java index 82715d3fe6..6a5e7fa70c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImplTest.java @@ -1,18 +1,12 @@ 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.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; @@ -23,7 +17,6 @@ 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.composition.ComponentComputeAssociation; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData; @@ -39,13 +32,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -public class DeploymentFlavorManagerImplTest { - - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; - private static final String USER = "depFlavorTestUser"; +public class DeploymentFlavorManagerImplTest { private static final String VSP_ID = "VSP_ID"; - private static final Version VERSION = new Version(0, 1); + private static final Version VERSION = new Version("version_id"); private static final String COMPONENT_ID = "COMPONENT_ID"; private static final String DF1_ID = "df1"; private static final String DF2_ID = "df2"; @@ -55,11 +48,11 @@ public class DeploymentFlavorManagerImplTest { @Mock private VendorSoftwareProductInfoDao vspInfoDao; @Mock - DeploymentFlavorDao deploymentFlavorDaoMock; + private DeploymentFlavorDao deploymentFlavorDaoMock; @Mock - ComponentDao componentDaoMock; + private ComponentDao componentDaoMock; @Mock - ComputeDao computeDaoMock; + private ComputeDao computeDaoMock; @InjectMocks @Spy private DeploymentFlavorManagerImpl deploymentFlavorManager; @@ -72,26 +65,26 @@ public class DeploymentFlavorManagerImplTest { @Test public void testListWhenNone() { final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = - deploymentFlavorManager.listDeploymentFlavors(VSP_ID, VERSION, USER); + deploymentFlavorManager.listDeploymentFlavors(VSP_ID, VERSION); Assert.assertEquals(deploymentFlavorEntities.size(), 0); } @Test public void testCreateOnNotManual_negative() { - testCreate_negative(new DeploymentFlavorEntity(VSP_ID, VERSION, null), USER, + testCreate_negative(new DeploymentFlavorEntity(VSP_ID, VERSION, null), VendorSoftwareProductErrorCodes.CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @Test public void testCreateManualDepFlavor() { - DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + 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); + deploymentFlavorManager.createDeploymentFlavor(expected); verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected); } @@ -104,17 +97,16 @@ public class DeploymentFlavorManagerImplTest { DeploymentFlavor deploymentFlavor = expectedDiffName.getDeploymentFlavorCompositionData(); deploymentFlavor.setModel(DF1_ID + "Name"); expectedDiffName.setDeploymentFlavorCompositionData(deploymentFlavor); - List<DeploymentFlavorEntity> list = new ArrayList<DeploymentFlavorEntity>(); + List<DeploymentFlavorEntity> list = new ArrayList<>(); list.add(expectedDiffName); doReturn(list).when(deploymentFlavorDaoMock).list(anyObject()); try { - deploymentFlavorManager.createDeploymentFlavor(expected, USER); + deploymentFlavorManager.createDeploymentFlavor(expected); Assert.fail(); - } - catch (CoreException ex) { - log.debug("",ex); - Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED, + } catch (CoreException ex) { + Assert.assertEquals( + VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED, ex.code().id()); } } @@ -129,7 +121,7 @@ public class DeploymentFlavorManagerImplTest { doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); - List<String> featureGrps = new ArrayList<String>(); + List<String> featureGrps = new ArrayList<>(); featureGrps.add("fg1"); featureGrps.add("fg2"); @@ -139,11 +131,9 @@ public class DeploymentFlavorManagerImplTest { try { - deploymentFlavorManager.createDeploymentFlavor(expected, USER); + deploymentFlavorManager.createDeploymentFlavor(expected); Assert.fail(); - } - catch (CoreException ex) { - log.debug("",ex); + } catch (CoreException ex) { Assert.assertEquals(VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP, ex.code().id()); } @@ -151,13 +141,13 @@ public class DeploymentFlavorManagerImplTest { @Test public void testCreateManualDepFlavorWithNullCompInAssociation() { - DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + 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<ComponentComputeAssociation> list = new ArrayList<>(); list.add(association); deploymentFlavor.setComponentComputeAssociations(list); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); @@ -168,26 +158,25 @@ public class DeploymentFlavorManagerImplTest { doReturn(vspDetails).when(vspInfoDao).get(anyObject()); try { - deploymentFlavorManager.createDeploymentFlavor(expected, USER); - } - catch (CoreException ex) { - log.debug("",ex); + deploymentFlavorManager.createDeploymentFlavor(expected); + } 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", + 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); + 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<ComponentComputeAssociation> list = new ArrayList<>(); list.add(association); deploymentFlavor.setComponentComputeAssociations(list); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); @@ -197,16 +186,14 @@ public class DeploymentFlavorManagerImplTest { VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); doReturn(vspDetails).when(vspInfoDao).get(anyObject()); - ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, USER); + ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null); doReturn(component).when(componentDaoMock).get(anyObject()); doReturn(null).when(computeDaoMock).get(anyObject()); try { - deploymentFlavorManager.createDeploymentFlavor(expected, USER); - } - catch (CoreException ex) { - log.debug("",ex); + deploymentFlavorManager.createDeploymentFlavor(expected); + } catch (CoreException ex) { Assert.assertEquals(VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID, ex.code().id()); } @@ -214,13 +201,13 @@ public class DeploymentFlavorManagerImplTest { @Test public void testCreateManualDepFlavorWithDuplicateVfcAssociation() { - DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); + 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<ComponentComputeAssociation> list = new ArrayList<>(); list.add(association); list.add(association); deploymentFlavor.setComponentComputeAssociations(list); @@ -231,18 +218,17 @@ public class DeploymentFlavorManagerImplTest { VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); doReturn(vspDetails).when(vspInfoDao).get(anyObject()); - ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, USER); + ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null); 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) { - log.debug("",ex); - Assert.assertEquals(VendorSoftwareProductErrorCodes.SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED, + deploymentFlavorManager.createDeploymentFlavor(expected); + } catch (CoreException ex) { + Assert.assertEquals( + VendorSoftwareProductErrorCodes.SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED, ex.code().id()); } } @@ -251,30 +237,30 @@ public class DeploymentFlavorManagerImplTest { public void testList() { doReturn(Arrays.asList( - createDeploymentFlavor(VSP_ID, VERSION, DF1_ID), - createDeploymentFlavor(VSP_ID, VERSION, DF2_ID))) + 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); + deploymentFlavorManager.listDeploymentFlavors(VSP_ID, VERSION); 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" ); + , DF1_ID.equals(deploymentFlavorEntity.getId()) ? DF1_ID + "name" : DF2_ID + "name"); } } @Test public void testUpdateHeatDepFlavor() { - testUpdate_negative(VSP_ID, VERSION, DF1_ID, USER, + testUpdate_negative(VSP_ID, VERSION, DF1_ID, 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, + testUpdate_negative(VSP_ID, VERSION, DF1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -292,21 +278,22 @@ public class DeploymentFlavorManagerImplTest { VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); doReturn(vspDetails).when(vspInfoDao).get(anyObject()); - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(VSP_ID, VERSION, DF1_ID); + 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); + deploymentFlavorManager.updateDeploymentFlavor(deploymentFlavorEntity); 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, + testGet_negative(VSP_ID, VERSION, "non existing image id", VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -320,25 +307,27 @@ public class DeploymentFlavorManagerImplTest { doReturn(vspDetails).when(vspInfoDao).get(anyObject()); CompositionEntityResponse<DeploymentFlavor> response = - deploymentFlavorManager.getDeploymentFlavor(VSP_ID, VERSION, DF1_ID, USER); + deploymentFlavorManager.getDeploymentFlavor(VSP_ID, VERSION, DF1_ID); Assert.assertEquals(response.getId(), expected.getId()); - Assert.assertEquals(response.getData().getModel(), expected.getDeploymentFlavorCompositionData(). - getModel()); - Assert.assertEquals(response.getData().getDescription(), expected.getDeploymentFlavorCompositionData(). - getDescription()); + 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, + testDelete_negative(VSP_ID, VERSION, DF1_ID, VendorSoftwareProductErrorCodes.DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @Test public void testDeleteOnNotExistImage() { - testDelete_negative(VSP_ID, VERSION, DF1_ID, USER, + testDelete_negative(VSP_ID, VERSION, DF1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -347,48 +336,35 @@ public class DeploymentFlavorManagerImplTest { 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); + deploymentFlavorManager.deleteDeploymentFlavor(VSP_ID, VERSION, DF1_ID); 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) { - log.debug("",exception); - Assert.assertEquals(exception.code().id(), expectedErrorCode); - Assert.assertEquals(exception.getMessage(), expectedErrorMsg); - } - } - - private void testCreate_negative(DeploymentFlavorEntity deploymentFlavorEntity, String user, String - expectedErrorCode) { + private void testCreate_negative(DeploymentFlavorEntity deploymentFlavorEntity, + String expectedErrorCode) { try { - deploymentFlavorManager.createDeploymentFlavor(deploymentFlavorEntity, user); + deploymentFlavorManager.createDeploymentFlavor(deploymentFlavorEntity); Assert.fail(); } catch (CoreException exception) { - log.debug("",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); + deploymentFlavorManager.deleteDeploymentFlavor(vspId, version, deploymentFlavorId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - static DeploymentFlavorEntity createDeploymentFlavor(String vspId, Version version, String deploymentFlavorId) { + private static DeploymentFlavorEntity createDeploymentFlavor(String vspId, Version version, + String deploymentFlavorId) { - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); deploymentFlavor.setModel(deploymentFlavorId + "name"); deploymentFlavor.setDescription(deploymentFlavorId + " desc"); @@ -397,29 +373,28 @@ public class DeploymentFlavorManagerImplTest { return deploymentFlavorEntity; } - private void testUpdate_negative(String vspId, Version version, String - deploymentFlavorId, String user, String expectedErrorCode) { + private void testUpdate_negative(String vspId, Version version, String deploymentFlavorId, + String expectedErrorCode) { try { - DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); + DeploymentFlavorEntity deploymentFlavorEntity = + new DeploymentFlavorEntity(vspId, version, deploymentFlavorId); DeploymentFlavor deploymentFlavor = new DeploymentFlavor(); deploymentFlavor.setModel("Name"); deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor); deploymentFlavorManager - .updateDeploymentFlavor(deploymentFlavorEntity, user); + .updateDeploymentFlavor(new DeploymentFlavorEntity(vspId, version, deploymentFlavorId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } private void testGet_negative(String vspId, Version version, String deploymentFlavorId, - String user, String expectedErrorCode) { + String expectedErrorCode) { try { - deploymentFlavorManager.getDeploymentFlavor(vspId, version, deploymentFlavorId, user); + deploymentFlavorManager.getDeploymentFlavor(vspId, version, deploymentFlavorId); Assert.fail(); } catch (CoreException exception) { - log.debug("",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 index 9f932b9fdf..d9b4188f5e 100644 --- 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 @@ -1,18 +1,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -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 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.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; @@ -29,21 +22,20 @@ 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 ImageManagerImplTest { +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); +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"; + "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"; @@ -68,7 +60,7 @@ public class ImageManagerImplTest { @Test public void testListWhenNone() { final Collection<ImageEntity> imageEntities = - imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(imageEntities.size(), 0); } @@ -76,32 +68,32 @@ public class ImageManagerImplTest { 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()); + 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); + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID); 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" ); + 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); + testCreate_negative(new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, null), + 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); + imageManager.createImage(expected); verify(compositionEntityDataManagerMock).createImage(expected); verify(compositionEntityDataManagerMock).createImage(expected); } @@ -115,14 +107,13 @@ public class ImageManagerImplTest { Image image = expectedDiffName.getImageCompositionData(); image.setFileName(IMAGE1_ID + "_Name"); expectedDiffName.setImageCompositionData(image); - List<ImageEntity> vfcImageList = new ArrayList<ImageEntity>(); + List<ImageEntity> vfcImageList = new ArrayList<>(); vfcImageList.add(expectedDiffName); doReturn(vfcImageList).when(imageDao).list(anyObject()); try { - imageManager.createImage(expected, USER); + imageManager.createImage(expected); Assert.fail(); - } - catch (CoreException ex) { + } catch (CoreException ex) { Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_NAME_NOT_ALLOWED, ex.code().id()); } @@ -130,18 +121,18 @@ public class ImageManagerImplTest { @Test public void testUpdateNonExistingImageId_negative() { - testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, - VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test public void testUpdateImage() { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .when(imageDao).get(anyObject()); doReturn(new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID)) - .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -150,7 +141,7 @@ public class ImageManagerImplTest { imageEntity.setImageCompositionData(imageData); CompositionEntityValidationData validationData = - imageManager.updateImage(imageEntity, USER); + imageManager.updateImage(imageEntity); Assert.assertTrue(validationData == null || validationData.getErrors() == null); verify(imageDao).update(imageEntity); } @@ -158,16 +149,16 @@ public class ImageManagerImplTest { @Test public void testIllegalImageUpdate() { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .when(imageDao).get(anyObject()); doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); CompositionEntityValidationData toBeReturned = - new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); + new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) - .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -175,7 +166,7 @@ public class ImageManagerImplTest { imageData.setDescription(IMAGE1_ID + " desc updated"); imageEntity.setImageCompositionData(imageData); - CompositionEntityValidationData validationData = imageManager.updateImage(imageEntity, USER); + CompositionEntityValidationData validationData = imageManager.updateImage(imageEntity); Assert.assertNotNull(validationData); Assert.assertEquals(validationData.getErrors().size(), 2); @@ -185,7 +176,7 @@ public class ImageManagerImplTest { @Test public void testUpdateHEATImageFileName() throws Exception { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .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"); @@ -193,10 +184,8 @@ public class ImageManagerImplTest { imageEntity.setImageCompositionData(imageData); try { - imageManager.updateImage(imageEntity, USER); - } - catch (CoreException ex) { - log.debug("",ex); + imageManager.updateImage(imageEntity); + } catch (CoreException ex) { Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED); } @@ -204,8 +193,8 @@ public class ImageManagerImplTest { @Test public void testGetNonExistingImageId_negative() { - testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing image id", USER, - VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing image id", + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test @@ -216,12 +205,12 @@ public class ImageManagerImplTest { doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(anyObject()); CompositionEntityResponse<Image> response = - imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Assert.assertEquals(response.getId(), expected.getId()); Assert.assertEquals(response.getData().getFileName(), expected.getImageCompositionData(). - getFileName()); + getFileName()); Assert.assertEquals(response.getData().getDescription(), expected.getImageCompositionData(). - getDescription()); + getDescription()); Assert.assertEquals(response.getSchema(), compositionSchema); } @@ -229,14 +218,14 @@ public class ImageManagerImplTest { 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); + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, + 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); + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test @@ -244,7 +233,7 @@ public class ImageManagerImplTest { 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); + imageManager.deleteImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); verify(imageDao).delete(anyObject()); } @@ -258,7 +247,7 @@ public class ImageManagerImplTest { doReturn(schema).when(imageManager).getImageQuestionnaireSchema(anyObject()); QuestionnaireResponse questionnaire = - imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Assert.assertNotNull(questionnaire); Assert.assertEquals(questionnaire.getData(), image.getQuestionnaireData()); Assert.assertEquals(questionnaire.getSchema(), schema); @@ -270,7 +259,8 @@ public class ImageManagerImplTest { 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); + + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); verify(imageDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); } @@ -291,10 +281,9 @@ public class ImageManagerImplTest { doReturn(imageEntities).when(imageDao).list(anyObject()); doReturn(imageEntities.get(0)).when(imageDao).getQuestionnaireData(anyObject(), anyObject(), anyObject(), anyObject()); - imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json, USER); + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_VERSION_NOT_ALLOWED); } @@ -316,12 +305,9 @@ public class ImageManagerImplTest { String updJson = "{\"format\" :\"aki\"}"; try { - imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson, - USER); + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson); Assert.fail(); - } - catch(CoreException ex) { - log.debug("",ex); + } catch (CoreException ex) { Assert.assertEquals(ex.code().id(), VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED); } } @@ -337,51 +323,34 @@ public class ImageManagerImplTest { String updJson = "{\"format\" :\"a22\"}"; try { - imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson, - USER); + imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson); Assert.fail(); - } - catch(CoreException ex) { - log.debug("",ex); + } 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) { - log.debug("",exception); - Assert.assertEquals(exception.code().id(), expectedErrorCode); - Assert.assertEquals(exception.getMessage(), expectedErrorMsg); - } - } - - private void testCreate_negative(ImageEntity image, String user, String expectedErrorCode) { + private void testCreate_negative(ImageEntity image, String expectedErrorCode) { try { - imageManager.createImage(image, user); + imageManager.createImage(image); Assert.fail(); } catch (CoreException exception) { - log.debug("",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); + imageManager.deleteImage(vspId, version, componentId, nicId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - static ImageEntity createImage(String vspId, Version version, String compId, String imageId) { + private 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"); @@ -390,21 +359,20 @@ public class ImageManagerImplTest { return imageEntity; } - private void testUpdate_negative(String vspId, Version version, String componentId, String - imageId, String user, String expectedErrorCode) { + private void testUpdate_negative(String vspId, Version version, String componentId, + String imageId, String expectedErrorCode) { try { - imageManager.updateImage(new ImageEntity(vspId, version, componentId, imageId), user); + imageManager.updateImage(new ImageEntity(vspId, version, componentId, imageId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } private void testGet_negative(String vspId, Version version, String componentId, String imageId, - String user, String expectedErrorCode) { + String expectedErrorCode) { try { - imageManager.getImage(vspId, version, componentId, imageId, user); + imageManager.getImage(vspId, version, componentId, imageId); 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 index ecfe0e6372..2360dc7398 100644 --- 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 @@ -1,57 +1,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.openecomp.sdc.generator.util.GeneratorConstants.ALLOWED_FLAVORS_PROPERTY; -import static org.openecomp.sdc.generator.util.GeneratorConstants.IMAGES_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.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.Spy; -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 org.openecomp.sdc.vendorsoftwareproduct.services.ManualVspDataCollectionService; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; public class ManualVspToscaManagerImplTest { @@ -96,36 +49,27 @@ public class ManualVspToscaManagerImplTest { private ManualVspDataCollectionService manualVspDataCollectionServiceMock; /* - private static List<String> supportedCapabilities = new ArrayList<>(); - private static List<String> supportedRequirements = new ArrayList<>(); - - static { - //TODO : Read from configuration - supportedCapabilities.addAll(Arrays.asList("host", "os", "endpoint", "scalable")); - supportedRequirements.addAll(Arrays.asList("link")); - } - @Test public void testGatherVspInformationInvalidVsp() { MockitoAnnotations.initMocks(this); VspModelInfo expectedVspData = new VspModelInfo(); doThrow(new RuntimeException()) .when(manualVspDataCollectionServiceMock) - .getReleaseVendor(INVALID_VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getReleaseVendor(INVALID_VSP_ID, Version.valueOf(VSP_VERSION)); doThrow(new RuntimeException()) .when(manualVspDataCollectionServiceMock) - .getAllowedFlavors(INVALID_VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getAllowedFlavors(INVALID_VSP_ID, Version.valueOf(VSP_VERSION)); doThrow(new RuntimeException()) .when(manualVspDataCollectionServiceMock) - .getVspComponentImages(INVALID_VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponentImages(INVALID_VSP_ID, Version.valueOf(VSP_VERSION)); doThrow(new RuntimeException()) .when(manualVspDataCollectionServiceMock) - .getVspComponents(INVALID_VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponents(INVALID_VSP_ID, Version.valueOf(VSP_VERSION)); doThrow(new RuntimeException()) .when(manualVspDataCollectionServiceMock) - .getVspComponentNics(INVALID_VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponentNics(INVALID_VSP_ID, Version.valueOf(VSP_VERSION)); VspModelInfo vspModelInfo = manualVspToscaManagerMock.gatherVspInformation(INVALID_VSP_ID, - Version.valueOf(VSP_VERSION), USER); + Version.valueOf(VSP_VERSION)); Assert.assertEquals(expectedVspData, vspModelInfo); } @@ -138,17 +82,17 @@ public class ManualVspToscaManagerImplTest { Map<String, String> componentData = getComponentData(); Map<String, List<MultiFlavorVfcImage>> vfcImageData = getVfcImageData(); doReturn(Optional.of(RELEASE_VENDOR)).when(manualVspDataCollectionServiceMock) - .getReleaseVendor(VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getReleaseVendor(VSP_ID, Version.valueOf(VSP_VERSION)); doReturn(deploymentFlavorData).when(manualVspDataCollectionServiceMock) - .getAllowedFlavors(VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getAllowedFlavors(VSP_ID, Version.valueOf(VSP_VERSION)); doReturn(vfcImageData).when(manualVspDataCollectionServiceMock) - .getVspComponentImages(VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponentImages(VSP_ID, Version.valueOf(VSP_VERSION)); doReturn(componentData).when(manualVspDataCollectionServiceMock) - .getVspComponents(VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponents(VSP_ID, Version.valueOf(VSP_VERSION)); doReturn(componentNics).when(manualVspDataCollectionServiceMock) - .getVspComponentNics(VSP_ID, Version.valueOf(VSP_VERSION), USER); + .getVspComponentNics(VSP_ID, Version.valueOf(VSP_VERSION)); VspModelInfo vspModelInfo = manualVspToscaManagerMock.gatherVspInformation(VSP_ID, - Version.valueOf(VSP_VERSION), USER); + Version.valueOf(VSP_VERSION)); VspModelInfo expectedVspData = new VspModelInfo(); expectedVspData.setReleaseVendor(RELEASE_VENDOR); @@ -449,9 +393,9 @@ public class ManualVspToscaManagerImplTest { private void validateSubstitutionCapabilities(Map<String, List<String>> capabilities, String componentName) { - List<String> SupportedCapabilities = supportedCapabilities; - Assert.assertEquals(SupportedCapabilities.size(), capabilities.size()); - for (String capability : SupportedCapabilities) { + 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); @@ -464,10 +408,10 @@ public class ManualVspToscaManagerImplTest { private void validateSubstitutionRequirements(Map<String, List<String>> requirements, List<Nic> nics) { - List<String> SupportedRequirements = supportedRequirements; + List<String> supportedRequirements = GeneratorUtils.supportedRequirements; for(Nic nic : nics) { String nicNodeTemplateId = nic.getName() + PORT_NODE_TEMPLATE_ID_SUFFIX; - for (String requirement : SupportedRequirements) { + for (String requirement : supportedRequirements) { String expectedRequirementId = requirement + "_" + nicNodeTemplateId; Assert.assertEquals(true, requirements.containsKey(expectedRequirementId)); List<String> expectedRequirementValue = new ArrayList<>(2); @@ -508,11 +452,11 @@ public class ManualVspToscaManagerImplTest { List<Map<String, RequirementDefinition>> requirements = deploymentFlavorNodeType.getRequirements(); - List<String> SupportedRequirements = supportedRequirements; + 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) { + for (String requirementId : supportedRequirements) { String expectedRequirementId = requirementId + "_" + nicNodeTemplateId; for (Map<String, RequirementDefinition> requirement : requirements) { if (requirement.containsKey(expectedRequirementId)) { @@ -525,8 +469,8 @@ public class ManualVspToscaManagerImplTest { } Map<String, CapabilityDefinition> capabilities = deploymentFlavorNodeType.getCapabilities(); - List<String> SupportedCapabilities = supportedCapabilities; - for (String capabilityId : SupportedCapabilities) { + List<String> supportedCapabilities = GeneratorUtils.supportedCapabilities; + for (String capabilityId : supportedCapabilities) { String expectedCapabilityId = capabilityId + "_" + componentName; Assert.assertEquals (true, capabilities.containsKey(expectedCapabilityId)); } 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 index 966e1f20bf..5e735ff74e 100644 --- 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 @@ -28,10 +28,9 @@ 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 Version VERSION = new Version("version_id"); private static final String TRAP_FILE_NAME = "MMSC.zip"; private static final String POLL_FILE_NAME = "MNS OAM FW.zip"; private static final String VES_FILE_NAME = "vesTest-yml_only.zip"; @@ -54,22 +53,19 @@ public class MonitoringUploadsManagerImplTest { @Test(expectedExceptions = CoreException.class) public void testUploadEmptyZip() { processFile(ZIP_DIR + EMPTY_ZIP_FILE_NAME, inputStream -> - monitoringUploadsManager.upload(inputStream, EMPTY_ZIP_FILE_NAME, VSP_ID, VERSION, COMPONENT_ID, - MonitoringUploadType.SNMP_TRAP, USER1)); + monitoringUploadsManager + .upload(inputStream, EMPTY_ZIP_FILE_NAME, VSP_ID, VERSION, COMPONENT_ID, + MonitoringUploadType.SNMP_TRAP)); } - @Test + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = + "Monitoring file uploaded for vendor software product with Id vspId and version version_id " + + "is invalid: Invalid zip file") public void testUploadInvalidZip() { - - try { - processFile("/notZipFile", inputStream -> + processFile("/notZipFile", inputStream -> monitoringUploadsManager .upload(inputStream, NOT_ZIP_FILE_NAME, VSP_ID, VERSION, COMPONENT_ID, - MonitoringUploadType.VES_EVENTS, USER1)); - Assert.fail(); - } catch (Exception exception) { - Assert.assertEquals(exception.getMessage(), "Invalid zip file"); - } + MonitoringUploadType.VES_EVENTS)); } @Test @@ -78,7 +74,7 @@ public class MonitoringUploadsManagerImplTest { try { processFile(ZIP_DIR + ZIP_WITH_FOLDERS_FILE_NAME, inputStream -> monitoringUploadsManager .upload(inputStream, ZIP_WITH_FOLDERS_FILE_NAME, VSP_ID, VERSION, COMPONENT_ID, - MonitoringUploadType.SNMP_TRAP, USER1)); + MonitoringUploadType.SNMP_TRAP)); Assert.fail(); } catch (Exception exception) { Assert.assertEquals(exception.getMessage(), "Zip file should not contain folders"); @@ -91,7 +87,7 @@ public class MonitoringUploadsManagerImplTest { try { processFile(ZIP_DIR + INVALID_VES_FILE_NAME, inputStream -> monitoringUploadsManager .upload(inputStream, INVALID_VES_FILE_NAME, VSP_ID, VERSION, COMPONENT_ID, - MonitoringUploadType.VES_EVENTS, USER1)); + MonitoringUploadType.VES_EVENTS)); Assert.fail(); } catch (Exception exception) { Assert.assertEquals(exception.getMessage(), @@ -122,18 +118,18 @@ public class MonitoringUploadsManagerImplTest { .when(componentArtifactDaoMock).list(anyObject()); MonitoringUploadStatus monitoringUploadStatus = - monitoringUploadsManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID, USER1); + monitoringUploadsManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(monitoringUploadStatus.getSnmpTrap(), TRAP_FILE_NAME); Assert.assertEquals(monitoringUploadStatus.getSnmpPoll(), POLL_FILE_NAME); Assert.assertEquals(monitoringUploadStatus.getVesEvent(), VES_FILE_NAME); } - @Test (expectedExceptions = CoreException.class) + @Test(expectedExceptions = CoreException.class) public void testDeleteComponentMibWhenNone() { doReturn(Optional.empty()).when(componentArtifactDaoMock).getByType(any()); monitoringUploadsManager - .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL, USER1); + .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL); verify(componentArtifactDaoMock, never()).delete(anyObject()); } @@ -146,7 +142,7 @@ public class MonitoringUploadsManagerImplTest { (componentArtifactDaoMock).getByType(anyObject()); monitoringUploadsManager - .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL, USER1); + .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL); verify(componentArtifactDaoMock).delete(anyObject()); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java index ebdbc6af7d..54687dc80d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NetworkManagerImplTest.java @@ -53,10 +53,8 @@ public class NetworkManagerImplTest { private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); - private static final String USER1 = "networksTestUser1"; - private static final String USER2 = "networksTestUser2"; private static final String VSP_ID = "vsp"; - private static final Version VERSION = new Version(0, 1); + private static final Version VERSION = new Version("version_id"); private static final String NETWORK1_ID = "network1"; private static final String NETWORK2_ID = "network2"; @@ -85,7 +83,7 @@ public class NetworkManagerImplTest { @Test public void testListWhenNone() { Collection<NetworkEntity> networks = - networkManager.listNetworks(VSP_ID, null, USER1); + networkManager.listNetworks(VSP_ID, null); Assert.assertEquals(networks.size(), 0); } @@ -96,7 +94,7 @@ public class NetworkManagerImplTest { createNetwork(VSP_ID, VERSION, NETWORK2_ID))) .when(networkDaoMock).list(anyObject()); - Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, VERSION, USER1); + Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, VERSION); Assert.assertEquals(actual.size(), 2); } @@ -113,7 +111,7 @@ public class NetworkManagerImplTest { expected.setNetworkCompositionData(networkData); - NetworkEntity created = networkManager.createNetwork(expected, USER1); + NetworkEntity created = networkManager.createNetwork(expected); Assert.assertNotNull(created); expected.setId(created.getId()); expected.setVersion(VERSION01); @@ -131,12 +129,12 @@ public class NetworkManagerImplTest { networkData.setName("network1 name"); networkData.setDhcp(true); network.setNetworkCompositionData(networkData); - testCreate_negative(network, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + testCreate_negative(network, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); }*/ @Test public void testCreateOnUploadVsp_negative() { - testCreate_negative(new NetworkEntity(VSP_ID, VERSION, null), USER1, + testCreate_negative(new NetworkEntity(VSP_ID, VERSION, null), VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } @@ -148,7 +146,7 @@ public class NetworkManagerImplTest { @Test public void testUpdateNonExistingNetworkId_negative() { - testUpdate_negative(VSP_ID, VERSION, NETWORK1_ID, USER1, + testUpdate_negative(VSP_ID, VERSION, NETWORK1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -171,7 +169,7 @@ public class NetworkManagerImplTest { networkEntity.setNetworkCompositionData(networkData); CompositionEntityValidationData validationData = - networkManager.updateNetwork(networkEntity, USER1); + networkManager.updateNetwork(networkEntity); Assert.assertNotNull(validationData); Assert.assertEquals(validationData.getErrors().size(), 2); @@ -180,7 +178,7 @@ public class NetworkManagerImplTest { @Test public void testGetNonExistingNetworkId_negative() { - testGet_negative(VSP_ID, VERSION, NETWORK1_ID, USER1, + testGet_negative(VSP_ID, VERSION, NETWORK1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -192,7 +190,7 @@ public class NetworkManagerImplTest { doReturn("schema string").when(networkManager).getCompositionSchema(anyObject()); CompositionEntityResponse<Network> response = - networkManager.getNetwork(VSP_ID, VERSION, NETWORK1_ID, USER1); + networkManager.getNetwork(VSP_ID, VERSION, NETWORK1_ID); Assert.assertEquals(response.getId(), network.getId()); Assert.assertEquals(response.getData(), network.getNetworkCompositionData()); Assert.assertNotNull(response.getSchema()); @@ -206,13 +204,13 @@ public class NetworkManagerImplTest { @Test(dependsOnMethods = "testList") public void testDeleteNonExistingNetworkId_negative() { - testDelete_negative(VSP_ID, "non existing network id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + testDelete_negative(VSP_ID, "non existing network id", VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); }*/ /* @Test(dependsOnMethods = "testList") public void testDelete() { - networkManager.deleteNetwork(VSP_ID, NETWORK1_ID, USER1); + networkManager.deleteNetwork(VSP_ID, NETWORK1_ID); NetworkEntity actual = networkDaoMock.getNetwork(VSP_ID, VERSION01, NETWORK1_ID); Assert.assertNull(actual); } @@ -224,70 +222,69 @@ public class NetworkManagerImplTest { NetworkEntity network3 = new NetworkEntity(VSP_ID, null, null); network3.setName("network3 name"); network3.setDescription("network3 desc"); - networkManager.createNetwork(network3, USER1); + networkManager.createNetwork(network3); - networkManager.deleteNetworks(VSP_ID, USER1); + networkManager.deleteNetworks(VSP_ID); - Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, null, USER1); + Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, null); Assert.assertEquals(actual.size(), 0); }*/ @Test(dependsOnMethods = "testList") public void testDeleteOnUploadVsp_negative() { - testDelete_negative(VSP_ID, VERSION, NETWORK1_ID, USER1, + testDelete_negative(VSP_ID, VERSION, NETWORK1_ID, VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } - private void testCreate_negative(NetworkEntity network, String user, String expectedErrorCode) { + private void testCreate_negative(NetworkEntity network, String expectedErrorCode) { try { - networkManager.createNetwork(network, user); + networkManager.createNetwork(network); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testGet_negative(String vspId, Version version, String networkId, String user, + private void testGet_negative(String vspId, Version version, String networkId, String expectedErrorCode) { try { - networkManager.getNetwork(vspId, version, networkId, user); + networkManager.getNetwork(vspId, version, networkId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testUpdate_negative(String vspId, Version version, String networkId, String user, + private void testUpdate_negative(String vspId, Version version, String networkId, String expectedErrorCode) { try { - networkManager.updateNetwork(new NetworkEntity(vspId, version, networkId), user); + networkManager.updateNetwork(new NetworkEntity(vspId, version, networkId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testList_negative(String vspId, Version version, String user, - String expectedErrorCode) { + private void testList_negative(String vspId, Version version, String expectedErrorCode) { try { - networkManager.listNetworks(vspId, version, user); + networkManager.listNetworks(vspId, version); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } - private void testDelete_negative(String vspId, Version version, String networkId, String user, + private void testDelete_negative(String vspId, Version version, String networkId, String expectedErrorCode) { try { - networkManager.deleteNetwork(vspId, version, networkId, user); + networkManager.deleteNetwork(vspId, version, networkId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", 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/NicManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/NicManagerImplTest.java index ba04e91c63..959b501c19 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 @@ -1,10 +1,5 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -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 org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -35,17 +30,21 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +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 NicManagerImplTest { private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); private static final String NIC_NOT_EXIST_MSG = "Vendor Software Product NIC with Id nic1 does not exist for Vendor Software Product with " + - "id VSP_ID and version 0.1"; + "id VSP_ID and version version_id"; - private static final String USER = "nicTestUser"; private static final String VSP_ID = "VSP_ID"; - private static final Version VERSION = new Version(0, 1); + private static final Version VERSION = new Version("version_id"); private static final String COMPONENT_ID = "COMPONENT_ID"; private static final String NIC1_ID = "nic1"; private static final String NIC2_ID = "nic2"; @@ -71,7 +70,7 @@ public class NicManagerImplTest { @Test public void testListWhenNone() { - Collection<NicEntity> nics = nicManager.listNics(VSP_ID, VERSION, COMPONENT_ID, USER); + Collection<NicEntity> nics = nicManager.listNics(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(nics.size(), 0); } @@ -85,9 +84,9 @@ public class NicManagerImplTest { NetworkEntity network1 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK1_ID); NetworkEntity network2 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK2_ID); doReturn(Arrays.asList(network1, network2)) - .when(networkManagerMock).listNetworks(VSP_ID, VERSION, USER); + .when(networkManagerMock).listNetworks(VSP_ID, VERSION); - Collection<NicEntity> nics = nicManager.listNics(VSP_ID, VERSION, COMPONENT_ID, USER); + Collection<NicEntity> nics = nicManager.listNics(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(nics.size(), 2); for (NicEntity nic : nics) { Assert.assertEquals(nic.getNicCompositionData().getNetworkName(), @@ -103,12 +102,12 @@ public class NicManagerImplTest { Nic nic = nicEntity.getNicCompositionData(); nic.setNetworkType(NetworkType.Internal); nicEntity.setNicCompositionData(nic); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + 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); + NicEntity created = nicManager.createNic(nicEntity); Assert.assertNotNull(created); } @@ -118,7 +117,7 @@ public class NicManagerImplTest { Nic nic = nicEntity.getNicCompositionData(); nic.setNetworkType(NetworkType.Internal); nicEntity.setNicCompositionData(nic); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); Collection<NicEntity> nicEntities = new ArrayList<>(); NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); @@ -130,11 +129,11 @@ public class NicManagerImplTest { doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); try { - NicEntity created = nicManager.createNic(nicEntity,USER); - } catch (CoreException exception) { - log.debug("",exception); - Assert.assertEquals(VendorSoftwareProductErrorCodes.NIC_NAME_FORMAT_NOT_ALLOWED, - exception.code().id()); + NicEntity created = nicManager.createNic(nicEntity); + } catch (CoreException exception) { + log.debug("", exception); + Assert.assertEquals(VendorSoftwareProductErrorCodes.NIC_NAME_FORMAT_NOT_ALLOWED, + exception.code().id()); } } @@ -144,7 +143,7 @@ public class NicManagerImplTest { Nic nic = nicEntity.getNicCompositionData(); nic.setNetworkType(NetworkType.Internal); nicEntity.setNicCompositionData(nic); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); Collection<NicEntity> nicEntities = new ArrayList<>(); NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); @@ -156,11 +155,11 @@ public class NicManagerImplTest { doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); try { - NicEntity created = nicManager.createNic(nicEntity,USER); - } catch (CoreException exception) { - log.debug("",exception); - Assert.assertEquals("Invalid request, NIC with name "+ nic.getName() + - " already exist for component with ID "+ nicEntity.getComponentId() +".", + NicEntity created = nicManager.createNic(nicEntity); + } catch (CoreException exception) { + log.debug("", 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()); @@ -173,19 +172,20 @@ public class NicManagerImplTest { Nic nic = nicEntity.getNicCompositionData(); nic.setNetworkType(NetworkType.External); nicEntity.setNicCompositionData(nic); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + 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) { - log.debug("",exception); + NicEntity created = nicManager.createNic(nicEntity); + } catch (CoreException exception) { + log.debug("", 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()); + Assert + .assertEquals(VendorSoftwareProductErrorCodes.NETWORKID_NOT_ALLOWED_FOR_EXTERNAL_NETWORK, + exception.code().id()); } } @@ -196,29 +196,29 @@ public class NicManagerImplTest { nic.setNetworkType(NetworkType.Internal); nic.setNetworkDescription(NIC1_ID); nicEntity.setNicCompositionData(nic); - doReturn(true).when(vspInfoDao).isManual(anyObject(),anyObject()); + 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) { - log.debug("",exception); + NicEntity created = nicManager.createNic(nicEntity); + } catch (CoreException exception) { + log.debug("", 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()); + .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(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); + nicManager.deleteNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); } @@ -227,9 +227,12 @@ public class NicManagerImplTest { NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); doReturn(nicEntity).when(nicDao).get(anyObject()); + doReturn("{}").when(nicManager).getNicCompositionSchema(anyObject()); - nicManager.updateNicQuestionnaire(VSP_ID,new Version(0,1),COMPONENT_ID,NIC1_ID,"Ques",USER); + nicManager + .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "Ques"); + verify(nicDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "Ques"); } // @Test(dependsOnMethods = "testListWhenNone") @@ -243,7 +246,7 @@ public class NicManagerImplTest { Nic nicData = new Nic(); nicData.setName("nic1 name"); nic.setNicCompositionData(nicData); - testCreate_negative(nic, USER, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); + testCreate_negative(nic, UniqueValueUtil.UNIQUE_VALUE_VIOLATION); }*/ // @Test(dependsOnMethods = {"testCreate"}) @@ -254,7 +257,7 @@ public class NicManagerImplTest { // compData12.setDescription("comp12 desc"); // component12.setComponentCompositionData(compData12); // -// String component12Id = nicManager.createComponent(component12, USER).getId(); +// String component12Id = nicManager.createComponent(component12).getId(); // testCreate(VSP_ID, component12Id, NETWORK1_ID, NETWORK1_ID.getNetworkCompositionData().getName()); // } @@ -266,7 +269,7 @@ public class NicManagerImplTest { @Test public void testCreateOnUploadVsp_negative() { - testCreate_negative(new NicEntity(VSP_ID, VERSION, COMPONENT_ID, null), USER, + testCreate_negative(new NicEntity(VSP_ID, VERSION, COMPONENT_ID, null), VendorSoftwareProductErrorCodes.ADD_NIC_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @@ -274,7 +277,7 @@ public class NicManagerImplTest { public void testUpdateNonExistingNicId_negative() { doReturn(null).when(nicDao).get(anyObject()); - testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER, + testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -295,7 +298,7 @@ public class NicManagerImplTest { nicEntity.setNicCompositionData(nicData); CompositionEntityValidationData validationData = - nicManager.updateNic(nicEntity, USER); + nicManager.updateNic(nicEntity); Assert.assertTrue(validationData == null || validationData.getErrors() == null); verify(nicDao).update(nicEntity); } @@ -319,7 +322,7 @@ public class NicManagerImplTest { nicData.setNetworkId(NETWORK1_ID); nicEntity.setNicCompositionData(nicData); - CompositionEntityValidationData validationData = nicManager.updateNic(nicEntity, USER); + CompositionEntityValidationData validationData = nicManager.updateNic(nicEntity); Assert.assertNotNull(validationData); Assert.assertEquals(validationData.getErrors().size(), 2); @@ -329,14 +332,14 @@ public class NicManagerImplTest { @Test public void testUpdateIncorrectNameFormat() { doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID)) - .when(nicDao).get(anyObject()); + .when(nicDao).get(anyObject()); CompositionEntityValidationData toBeReturned = - new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID); + new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) - .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); @@ -347,20 +350,19 @@ public class NicManagerImplTest { nicEntity.setNicCompositionData(nicData); try { - nicManager.updateNic(nicEntity, USER); + nicManager.updateNic(nicEntity); Assert.fail(); - } - catch (CoreException ex) { - log.debug("",ex); + } catch (CoreException ex) { + log.debug("", ex); Assert.assertEquals(VendorSoftwareProductErrorCodes.NIC_NAME_FORMAT_NOT_ALLOWED, - ex.code().id()); + ex.code().id()); } } @Test public void testGetNonExistingNicId_negative() { - testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing nic id", USER, + testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing nic id", VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @@ -373,7 +375,7 @@ public class NicManagerImplTest { doReturn(compositionSchema).when(nicManager).getNicCompositionSchema(anyObject()); CompositionEntityResponse<Nic> response = - nicManager.getNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER); + nicManager.getNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Assert.assertEquals(response.getId(), expected.getId()); Assert.assertEquals(response.getData(), expected.getNicCompositionData()); Assert.assertEquals(response.getSchema(), compositionSchema); @@ -387,32 +389,32 @@ public class NicManagerImplTest { @Test public void testDeleteNonExistingNicId_negative() { - testDelete_negative(VSP_ID, COMPONENT_ID, "non existing nic id", USER, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + testDelete_negative(VSP_ID, COMPONENT_ID, "non existing nic id", VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test(dependsOnMethods = "testList") public void testDeleteNonExistingComponentId_negative() { - testDelete_negative(VSP_ID, "non existing component id", NIC1_ID, USER, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + testDelete_negative(VSP_ID, "non existing component id", NIC1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); }*/ /* @Test(dependsOnMethods = "testList") public void testDelete() { - nicManager.deleteNic(VSP_ID, COMPONENT_ID, NIC1_ID, USER); + nicManager.deleteNic(VSP_ID, COMPONENT_ID, NIC1_ID); NicEntity actual = vendorSoftwareProductDao.getNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Assert.assertNull(actual); }*/ @Test public void testDeleteOnUploadVsp_negative() { - testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER, + testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, VendorSoftwareProductErrorCodes.DELETE_NIC_NOT_ALLOWED); } @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = NIC_NOT_EXIST_MSG) public void testGetNonExistingNicQuestionnaire() throws Exception { - nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER); + nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); } @Test @@ -425,7 +427,7 @@ public class NicManagerImplTest { doReturn(schema).when(nicManager).getNicQuestionnaireSchema(anyObject()); QuestionnaireResponse questionnaire = - nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, USER); + nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Assert.assertNotNull(questionnaire); Assert.assertEquals(questionnaire.getData(), nic.getQuestionnaireData()); Assert.assertEquals(questionnaire.getSchema(), schema); @@ -437,7 +439,7 @@ public class NicManagerImplTest { public void testUpdateNonExistingNicQuestionnaire() throws Exception { doReturn(null).when(nicDao).get(anyObject()); nicManager - .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "questionnaire data", USER); + .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "questionnaire data"); } @Test @@ -445,46 +447,45 @@ public class NicManagerImplTest { } - private void testCreate_negative(NicEntity nic, String user, String expectedErrorCode) { + private void testCreate_negative(NicEntity nic, String expectedErrorCode) { try { - nicManager.createNic(nic, user); + nicManager.createNic(nic); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } private void testGet_negative(String vspId, Version version, String componentId, String nicId, - String user, String expectedErrorCode) { + String expectedErrorCode) { try { - nicManager.getNic(vspId, version, componentId, nicId, user); + nicManager.getNic(vspId, version, componentId, nicId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } private void testUpdate_negative(String vspId, Version version, String componentId, String nicId, - String user, String expectedErrorCode) { + String expectedErrorCode) { try { - nicManager.updateNic(new NicEntity(vspId, version, componentId, nicId), user); + nicManager.updateNic(new NicEntity(vspId, version, componentId, nicId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } private void testDelete_negative(String vspId, Version version, String componentId, String nicId, - String user, String expectedErrorCode) { try { - nicManager.deleteNic(vspId, version, componentId, nicId, user); + nicManager.deleteNic(vspId, version, componentId, nicId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", 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/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java index d1cba65182..26ec917546 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java @@ -1,18 +1,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; - import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; @@ -37,10 +33,13 @@ import java.util.Iterator; import java.util.Map; import java.util.Optional; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; + public class OrchestrationTemplateCandidateManagerImplTest { - private static final String USER1 = "vspTestUser1"; private static final String VSP_ID = "vspId"; - private static final Version VERSION01 = new Version(0, 1); + private static final Version VERSION01 = new Version("versionId"); private static final String COMPONENT_ORIG_ID_1 = "Component_Pd_Server_Id_Orig"; private static final String COMPONENT_ORIG_ID_2 = "Component_Sm_Server_Id_Orig"; @@ -58,8 +57,6 @@ public class OrchestrationTemplateCandidateManagerImplTest { private static final String COMPONENT_NAME_4 = "ps_server"; @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock private VendorSoftwareProductInfoDao vspInfoDaoMock; @Mock private CandidateService candidateServiceMock; @@ -67,6 +64,8 @@ public class OrchestrationTemplateCandidateManagerImplTest { private OrchestrationTemplateDao orchestrationTemplateDaoMock; @Mock private ComponentDependencyModelDao componentDependencyModelDaoMock; + @Mock + private ComponentDao componentDaoMock; @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; @@ -100,7 +99,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn(new VspDetails(VSP_ID, VERSION01)) .when(vspInfoDaoMock).get(anyObject()); doReturn(null) - .when(orchestrationTemplateDaoMock).getValidationData(anyObject(), anyObject()); + .when(orchestrationTemplateDaoMock).getInfo(anyObject(), anyObject()); doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject()); doReturn(Optional.empty()).when(candidateServiceMock) @@ -109,7 +108,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { OrchestrationTemplateActionResponse response = - candidateManager.process(VSP_ID, VERSION01, USER1); + candidateManager.process(VSP_ID, VERSION01); Assert.assertNotNull(response); } @@ -118,12 +117,11 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUpdateVspComponentDependenciesHeatReuploadMoreComponents() { Collection<ComponentDependencyModelEntity> existingComponentsDependencies = getExistingComponentDependencies(); - doReturn(existingComponentsDependencies). - when(vendorSoftwareProductDaoMock).listComponentDependencies(anyObject(), anyObject()); + doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock) + .list(anyObject()); Collection<ComponentEntity> componentListWithMoreComponentsInHeat = getComponentListWithMoreComponentsInHeat(); - doReturn(componentListWithMoreComponentsInHeat).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(componentListWithMoreComponentsInHeat).when(componentDaoMock).list(anyObject()); Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo(); orchestrationUtil.updateVspComponentDependencies(anyObject(), anyObject(), componentIdNameInfoBeforeProcess); @@ -136,14 +134,14 @@ public class OrchestrationTemplateCandidateManagerImplTest { Collection<ComponentDependencyModelEntity> existingComponentsDependencies = getExistingComponentDependencies(); doReturn(existingComponentsDependencies). - when(vendorSoftwareProductDaoMock).listComponentDependencies(anyObject(), anyObject()); + when(componentDependencyModelDaoMock).list(anyObject()); Collection<ComponentEntity> componentListWithLessComponentsInHeat = getComponentListWithLessComponentsInHeat(); - doReturn(componentListWithLessComponentsInHeat).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(componentListWithLessComponentsInHeat).when(componentDaoMock).list(anyObject()); Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo(); - orchestrationUtil.updateVspComponentDependencies(anyObject(), anyObject(), - componentIdNameInfoBeforeProcess); + orchestrationUtil + .updateVspComponentDependencies(anyObject(), anyObject(), + componentIdNameInfoBeforeProcess); Mockito.verify(componentDependencyModelDaoMock, Mockito.times(1)).update(anyObject()); Mockito.verify(componentDependencyModelDaoMock, Mockito.times(1)).delete(anyObject()); } @@ -152,12 +150,11 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUpdateVspComponentDependenciesHeatReuploadSameComponents() { Collection<ComponentDependencyModelEntity> existingComponentsDependencies = getExistingComponentDependencies(); - doReturn(existingComponentsDependencies). - when(vendorSoftwareProductDaoMock).listComponentDependencies(anyObject(), anyObject()); + doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock) + .list(anyObject()); Collection<ComponentEntity> componentListWithSameComponentsInHeat = getComponentListWithSameComponentsInHeat(); - doReturn(componentListWithSameComponentsInHeat).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(componentListWithSameComponentsInHeat).when(componentDaoMock).list(anyObject()); Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo(); orchestrationUtil.updateVspComponentDependencies(anyObject(), anyObject(), componentIdNameInfoBeforeProcess); @@ -169,12 +166,11 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUpdateVspComponentDependenciesHeatReuploadNoComponents() { Collection<ComponentDependencyModelEntity> existingComponentsDependencies = getExistingComponentDependencies(); - doReturn(existingComponentsDependencies). - when(vendorSoftwareProductDaoMock).listComponentDependencies(anyObject(), anyObject()); + doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock) + .list(anyObject()); Collection<ComponentEntity> componentListWithMoreComponentsInHeat = new ArrayList<>(); - doReturn(componentListWithMoreComponentsInHeat).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(componentListWithMoreComponentsInHeat).when(componentDaoMock).list(anyObject()); Map<String, String> componentIdNameInfoBeforeProcess = getVspInitComponentIdNameInfo(); orchestrationUtil.updateVspComponentDependencies(anyObject(), anyObject(), componentIdNameInfoBeforeProcess); @@ -193,8 +189,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { @Test public void testVspComponentIdNameInfo() { Collection<ComponentEntity> initialVspComponents = getInitialVspComponents(); - doReturn(initialVspComponents).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(initialVspComponents).when(componentDaoMock).list(anyObject()); Map<String, String> vspComponentIdNameInfo = orchestrationUtil.getVspComponentIdNameInfo(anyObject(), anyObject()); Assert.assertEquals(vspComponentIdNameInfo.size(), 3); @@ -210,8 +205,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { componentEntity.setId(COMPONENT_ORIG_ID_4); initialVspComponents.add(componentEntity); - doReturn(initialVspComponents).when(vendorSoftwareProductDaoMock) - .listComponents(anyObject(), anyObject()); + doReturn(initialVspComponents).when(componentDaoMock).list(anyObject()); Map<String, String> vspComponentIdNameInfo = orchestrationUtil.getVspComponentIdNameInfo(anyObject(), anyObject()); Assert.assertEquals(vspComponentIdNameInfo.size(), 3); @@ -250,7 +244,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { private Collection<ComponentEntity> getComponentListWithLessComponentsInHeat() { Collection<ComponentEntity> vspComponents = getInitialVspComponents(); - for (Iterator<ComponentEntity> iterator = vspComponents.iterator(); iterator.hasNext();) { + for (Iterator<ComponentEntity> iterator = vspComponents.iterator(); iterator.hasNext(); ) { ComponentEntity componentEntity = iterator.next(); if (componentEntity.getComponentCompositionData().getName().equals(COMPONENT_NAME_1)) { iterator.remove(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateProcessCsarHandlerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateProcessCsarHandlerTest.java index c2a207d6d9..bc3727381b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateProcessCsarHandlerTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateProcessCsarHandlerTest.java @@ -6,14 +6,12 @@ import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.factory.impl.AbstractFactoryBase; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.CandidateServiceFactoryMock; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.NoSqlDbFactoryMock; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.PackageInfoDaoFactoryImplMock; -import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.VendorSoftwareProductDaoFactoryMock; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessCsarHandler; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.versioning.dao.types.Version; @@ -21,27 +19,31 @@ import org.openecomp.sdc.versioning.dao.types.Version; import java.nio.ByteBuffer; import static org.junit.Assert.assertFalse; -public class OrchestrationTemplateProcessCsarHandlerTest { - - - @Before - public void insertMocks(){ - EnrichmentManagerFactory.getInstance(); - AbstractFactoryBase.registerFactory(NoSqlDbFactory.class, NoSqlDbFactoryMock.class); - AbstractFactoryBase.registerFactory(PackageInfoDaoFactory.class, PackageInfoDaoFactoryImplMock.class); - AbstractFactoryBase.registerFactory(PackageInfoDaoFactory.class, PackageInfoDaoFactoryImplMock.class); - AbstractFactoryBase.registerFactory(VendorSoftwareProductDaoFactory.class, VendorSoftwareProductDaoFactoryMock.class); - AbstractFactoryBase.registerFactory(CandidateServiceFactory.class, CandidateServiceFactoryMock.class); - } +public class OrchestrationTemplateProcessCsarHandlerTest { - @Test - public void validateErrorHandling(){ - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new OrchestrationTemplateCandidateData(ByteBuffer.wrap("".getBytes()),""); - OrchestrationTemplateProcessCsarHandler handler = new OrchestrationTemplateProcessCsarHandler(); - OrchestrationTemplateActionResponse response = handler.process(vspDetails, orchestrationTemplateCandidateData, "007"); - assertFalse(response.getErrors().isEmpty()); - } + @Before + public void insertMocks() { + EnrichmentManagerFactory.getInstance(); + AbstractFactoryBase.registerFactory(NoSqlDbFactory.class, NoSqlDbFactoryMock.class); + AbstractFactoryBase + .registerFactory(PackageInfoDaoFactory.class, PackageInfoDaoFactoryImplMock.class); + AbstractFactoryBase + .registerFactory(PackageInfoDaoFactory.class, PackageInfoDaoFactoryImplMock.class); + AbstractFactoryBase + .registerFactory(CandidateServiceFactory.class, CandidateServiceFactoryMock.class); + } + + + @Test + public void validateErrorHandling() { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = + new OrchestrationTemplateCandidateData(ByteBuffer.wrap("".getBytes()), "", "zip", "file"); + OrchestrationTemplateProcessCsarHandler handler = new OrchestrationTemplateProcessCsarHandler(); + OrchestrationTemplateActionResponse response = + handler.process(vspDetails, orchestrationTemplateCandidateData); + assertFalse(response.getErrors().isEmpty()); + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImplTest.java index 478bdfbbba..b925ab9270 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImplTest.java @@ -1,19 +1,18 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType; import org.openecomp.sdc.versioning.dao.types.Version; @@ -28,12 +27,13 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.Matchers.eq; public class ProcessManagerImplTest { @@ -48,9 +48,7 @@ public class ProcessManagerImplTest { private static final String ARTIFACT_NAME = "artifact.sh"; @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private ActivityLogManager activityLogManagerMock; + private ProcessDao processDaoMock; @InjectMocks @Spy @@ -66,7 +64,7 @@ public class ProcessManagerImplTest { @Test public void testListWhenNone() { Collection<ProcessEntity> processes = - processManager.listProcesses(VSP_ID, VERSION, COMPONENT_ID, USER1); + processManager.listProcesses(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(processes.size(), 0); } @@ -75,17 +73,17 @@ public class ProcessManagerImplTest { doReturn(Arrays.asList( createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID), createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS2_ID))) - .when(vendorSoftwareProductDaoMock).listProcesses(VSP_ID, VERSION, COMPONENT_ID); + .when(processDaoMock).list(any(ProcessEntity.class)); Collection<ProcessEntity> actual = - processManager.listProcesses(VSP_ID, VERSION, COMPONENT_ID, USER1); + processManager.listProcesses(VSP_ID, VERSION, COMPONENT_ID); Assert.assertEquals(actual.size(), 2); } @Test public void testDeleteListWhenNone() { - processManager.deleteProcesses(VSP_ID, VERSION, COMPONENT_ID, USER1); - verify(vendorSoftwareProductDaoMock, never()).deleteProcesses(VSP_ID, VERSION, COMPONENT_ID); + processManager.deleteProcesses(VSP_ID, VERSION, COMPONENT_ID); + verify(processDaoMock, never()).delete(any(ProcessEntity.class)); } @Test @@ -93,15 +91,15 @@ public class ProcessManagerImplTest { ProcessEntity process1 = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); ProcessEntity process2 = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS2_ID); doReturn(Arrays.asList(process1, process2)) - .when(vendorSoftwareProductDaoMock).listProcesses(VSP_ID, VERSION, COMPONENT_ID); + .when(processDaoMock).list(any(ProcessEntity.class)); doNothing().when(processManager) .deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, process1.getName()); doNothing().when(processManager) .deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, process2.getName()); - processManager.deleteProcesses(VSP_ID, VERSION, COMPONENT_ID, USER1); + processManager.deleteProcesses(VSP_ID, VERSION, COMPONENT_ID); - verify(vendorSoftwareProductDaoMock).deleteProcesses(VSP_ID, VERSION, COMPONENT_ID); + verify(processDaoMock).deleteAll(eq(new ProcessEntity(VSP_ID, VERSION, COMPONENT_ID, null))); verify(processManager) .deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, process1.getName()); verify(processManager) @@ -118,7 +116,7 @@ public class ProcessManagerImplTest { doNothing().when(processManager) .createUniqueName(VSP_ID, VERSION, COMPONENT_ID, processToCreate.getName()); - ProcessEntity process = processManager.createProcess(processToCreate, USER1); + ProcessEntity process = processManager.createProcess(processToCreate); Assert.assertNotNull(process); process.setId(process.getId()); @@ -134,13 +132,12 @@ public class ProcessManagerImplTest { new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) .when(processManager).validateUniqueName(VSP_ID, VERSION, COMPONENT_ID, process.getName()); - processManager.createProcess(process, USER1); + processManager.createProcess(process); } @Test public void testUpdateNonExistingProcessId_negative() { - doReturn(null).when(vendorSoftwareProductDaoMock) - .getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(null).when(processDaoMock).get(any(ProcessEntity.class)); testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); @@ -149,8 +146,7 @@ public class ProcessManagerImplTest { @Test(expectedExceptions = CoreException.class) public void testUpdateWithExistingName_negative() { ProcessEntity existingProcess = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); - doReturn(existingProcess).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(existingProcess).when(processDaoMock).get(any(ProcessEntity.class)); ProcessEntity processToUpdate = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); doThrow(new CoreException( @@ -159,22 +155,21 @@ public class ProcessManagerImplTest { .updateUniqueName(VSP_ID, VERSION, COMPONENT_ID, existingProcess.getName(), processToUpdate.getName()); - processManager.updateProcess(processToUpdate, USER1); + processManager.updateProcess(processToUpdate); } @Test public void testUpdate() { ProcessEntity existingProcess = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); - doReturn(existingProcess).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(existingProcess).when(processDaoMock).get(any(ProcessEntity.class)); ProcessEntity processToUpdate = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); doNothing().when(processManager) .updateUniqueName(VSP_ID, VERSION, COMPONENT_ID, existingProcess.getName(), processToUpdate.getName()); - processManager.updateProcess(processToUpdate, USER1); - verify(vendorSoftwareProductDaoMock).updateProcess(processToUpdate); + processManager.updateProcess(processToUpdate); + verify(processDaoMock).update(processToUpdate); } @@ -187,10 +182,9 @@ public class ProcessManagerImplTest { @Test public void testGet() { ProcessEntity process = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); - doReturn(process).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(process).when(processDaoMock).get(any(ProcessEntity.class)); ProcessEntity actual = - processManager.getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); + processManager.getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); Assert.assertEquals(actual, process); Assert.assertNull(actual.getArtifactName()); } @@ -199,29 +193,28 @@ public class ProcessManagerImplTest { public void testGetAfterUploadArtifact() { ProcessEntity process = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); process.setArtifactName(ARTIFACT_NAME); - doReturn(process).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(process).when(processDaoMock).get(any(ProcessEntity.class)); ProcessEntity actual = - processManager.getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); + processManager.getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); Assert.assertEquals(actual, process); Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME); } @Test(expectedExceptions = CoreException.class) public void testDeleteNonExistingProcessId_negative() { - processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); + processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); } @Test public void testDelete() { ProcessEntity processToDelete = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); - doReturn(processToDelete).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(processToDelete).when(processDaoMock) + .get(any(ProcessEntity.class)); doNothing().when(processManager).deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, processToDelete.getName()); - processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); - verify(vendorSoftwareProductDaoMock).deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + verify(processDaoMock).delete(any(ProcessEntity.class)); verify(processManager) .deleteUniqueValue(VSP_ID, VERSION, COMPONENT_ID, processToDelete.getName()); } @@ -235,21 +228,13 @@ public class ProcessManagerImplTest { @Test public void testUploadArtifact() { ProcessEntity process = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); - doReturn(process).when - (vendorSoftwareProductDaoMock).getProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(process).when(processDaoMock).get(any(ProcessEntity.class)); byte[] artifactBytes = "bla bla".getBytes(); processManager .uploadProcessArtifact(new ByteArrayInputStream(artifactBytes), ARTIFACT_NAME, - VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); - verify(vendorSoftwareProductDaoMock) - .uploadProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, artifactBytes, - ARTIFACT_NAME); - - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION.getMajor()+1)); - Assert.assertTrue(activityLogEntity.isSuccess()); + VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + verify(processDaoMock).uploadArtifact(any(ProcessEntity.class)); } @Test @@ -269,11 +254,11 @@ public class ProcessManagerImplTest { ProcessEntity processArtifact = new ProcessEntity(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); processArtifact.setArtifact(ByteBuffer.wrap("bla bla".getBytes())); - doReturn(processArtifact).when(vendorSoftwareProductDaoMock) - .getProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(processArtifact).when(processDaoMock) + .getArtifact(any(ProcessEntity.class)); File actual = - processManager.getProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); + processManager.getProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); Assert.assertNotNull(actual); } @@ -294,12 +279,12 @@ public class ProcessManagerImplTest { ProcessEntity processArtifact = new ProcessEntity(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); processArtifact.setArtifact(ByteBuffer.wrap("bla bla".getBytes())); - doReturn(processArtifact).when(vendorSoftwareProductDaoMock) - .getProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + doReturn(processArtifact).when(processDaoMock) + .getArtifact(any(ProcessEntity.class)); - processManager.deleteProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID, USER1); - verify(vendorSoftwareProductDaoMock) - .deleteProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + processManager.deleteProcessArtifact(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); + verify(processDaoMock) + .deleteArtifact(any(ProcessEntity.class)); } @@ -315,10 +300,10 @@ public class ProcessManagerImplTest { private void testGet_negative(String vspId, Version version, String componentId, String processId, String user, String expectedErrorCode) { try { - processManager.getProcess(vspId, version, componentId, processId, user); + processManager.getProcess(vspId, version, componentId, processId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } @@ -328,10 +313,10 @@ public class ProcessManagerImplTest { String expectedErrorCode) { try { processManager - .updateProcess(new ProcessEntity(vspId, version, componentId, processId), user); + .updateProcess(new ProcessEntity(vspId, version, componentId, processId)); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } @@ -339,10 +324,10 @@ public class ProcessManagerImplTest { private void testGetFile_negative(String vspId, Version version, String componentId, String processId, String user, String expectedErrorCode) { try { - processManager.getProcessArtifact(vspId, version, componentId, processId, user); + processManager.getProcessArtifact(vspId, version, componentId, processId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } @@ -353,10 +338,10 @@ public class ProcessManagerImplTest { try { processManager .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), "artifact.sh", - vspId, version, componentId, processId, user); + vspId, version, componentId, processId); Assert.fail(); } catch (CoreException exception) { - log.error("",exception); + log.error("", exception); Assert.assertEquals(exception.code().id(), expectedErrorCode); } } @@ -364,10 +349,10 @@ public class ProcessManagerImplTest { private void testDeleteArtifact_negative(String vspId, String componentId, String processId, String user, String expectedErrorCode) { try { - processManager.deleteProcessArtifact(vspId, VERSION, componentId, processId, user); + processManager.deleteProcessArtifact(vspId, VERSION, componentId, processId); Assert.fail(); } catch (CoreException exception) { - log.debug("",exception); + log.debug("", 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/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 5199dfd365..7721817c3b 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 @@ -33,15 +33,12 @@ import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.healing.api.HealingManager; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; @@ -53,18 +50,16 @@ import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; -import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; @@ -94,7 +89,6 @@ import java.util.zip.ZipInputStream; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -103,13 +97,10 @@ import static org.mockito.Mockito.verify; public class VendorSoftwareProductManagerImplTest { - - private static final Logger LOG = LoggerFactory.getLogger(VendorSoftwareProductManagerImplTest.class); - private static final String INVALID_VERSION_MSG = "Invalid requested version."; - private static final String VSP_ID = "vspId"; - private static final String VERSION_ID = "versionId"; + private static String VSP_ID = "vspId"; + private static String VERSION_ID = "versionId"; public static final Version VERSION01 = new Version(0, 1); private static final Version VERSION10 = new Version(1, 0); private static final String USER1 = "vspTestUser1"; @@ -121,8 +112,6 @@ public class VendorSoftwareProductManagerImplTest { @Mock private VersioningManager versioningManagerMock; @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of - @Mock private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; @Mock private VendorLicenseFacade vendorLicenseFacadeMock; @@ -139,8 +128,6 @@ public class VendorSoftwareProductManagerImplTest { @Mock private InformationArtifactGenerator informationArtifactGeneratorMock; @Mock - private ActivityLogManager activityLogManagerMock; - @Mock private PackageInfoDao packageInfoDao; @Mock private VendorSoftwareProductInfoDao vspInfoDaoMock; @@ -164,14 +151,14 @@ public class VendorSoftwareProductManagerImplTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - +/* @Test public void testListWhenNone() { doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(null, USER1); + vendorSoftwareProductManager.listVsps(null); Assert.assertEquals(vsps.size(), 0); } @@ -190,16 +177,16 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); VspDetails vsp1 = new VspDetails(vsp1id, VERSION01); vsp1.setWritetimeMicroSeconds(8L); doReturn(vsp1).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(null, USER1); + vendorSoftwareProductManager.listVsps(null); Assert.assertEquals(vsps.size(), 2); } @@ -218,11 +205,11 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); + vendorSoftwareProductManager.listVsps(VersionStatus.Certified.name()); Assert.assertEquals(vsps.size(), 0); } @@ -242,53 +229,36 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); VspDetails vsp2 = new VspDetails(vsp2id, VERSION10); vsp2.setWritetimeMicroSeconds(8L); doReturn(vsp2).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); + vendorSoftwareProductManager.listVsps(VersionStatus.Certified.name()); Assert.assertEquals(vsps.size(), 1); - } + }*/ - @Test(expectedExceptions = CoreException.class) - public void testCreateWithExistingName_negative() { - doThrow(new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) - .when(vendorSoftwareProductManager).validateUniqueName("Vsp1"); - VspDetails expectedVsp = - createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", null); - - vendorSoftwareProductManager.createVsp(expectedVsp, USER1); - } @Test public void testCreate() { - doNothing().when(vendorSoftwareProductManager).validateUniqueName("Vsp1"); - doNothing().when(vendorSoftwareProductManager).createUniqueName("Vsp1"); - doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject()); + //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject()); doReturn("{}") - .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject()); + .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject()); VspDetails vspToCreate = - createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", null); + createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "123", null); - VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1); + VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate); Assert.assertNotNull(vsp); vspToCreate.setId(vsp.getId()); vspToCreate.setVersion(VERSION01); assertVspsEquals(vsp, vspToCreate); - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); - Assert.assertTrue(activityLogEntity.isSuccess()); } @Test(expectedExceptions = CoreException.class) @@ -296,23 +266,23 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id", - "icon", "category", "subCategory", "123", null); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id", + "icon", "category", "subCategory", "123", null); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName", - "vlm1Id", "icon", "category", "subCategory", "123", null); + createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doThrow(new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) - .when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) + .when(vendorSoftwareProductManager) + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); - vendorSoftwareProductManager.updateVsp(updatedVsp, USER1); + vendorSoftwareProductManager.updateVsp(updatedVsp); } @Test @@ -320,23 +290,23 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", - "category_updated", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", + "category_updated", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doNothing().when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); - vendorSoftwareProductManager.updateVsp(updatedVsp, USER1); + vendorSoftwareProductManager.updateVsp(updatedVsp); verify(vspInfoDaoMock).update(updatedVsp); } @@ -346,40 +316,41 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); - List<String> fgs = new ArrayList<>(); - fgs.add("fg1"); fgs.add("fg2"); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); + List<String> fgs = new ArrayList<String>(); + fgs.add("fg1"); + fgs.add("fg2"); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", fgs); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", fgs); - List<String> updFgs = new ArrayList<>(); - updFgs.add("fg2"); + List<String> updFgs = new ArrayList<String>(); + //updFgs.add("fg2"); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", - "category_updated", - "subCategory", "456", updFgs); + createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", + "category_updated", + "subCategory", "456", updFgs); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doNothing().when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); - DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID,VERSION01,"DF_ID"); + DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID"); DeploymentFlavor flavor = new DeploymentFlavor(); flavor.setFeatureGroupId("fg1"); dfEntity.setDeploymentFlavorCompositionData(flavor); - List<DeploymentFlavorEntity> dfList = new ArrayList<>(); + List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>(); dfList.add(dfEntity); doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject()); - vendorSoftwareProductManager.updateVsp(updatedVsp, USER1); + vendorSoftwareProductManager.updateVsp(updatedVsp); - verify(vendorSoftwareProductDaoMock).updateDeploymentFlavor(dfEntity); + verify(deploymentFlavorDaoMock).update(dfEntity); Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId()); @@ -389,7 +360,7 @@ public class VendorSoftwareProductManagerImplTest { public void testGetNonExistingVersion_negative() { Version notExistversion = new Version(43, 8); doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class)); - vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion, USER1); + vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion); } @Test @@ -399,18 +370,18 @@ public class VendorSoftwareProductManagerImplTest { versionInfo.setStatus(VersionStatus.Locked); versionInfo.setLockingUser(USER1); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class)); VspDetails actualVsp = - vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); + vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01); assertVspsEquals(actualVsp, existingVsp); } @@ -423,84 +394,26 @@ public class VendorSoftwareProductManagerImplTest { versionInfo.setStatus(VersionStatus.Locked); versionInfo.setLockingUser(USER2); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp) - .when(vspInfoDaoMock).get(any(VspDetails.class)); + .when(vspInfoDaoMock).get(any(VspDetails.class)); VspDetails actualVsp = - vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); + vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01); VspDetails expectedVsp = - vspInfoDaoMock - .get(new VspDetails(VSP_ID, VERSION01)); + vspInfoDaoMock + .get(new VspDetails(VSP_ID, VERSION01)); assertVspsEquals(actualVsp, expectedVsp); } - @Test - public void testCheckin() { - doReturn(VERSION01).when(versioningManagerMock) - .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); - Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1); - - Assert.assertEquals(version, VERSION01); - verify(versioningManagerMock) - .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); - Assert.assertTrue(activityLogEntity.isSuccess()); - } - - @Test - public void testCheckout() { - doReturn(VERSION01).when(versioningManagerMock) - .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1); - Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1); - - Assert.assertEquals(version, VERSION01); - verify(versioningManagerMock) - .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1); - - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); - Assert.assertTrue(activityLogEntity.isSuccess()); - } - - - @Test - public void testUndoCheckout() { - Version existingVersion = new Version(0, 2); - VersionInfo versionInfo = new VersionInfo(); - versionInfo.setActiveVersion(existingVersion); - doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - VSP_ID, USER1, VersionableEntityAction.Read); - - doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants - .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1); - - VspDetails vsp = new VspDetails(VSP_ID, existingVersion); - vsp.setName("ExistingName"); - doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); - doNothing().when(vendorSoftwareProductManager).updateUniqueName(vsp.getName(), vsp.getName()); - - Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1); - - Assert.assertEquals(undoCheckoutVersion, VERSION01); - } - /* @Test public void testSubmitWithMissingData() throws IOException { @@ -551,35 +464,33 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - VSP_ID, USER1, VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + VSP_ID, USER1, VersionableEntityAction.Read); VspDetails vsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "licenseAgreementId", - Collections.singletonList("featureGroupId")); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "licenseAgreementId", + Collections.singletonList("featureGroupId")); doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); - UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01); + OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01); uploadData.setContentData( - ByteBuffer.wrap(getBytes("/emptyComposition"))); + ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); doReturn(uploadData).when(orchestrationTemplateDataDaoMock) - .getOrchestrationTemplate(anyObject(), anyObject()); + .get(anyObject(), anyObject()); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), - "MainServiceTemplate.yaml")) - .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); + "MainServiceTemplate.yaml")) + .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); - ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1); + ValidationResponse validationResponse = + vendorSoftwareProductManager.validate(VSP_ID, VERSION01); Assert.assertNotNull(validationResponse); Assert.assertFalse(validationResponse.isValid()); Assert.assertNull(validationResponse.getVspErrors()); - Assert.assertEquals(validationResponse.getLicensingDataErrors(), 1); + Assert.assertEquals(validationResponse.getLicensingDataErrors().size(), 1); verify(versioningManagerMock, never()) - .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); - - //TODO - check.. - verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); } // TODO: 3/15/2017 fix and enable @@ -589,40 +500,32 @@ public class VendorSoftwareProductManagerImplTest { EnrichmentManagerFactory.getInstance(); AbstractFactoryBase - .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class); + .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class); VspDetails vsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", Collections.singletonList("fg1")); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "123", Collections.singletonList("fg1")); doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); - UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01); + OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(VSP_ID, VERSION01); uploadData.setContentData( - ByteBuffer.wrap(getBytes("/emptyComposition"))); + ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); doReturn(uploadData).when(orchestrationTemplateDataDaoMock) - .getOrchestrationTemplate(anyObject(), anyObject()); + .get(anyObject(), anyObject()); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), - "MainServiceTemplate.yaml")) - .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); + "MainServiceTemplate.yaml")) + .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); - ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1); + ValidationResponse validationResponse = + vendorSoftwareProductManager.validate(VSP_ID, VERSION01); Assert.assertTrue(validationResponse.isValid()); -/* Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10); - Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final); +/* Assert.assertEquals(vsp2.getVersionInfo().getVersion(), VERSION10); + Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Certified); Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/ verify(versioningManagerMock) - .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); - verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); - ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); - Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor())); - Assert.assertTrue(activityLogEntity.isSuccess()); - } - - @Test(expectedExceptions = CoreException.class) - public void testCreatePackageOnNonFinalVersion_negative() throws IOException { - vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1); + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); } @Test @@ -632,11 +535,11 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION10); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when - (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10); + (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10); VspDetails vsp = new VspDetails(VSP_ID, VERSION10); vsp.setVendorId("vendorId"); @@ -645,20 +548,20 @@ public class VendorSoftwareProductManagerImplTest { doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class)); doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock) - .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(), - USER1); + .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups() + ); - PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1); + PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10); Assert.assertNotNull(packageInfo.getVspId()); } // TODO: 3/15/2017 fix and enable //@Test(dependsOnMethods = {"testListFinals"}) public void testUploadFileMissingFile() throws IOException { + try (InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip")) { - try (InputStream zis = this.getClass().getResourceAsStream("/vspmanager/zips/missingYml.zip")) { UploadFileResponse uploadFileResponse = - candidateManager.upload(VSP_ID, VERSION01, zis, USER1, "zip", "missingYml"); + candidateManager.upload(VSP_ID, VERSION01, zis, "zip", "file"); Assert.assertEquals(uploadFileResponse.getErrors().size(), 0); } @@ -667,38 +570,130 @@ public class VendorSoftwareProductManagerImplTest { // TODO: 3/15/2017 fix and enable //@Test(dependsOnMethods = {"testUploadFileMissingFile"}) public void testUploadNotZipFile() throws IOException { - URL url = this.getClass().getResource("/notZipFile"); - try (InputStream inputStream = url.openStream()) { - candidateManager - .upload(VSP_ID, VERSION01, - inputStream, USER1, "zip", "notZipFile"); - candidateManager.process(VSP_ID, VERSION01, USER1); + try { + candidateManager.upload(VSP_ID, VERSION01, url.openStream(), "zip", "file"); + candidateManager.process(VSP_ID, VERSION01); } catch (Exception ce) { Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); } + } +/* + @Test + public void testEnrichModelInSubmit() { + UniqueValueUtil + .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + "VSP_syb"); + VspDetails vspDetails = vendorSoftwareProductManager.createVsp( + createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "456", null), USER1); + String id = vspDetails.getId(); + + //upload file + InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); + candidateManager.upload(id, VERSION01, zis, USER1); + OrchestrationTemplateActionResponse uploadFileResponse = + candidateManager.process(id, VERSION01, USER1); + + //check in + vendorSoftwareProductManager.checkin(id, USER1); + //submit + try { + ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); + } catch (IOException exception) { + Assert.fail(); + } + VersionedVendorSoftwareProductInfo details = + vendorSoftwareProductManager.getVsp(id, null, USER1); + Collection<ComponentEntity> components =vendorSoftwareProductManager + .listComponents(id, details.getVersionInfo().getVersion(), USER1); + + ToscaServiceModel model = + (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() + .getServiceModel(id, details.getVersionInfo().getVersion()); + + Map<String, CapabilityDefinition> capabilities = new HashMap<>(); + for (ComponentEntity component : components) { + model.getServiceTemplates(). + entrySet(). + stream(). + filter(entryValue -> entryValue.getValue() != null && + entryValue.getValue().getNode_types() != null && + entryValue.getValue(). + getNode_types(). + containsKey(component.getComponentCompositionData().getName())). + forEach(entryValue -> entryValue.getValue().getNode_types(). + values(). + stream(). + filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). + forEach(type -> type.getCapabilities(). + entrySet(). + forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), + entry.getValue())))); + + } + + Assert.assertNotNull(capabilities); + } + + @Test(dependsOnMethods = {"testCreatePackage"}) + public void testEnrichedFilesDeletedOnNewUpload() throws IOException { + Version activeVersion; + + createPackageFromUpload(VSP_ID, USER1, "/fullComposition"); + activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() + .getVersion(); + + List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock + .getExternalArtifacts(VSP_ID, activeVersion); + ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, + activeVersion); + + createPackageFromUpload(VSP_ID, USER1, "/emptyComposition"); + activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() + .getVersion(); + + List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock + .getExternalArtifacts(VSP_ID, activeVersion); + ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, + activeVersion); + + Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts); + Assert.assertNotEquals(firstServiceModel, secondServiceModel); - verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); } + @Test(dependsOnMethods = {"testMibsDeletedInCsar"}) + public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException { + String nestedPath = "Definitions" + File.separator + "nested"; + + uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip"); + checkinSubmitCreatePackage(VSP_ID, USER1); + List<String> nestedFileNamesServiceTemplates = + getWantedFileNamesFromCsar(nestedPath); + + uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip"); + checkinSubmitCreatePackage(VSP_ID, USER1); + List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath); + + Assert.assertEquals(emptyNestedNamesList.size(), 0); + Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size()); + }*/ private List<String> getWantedFileNamesFromCsar(String pathInCsar) - throws IOException { - File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1); + throws IOException { + File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10); return getFileNamesFromFolderInCsar(translatedFile, - pathInCsar); + pathInCsar); } private List<String> getFileNamesFromFolderInCsar(File csar, String folderName) - throws IOException { - + throws IOException { List<String> fileNames = new ArrayList<>(); - try (FileInputStream fileInputStream = new FileInputStream(csar); - ZipInputStream zip = new ZipInputStream(fileInputStream)) { - + try (ZipInputStream zip = new ZipInputStream(new FileInputStream(csar))) { ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { @@ -711,28 +706,26 @@ public class VendorSoftwareProductManagerImplTest { return fileNames; } - - private void createPackageFromUpload(String vspId, String user, String filePath) - throws IOException { - uploadFileAndProcess(vspId, user, filePath); - checkinSubmitCreatePackage(vspId, user); - } - - private void uploadFileAndProcess(String vspId, String user, String filePath) throws IOException { - vendorSoftwareProductManager.checkout(vspId, user); - - try (InputStream inputStream = this.getClass().getResourceAsStream(filePath)) { - candidateManager.upload(vspId, VERSION01, inputStream, user, "zip", "file"); - candidateManager.process(vspId, VERSION01, user); - } - } - - private void checkinSubmitCreatePackage(String vspId, String user) throws IOException { - vendorSoftwareProductManager.checkin(vspId, user); - ValidationResponse submitResponse = vendorSoftwareProductManager.submit(vspId, user); - Assert.assertTrue(submitResponse.isValid()); - vendorSoftwareProductManager.createPackage(vspId, VERSION10, user); - } + /* + //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); + monitoringUploadsManager.upload(getFileInputStream(filePath), + fileName, vspId, +<<<<<<< HEAD + VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL); + //TODO: add validate of logActivity() func call +======= + VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user); + //TODO: add validate of addActionLog() func call +>>>>>>> feature/Amdocs-ASDC-1710 + + return new ImmutablePair<>(componentEntities.get(0).getId(), + componentEntities.get(0).getComponentCompositionData() + .getDisplayName()); + }*/ // TODO: 3/15/2017 fix and enable /* @@ -781,11 +774,11 @@ public class VendorSoftwareProductManagerImplTest { */ private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, VERSION01, upload, USER1, "zip", "file"); - candidateManager.process(vspId, VERSION01, user); + candidateManager.upload(vspId, VERSION01, upload, "zip", "file"); + candidateManager.process(vspId, VERSION01); - UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); + OrchestrationTemplateEntity uploadData = + orchestrationTemplateDataDaoMock.get(vspId, version); Assert.assertNotNull(uploadData); } @@ -795,20 +788,40 @@ public class VendorSoftwareProductManagerImplTest { capabilities.put(entryValueKey + "_" + key, value); } - private byte[] getBytes(String fileName) throws IOException { + public InputStream getFileInputStream(String fileName) { URL url = this.getClass().getResource(fileName); - try (InputStream inputStream = url.openStream()) { - return FileUtils.toByteArray(inputStream); + try { + return url.openStream(); + } catch (IOException exception) { + exception.printStackTrace(); + return null; } } - private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) { +/* private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) { List<VersionedVendorSoftwareProductInfo> vspList = - vendorSoftwareProductManager.listVsps(null, user); + vendorSoftwareProductManager.listVsps(null); Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId); - } - - + }*/ + + + // private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName) +// throws IOException { +// ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName))); +// boolean isInfoArtifactInZip = false; +// +// ZipEntry zipEntry; +// while ((zipEntry = inputZipStream.getNextEntry()) != null) { +// String currentEntryName = zipEntry.getName(); +// if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" + +// vspId + "_Information.txt")){ +// isInfoArtifactInZip = true; +// break; +// } +// } +// +// Assert.assertTrue(isInfoArtifactInZip); +// } static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, @@ -842,30 +855,68 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups()); } - // todo ********************** move to common ************************************** + +// @Test +// public void testDownloadFile() throws IOException { +// VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null); +// VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1); +// +// id005 = createdVsp.getId(); +// Assert.assertNotNull(id005); +// Assert.assertNotNull(createdVsp.getVersion()); +// +// try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) { +// +// UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1); +// vendorSoftwareProductManager.process(id005, USER1); +// Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1); +// +// File latestHeatPackage = fileCandidate.get(); +// +// zipInputStream.reset(); +// byte[] uploaded = IOUtils.toByteArray(zipInputStream); +// +// Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded); +// FileContentHandler fileContentHandler = new FileContentHandler(); +// if(zipContentMap.isPresent()){ +// fileContentHandler = zipContentMap.get(); +// } +// +// uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values()); +// +// byte[] downloaded; +// try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) { +// downloaded = IOUtils.toByteArray(fileStream); +// } +// +// Assert.assertTrue(Arrays.equals(uploaded, downloaded)); +// } +// } + + // todo ********************** move to common ************************************** private void mockVersioning(VersionableEntityAction action) { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + action); } private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) { doThrow(new CoreException(new EntityNotExistErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build())) + .when(versioningManagerMock).getEntityVersionInfo( + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1, + action); } private void MockVersioningEntityLocked(VersionableEntityAction action) { doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1) - .build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1) + .build())) + .when(versioningManagerMock).getEntityVersionInfo( + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2, + action); } }
\ 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/impl/mock/VendorSoftwareProductDaoFactoryMock.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/mock/VendorSoftwareProductDaoFactoryMock.java deleted file mode 100644 index ede8620cf9..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/mock/VendorSoftwareProductDaoFactoryMock.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.openecomp.sdc.vendorsoftwareproduct.impl.mock; - -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; - -public class VendorSoftwareProductDaoFactoryMock extends VendorSoftwareProductDaoFactory { - - @Override - public VendorSoftwareProductDao createInterface() { - return null; - } -} 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 3d98ab76c6..1c9d61b51b 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 @@ -30,7 +30,6 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.ManifestCreator; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; @@ -57,8 +56,6 @@ import static org.testng.Assert.assertTrue; public class CandidateServiceImplTest { @Mock private ManifestCreator manifestCreatorMock; - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; @InjectMocks private CandidateServiceImpl candidateService; @@ -95,7 +92,8 @@ public class CandidateServiceImplTest { //vspDetails.setOnboardingMethod(VSPCommon.OnboardingMethod.HEAT.name()); vspDetails.setOnboardingMethod("HEAT"); - FilesDataStructure structure = JsonUtil.json2Object(getExpectedJson(), FilesDataStructure.class); + FilesDataStructure structure = + JsonUtil.json2Object(getExpectedJson(), FilesDataStructure.class); Optional<ManifestContent> expectedManifest = getExpectedManifestJson(); doReturn(expectedManifest) @@ -191,7 +189,8 @@ public class CandidateServiceImplTest { fileData = createFileData("file1.yaml", true, FileData.Type.HEAT, null); mockFileData.add(fileData); fileData = createFileData("file1_vol.yaml", null, FileData.Type.HEAT_VOL, fileData); - fileData = createFileData("file1.env", null, FileData.Type.HEAT_ENV, mockFileData.get(1).getData().get(0)); + fileData = createFileData("file1.env", null, FileData.Type.HEAT_ENV, + mockFileData.get(1).getData().get(0)); mockFileData.add(createFileData("file2.sh", null, FileData.Type.OTHER, null)); mockFileData.add(createFileData("file3.yml", null, FileData.Type.OTHER, null)); mock.setData(mockFileData); @@ -202,7 +201,7 @@ public class CandidateServiceImplTest { FileData fileDataToAddTo) { FileData fileData = new FileData(); fileData.setFile(fileName); - if(isBase != null) { + if (isBase != null) { fileData.setBase(isBase); } fileData.setType(fileType); @@ -211,11 +210,9 @@ public class CandidateServiceImplTest { } private void addFileDataToList(FileData fileDataToAddTo, FileData fileData) { - if(fileDataToAddTo != null) - { + if (fileDataToAddTo != null) { List<FileData> list = fileDataToAddTo.getData(); - if(CollectionUtils.isEmpty(list)) - { + if (CollectionUtils.isEmpty(list)) { list = new ArrayList<>(); } list.add(fileData); 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 2f85f30dc5..9385d4a10c 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 @@ -27,8 +27,8 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; 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.ToscaExtensionYamlUtil; +import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; @@ -110,11 +110,12 @@ public class CompositionDataExtractorImplTest { try (InputStream yamlFile = new FileInputStream(file)) { ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); - serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplateFromYaml), serviceTemplateFromYaml); + serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplateFromYaml), + serviceTemplateFromYaml); try { yamlFile.close(); } catch (IOException ignore) { - log.debug("",ignore); + log.debug("", ignore); } } catch (FileNotFoundException exception) { throw exception; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java index 1acd58d157..0d9245d779 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionEntityDataManagerImplTest.java @@ -22,12 +22,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.composition; import org.apache.commons.collections.CollectionUtils; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; @@ -43,6 +41,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -90,8 +89,6 @@ public class CompositionEntityDataManagerImplTest { "}"; private Map<CompositionEntityId, Collection<String>> errorsById; - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; @InjectMocks @Spy private CompositionEntityDataManagerImpl compositionEntityDataManager; @@ -248,7 +245,7 @@ public class CompositionEntityDataManagerImplTest { Map<CompositionEntityId, Collection<String>> errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); - Assert.assertEquals(errorsById.size(), 0); + Assert.assertEquals(errorsById.size(), 1); } @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire") @@ -259,9 +256,9 @@ public class CompositionEntityDataManagerImplTest { Map<CompositionEntityId, Collection<String>> errorsById = compositionEntityDataManager.validateEntitiesQuestionnaire(); - Assert.assertEquals(errorsById.size(), 1); + Assert.assertEquals(errorsById.size(), 2); - CompositionEntityId component = errorsById.keySet().iterator().next(); + CompositionEntityId component = new ArrayList<>(errorsById.keySet()).get(1); List<String> errors = (List<String>) errorsById.get(component); Assert.assertEquals(errors.size(), 1); Assert.assertEquals(errors.get(0), 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 acd76a151b..237e9cce8f 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 @@ -20,27 +20,6 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator; -import org.everit.json.schema.EmptySchema; -import org.everit.json.schema.loader.SchemaLoader; -import org.json.JSONObject; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentCompositionSchemaInput; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NicCompositionSchemaInput; -import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.Arrays; -import java.util.Map; - public class SchemaGeneratorTest { /* diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index df386b12cd..2a475fe895 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -21,9 +21,6 @@ package org.openecomp.sdc.vendorsoftwareproduct.tree; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; - import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -32,13 +29,10 @@ import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.healing.api.HealingManager; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; @@ -50,7 +44,11 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.util.zip.ZipOutputStream; @@ -59,70 +57,69 @@ import static org.mockito.Mockito.doReturn; import static org.testng.Assert.assertEquals; public class UploadFileTest { - private static final String USER1 = "vspTestUser1"; - - public static final Version VERSION01 = new Version(0, 1); - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; - @Spy - private CandidateServiceImpl candidateService; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private VendorSoftwareProductInfoDao vspInfoDaoMock; - - @InjectMocks - private OrchestrationTemplateCandidateManagerImpl candidateManager; - - private static String vlm1Id; - public static String id001 = null; - public static String id002 = null; - - public static Version activeVersion002 = null; - - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUploadFile() { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1, OnboardingTypesEnum.ZIP.toString(), "legalUpload"); - } - - - private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, - upload, user, OnboardingTypesEnum.ZIP.toString(),"file" ); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); - UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); - - } - - public InputStream getZipInputStream(String name) { - URL url = this.getClass().getResource(name); - File templateDir = new File(url.getFile()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ZipOutputStream zos = new ZipOutputStream(baos)) { - VSPCommon.zipDir(templateDir, "", zos, true); - } catch (IOException e) { - e.printStackTrace(); - } - return new ByteArrayInputStream(baos.toByteArray()); + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + + @InjectMocks + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + private static String vlm1Id; + public static String id001 = null; + public static String id002 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testUploadFile() { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), + OnboardingTypesEnum.ZIP.toString(), "legalUpload"); + } + + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, + upload, OnboardingTypesEnum.ZIP.toString(), "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); + OrchestrationTemplateEntity uploadData = orchestrationTemplateDataDaoMock.get(vspId, version); + + } + + public InputStream getZipInputStream(String name) { + URL url = this.getClass().getResource(name); + File templateDir = new File(url.getFile()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + VSPCommon.zipDir(templateDir, "", zos, true); + } catch (IOException e) { + e.printStackTrace(); } + return new ByteArrayInputStream(baos.toByteArray()); + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/HeatCleanup/HeatCleanupOnNewUploadTest.java index 4d925c00cd..13f3859c0c 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 @@ -38,7 +38,7 @@ public class HeatCleanupOnNewUploadTest {/* UploadDataEntity uploadDataEntity = vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, vspActiveVersion)); Assert.assertTrue((uploadDataEntity.getContentData() != null) == exist); - Assert.assertTrue((uploadDataEntity.getValidationData() != null) == exist); + Assert.assertTrue((uploadDataEntity.getInfo() != null) == exist); Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist); Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist); //TODO: talio - delete enrich data on new upload diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java index 3332e81e36..ee451e0a3c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java @@ -7,52 +7,55 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.Onboardin import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class ManifestParsingTest { - @Test - public void testSuccessfulParsing() throws IOException { - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) { - OnboardingManifest onboardingManifest = new OnboardingManifest(is); - assertTrue(onboardingManifest.isValid()); - assertEquals(onboardingManifest.getMetadata().size(), 4); - assertEquals(onboardingManifest.getSources().size(), 5); - } + @Test + public void testSuccessfulParsing() throws IOException { + try (InputStream is = getClass() + .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertTrue(onboardingManifest.isValid()); + assertEquals(onboardingManifest.getMetadata().size(), 4); + assertEquals(onboardingManifest.getSources().size(), 5); } - - @Test - public void testNoMetadataParsing() throws IOException { - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) { - OnboardingManifest onboardingManifest = new OnboardingManifest(is); - assertFalse(onboardingManifest.isValid()); - assertTrue(onboardingManifest.getErrors().stream(). - filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) - .findAny().isPresent()); - } + } + + @Test + public void testNoMetadataParsing() throws IOException { + try (InputStream is = getClass() + .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error + .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10)))); } - - @Test - public void testBrokenMDParsing() throws IOException { - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) { - OnboardingManifest onboardingManifest = new OnboardingManifest(is); - assertFalse(onboardingManifest.isValid()); - assertTrue(onboardingManifest.getErrors().stream(). - filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) - .findAny().isPresent()); - } + } + + @Test + public void testBrokenMDParsing() throws IOException { + try (InputStream is = getClass() + .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error + .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10)))); } - - @Test - public void testNoMetaParsing() throws IOException { - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) { - OnboardingManifest onboardingManifest = new OnboardingManifest(is); - assertFalse(onboardingManifest.isValid()); - assertTrue(onboardingManifest.getErrors().stream(). - filter(error -> error.contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))) - .findAny().isPresent()); - } + } + + @Test + public void testNoMetaParsing() throws IOException { + try (InputStream is = getClass() + .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error + .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10)))); } + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java index a7fc0e1ba0..d574c9ee74 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java @@ -33,7 +33,6 @@ import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; @@ -51,171 +50,163 @@ import java.io.InputStream; import java.util.List; import java.util.function.Predicate; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; public class UploadCSARFileTest { - private static final String USER1 = "vspTestUser1"; - - public static final Version VERSION01 = new Version(0, 1); - - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; - - @Spy - private CandidateServiceImpl candidateService; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private VendorSoftwareProductInfoDao vspInfoDaoMock; - @Mock - private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; - @Mock - private ManifestCreatorNamingConventionImpl manifestCreator; - - private OrchestrationTemplateCandidateManagerImpl candidateManager; - - - public static String id001 = null; - - public static Version activeVersion002 = null; - - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - candidateService = new CandidateServiceImpl(manifestCreator,orchestrationTemplateCandidateDao); - candidateManager = new OrchestrationTemplateCandidateManagerImpl( vendorSoftwareProductDaoMock, - vspInfoDaoMock, - orchestrationTemplateDataDaoMock, - candidateService, healingManagerMock, - compositionDataExtractorMock, - serviceModelDaoMock, - compositionEntityDataManagerMock, - null, - null, - null, - null, - null); - } - - @Test - public void testSuccessfulUploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmock"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(0, uploadFileResponse.getErrors().size()); - assertTrue(uploadFileResponse.getErrors().isEmpty()); - } - } - - @Test - public void testFail1UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, - "csar", "SDCmockFail1"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue( uploadFileResponse.getErrors().values().stream() - .filter(getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED - .getErrorMessage().substring(0, 7))).findAny().isPresent()); - } - } - private Predicate<List<ErrorMessage>> getListPredicate(String substring) { - return error -> isEquals(substring, error); + public static final Version VERSION01 = new Version("0.1"); + + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + @Mock + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; + @Mock + private ManifestCreatorNamingConventionImpl manifestCreator; + + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + + public static String id001 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + candidateService = new CandidateServiceImpl(manifestCreator, orchestrationTemplateCandidateDao); + candidateManager = new OrchestrationTemplateCandidateManagerImpl(vspInfoDaoMock, + candidateService, healingManagerMock); + } + + @Test + public void testSuccessfulUploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, "csar", "SDCmock"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(0, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().isEmpty()); } - - private boolean isEquals(String substring, List<ErrorMessage> error) { - return error.iterator().next().getMessage().contains(substring); + } + + @Test + public void testFail1UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, + "csar", "SDCmockFail1"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( + getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage().substring(0, 7)))); } - - @Test - public void testFail2UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, - "csar", "SDCmockFail2"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue( uploadFileResponse.getErrors().values().stream() - .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND - .getErrorMessage().substring(0,7))).findAny().isPresent()); - } + } + + private Predicate<List<ErrorMessage>> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List<ErrorMessage> error) { + return error.iterator().next().getMessage().contains(substring); + } + + @Test + public void testFail2UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, + "csar", "SDCmockFail2"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( + getListPredicate(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage().substring(0, 7)))); } - @Test - public void testFail3UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, - "csar", "SDCmockFail3"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - } + } + + @Test + public void testFail3UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, + "csar", "SDCmockFail3"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); } - - @Test - public void testUploadFileIsNotZip() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = new ByteArrayInputStream( "Thia is not a zip file".getBytes() );) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, - "csar", "file"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertFalse(uploadFileResponse.getErrors().isEmpty()); - assertTrue( uploadFileResponse.getErrors().values().stream() - .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND - .getErrorMessage().substring(0,7))).findAny().isPresent()); - } + } + + @Test + public void testUploadFileIsNotZip() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream("Thia is not a zip file".getBytes());) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, + "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertFalse(uploadFileResponse.getErrors().isEmpty()); + assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( + getListPredicate(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage().substring(0, 7)))); } - @Test - public void testUploadFileIsEmpty() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = new ByteArrayInputStream( new byte[]{} )) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, - activeVersion002, is, USER1, "csar", "file"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - } + } + + @Test + public void testUploadFileIsEmpty() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream(new byte[]{})) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, + activeVersion002, is, "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); } + } - @Test - public void testMFError() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + @Test + public void testMFError() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { - UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmockBrokenMF"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue( uploadFileResponse.getErrors() - .values().stream() - .filter(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage())).findAny().isPresent()); + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { + UploadFileResponse uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, "csar", "SDCmockBrokenMF"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().values().stream() + .anyMatch(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage()))); - } } + } } |