diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp')
19 files changed, 449 insertions, 329 deletions
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 52b154687b..78cd45cdce 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 @@ -1,5 +1,9 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -10,12 +14,8 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; @@ -36,12 +36,12 @@ public class ImagesTest { @Spy private ImageManagerImpl imageManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ imageManager = null; } @@ -49,7 +49,7 @@ public class ImagesTest { @Test public void createImage() { ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); - doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vendorSoftwareProductInfoDao).isManual(any(), any()); imageManager.createImage(imageEntity); verify(compositionEntityDataManager).createImage(imageEntity); @@ -58,7 +58,7 @@ public class ImagesTest { @Test public void createImageHeat() { ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(), any()); try { imageManager.createImage(imageEntity); 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 b86a1db5d4..ee4b2fa26c 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 @@ -22,7 +22,13 @@ package org.openecomp.sdc.vendorsoftwareproduct; import org.apache.commons.collections4.MapUtils; -import org.mockito.*; +import org.junit.Assert; +import org.junit.Before; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +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; @@ -39,8 +45,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; import java.io.IOException; import java.io.InputStream; @@ -74,7 +78,7 @@ public class QuestionnaireDataServiceTest { private static Version vspActiveVersion; private static final String USER1 = "vspTestUser1"; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } 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 2557da7d6b..b7388b55e8 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 @@ -1,21 +1,25 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import org.mockito.*; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +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.vendorsoftwareproduct.ComponentManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; import org.openecomp.sdc.vendorsoftwareproduct.errors.ComponentDependencyModelErrorBuilder; import org.openecomp.sdc.versioning.dao.types.Version; -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 static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; public class ComponentDependencyModelTest { @@ -37,8 +41,8 @@ public class ComponentDependencyModelTest { @Mock private ComponentDependencyModelDao componentDependencyModelDao; - @BeforeMethod - private void init() { + @Before + public void init() { MockitoAnnotations.initMocks(this); } @@ -100,7 +104,7 @@ public class ComponentDependencyModelTest { createModelEntity(COMP_ID_1, COMP_ID_2); modelEntity.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity); componentDependencyModelManager.update(modelEntity); Mockito.verify(componentDependencyModelDao, Mockito.times(1)).update(modelEntity); @@ -112,7 +116,7 @@ public class ComponentDependencyModelTest { ComponentDependencyModelEntity modelEntity = createModelEntity(null, COMP_ID_1); modelEntity.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity); testUpdateDependency_negative(modelEntity, ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), @@ -121,7 +125,7 @@ public class ComponentDependencyModelTest { ComponentDependencyModelEntity modelEntity1 = createModelEntity("", COMP_ID_1); modelEntity1.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity1); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity1); testUpdateDependency_negative(modelEntity1, ComponentDependencyModelErrorBuilder.getNoSourceComponentErrorBuilder().id(), @@ -134,7 +138,7 @@ public class ComponentDependencyModelTest { createModelEntity(COMP_ID_1, COMP_ID_1); modelEntity.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity); testUpdateDependency_negative(modelEntity, ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().id(), ComponentDependencyModelErrorBuilder.getSourceTargetComponentEqualErrorBuilder().message()); @@ -146,7 +150,7 @@ public class ComponentDependencyModelTest { createModelEntity(COMP_ID_1, COMP_ID_2); modelEntity.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity); componentDependencyModelManager.delete(VSP_ID, VERSION, COMP_DEP_ID); Mockito.verify(componentDependencyModelDao, Mockito.times(1)).delete(modelEntity); @@ -177,7 +181,7 @@ public class ComponentDependencyModelTest { createModelEntity(COMP_ID_1, COMP_ID_2); modelEntity.setId(COMP_DEP_ID); - when(componentDependencyModelDao.get(anyObject())).thenReturn(modelEntity); + when(componentDependencyModelDao.get(any())).thenReturn(modelEntity); ComponentDependencyModelEntity retrieved = componentDependencyModelManager.get(VSP_ID, VERSION, COMP_DEP_ID); 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 7eb593be21..0617464bd1 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 @@ -1,6 +1,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import org.mockito.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.NicManager; @@ -17,17 +25,15 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; public class ComponentManagerImplTest { private static final String VSP_ID = "VSP_ID"; @@ -50,12 +56,12 @@ public class ComponentManagerImplTest { @Spy private ComponentManagerImpl componentManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { componentManager = null; } @@ -66,10 +72,9 @@ public class ComponentManagerImplTest { Assert.assertEquals(components.size(), 0); } - @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) + @Test(expected = CoreException.class) public void validateExceptionWhenTryingToRetriveNotExistingComponentEntity() { - doReturn(null).when(componentDaoMock).get(anyObject()); + doReturn(null).when(componentDaoMock).get(any()); componentManager.validateComponentExistence(VSP_ID, VERSION, COMP1_ID); } @@ -78,7 +83,7 @@ public class ComponentManagerImplTest { doReturn(Arrays.asList( createComponent(VSP_ID, VERSION, COMP1_ID), createComponent(VSP_ID, VERSION, COMP2_ID))) - .when(componentDaoMock).list(anyObject()); + .when(componentDaoMock).list(any()); Collection<ComponentEntity> actual = componentManager.listComponents(VSP_ID, VERSION); Assert.assertEquals(actual.size(), 2); @@ -98,10 +103,10 @@ public class ComponentManagerImplTest { compData.setDescription("comp1 desc"); expected.setComponentCompositionData(compData); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); Collection<ComponentEntity> vspComponentList = new ArrayList<>(); - doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); - doReturn(expected).when(compositionEntityDataManagerMock).createComponent(anyObject(), Matchers.anyBoolean()); + doReturn(vspComponentList).when(componentDaoMock).list(any()); + doReturn(expected).when(compositionEntityDataManagerMock).createComponent(any(), ArgumentMatchers.anyBoolean()); ComponentEntity created = componentManager.createComponent(expected); Assert.assertNotNull(created); @@ -122,10 +127,10 @@ public class ComponentManagerImplTest { compData.setDescription("comp1 desc"); expected.setComponentCompositionData(compData); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); Collection<ComponentEntity> vspComponentList = new ArrayList<>(); vspComponentList.add(expected); - doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(vspComponentList).when(componentDaoMock).list(any()); try { componentManager.createComponent(expected); @@ -144,13 +149,13 @@ public class ComponentManagerImplTest { compData.setDescription("comp1 desc"); expected.setComponentCompositionData(compData); - doReturn(expected).when(componentDaoMock).get(anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(expected).when(componentDaoMock).get(any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); Collection<ComponentEntity> vspComponentList = new ArrayList<>(); vspComponentList.add(expected); - doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(vspComponentList).when(componentDaoMock).list(any()); doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); CompositionEntityValidationData created = componentManager.updateComponent(expected); Assert.assertNotNull(created); @@ -165,16 +170,16 @@ public class ComponentManagerImplTest { compData.setDisplayName("comp1 displayname"); expected.setComponentCompositionData(compData); - doReturn(expected).when(componentDaoMock).get(anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(expected).when(componentDaoMock).get(any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); Collection<ComponentEntity> vspComponentList = new ArrayList<>(); vspComponentList.add(expected); ComponentEntity expected2 = new ComponentEntity(VSP_ID + "2", null, COMP1_ID + "2"); expected2.setComponentCompositionData(compData); vspComponentList.add(expected2); - doReturn(vspComponentList).when(componentDaoMock).list(anyObject()); + doReturn(vspComponentList).when(componentDaoMock).list(any()); doReturn(new CompositionEntityValidationData(null, null)).when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); try { componentManager.updateComponent(expected); @@ -210,7 +215,7 @@ public class ComponentManagerImplTest { @Test public void testUpdateNonExistingComponentId_negative() { String componentId = "non existing component id"; - doReturn(null).when(componentDaoMock).get(anyObject()); + doReturn(null).when(componentDaoMock).get(any()); testUpdate_negative(VSP_ID, VERSION, componentId, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); @@ -219,11 +224,11 @@ public class ComponentManagerImplTest { @Test public void testUpdateOnUploadVsp() { doReturn(createComponent(VSP_ID, VERSION, COMP1_ID)).when(componentDaoMock) - .get(anyObject()); + .get(any()); doReturn(new CompositionEntityValidationData(CompositionEntityType.component, COMP1_ID)) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, COMP1_ID); ComponentData compData = new ComponentData(); @@ -242,14 +247,14 @@ public class ComponentManagerImplTest { @Test public void testIllegalUpdateOnUploadVsp() { doReturn(createComponent(VSP_ID, VERSION, COMP1_ID)) - .when(componentDaoMock).get(anyObject()); + .when(componentDaoMock).get(any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.component, COMP1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, COMP1_ID); ComponentData compData = new ComponentData(); @@ -267,7 +272,7 @@ public class ComponentManagerImplTest { @Test public void testGetNonExistingComponentId_negative() { String componentId = "non existing component id"; - doReturn(null).when(componentDaoMock).get(anyObject()); + doReturn(null).when(componentDaoMock).get(any()); testGet_negative(VSP_ID, VERSION, componentId, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); @@ -276,9 +281,9 @@ public class ComponentManagerImplTest { @Test public void testGet() { ComponentEntity expected = createComponent(VSP_ID, VERSION, COMP1_ID); - doReturn(expected).when(componentDaoMock).get(anyObject()); + doReturn(expected).when(componentDaoMock).get(any()); - doReturn("schema string").when(componentManager).getComponentCompositionSchema(anyObject()); + doReturn("schema string").when(componentManager).getComponentCompositionSchema(any()); testGet(VSP_ID, VERSION, COMP1_ID, expected); } @@ -313,8 +318,7 @@ public class ComponentManagerImplTest { VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } - @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) + @Test(expected = CoreException.class) public void testGetNonExistingComponentQuestionnaire() throws Exception { componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); } @@ -324,7 +328,7 @@ public class ComponentManagerImplTest { doReturn(new ComponentEntity(VSP_ID, VERSION, COMP1_ID)).when(componentDaoMock) .getQuestionnaireData(VSP_ID, VERSION, COMP1_ID); String schema = "schema string"; - doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject()); + doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(any()); QuestionnaireResponse questionnaire = componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); @@ -355,7 +359,7 @@ public class ComponentManagerImplTest { .when(nicManagerMock).listNics(VSP_ID, VERSION, COMP1_ID); String schema = "schema string"; - doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(anyObject()); + doReturn(schema).when(componentManager).getComponentQuestionnaireSchema(any()); QuestionnaireResponse questionnaire = componentManager.getQuestionnaire(VSP_ID, VERSION, COMP1_ID); @@ -365,17 +369,16 @@ public class ComponentManagerImplTest { Assert.assertNull(questionnaire.getErrorMessage()); } - @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = COMP_NOT_EXIST_MSG) + @Test(expected = CoreException.class) public void testUpdateNonExistingComponentQuestionnaire() throws Exception { - doReturn(null).when(componentDaoMock).get(anyObject()); + doReturn(null).when(componentDaoMock).get(any()); componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data"); } @Test public void testUpdateQuestionnaire() throws Exception { ComponentEntity component = createComponent(VSP_ID, VERSION, COMP1_ID); - doReturn(component).when(componentDaoMock).get(anyObject()); + doReturn(component).when(componentDaoMock).get(any()); componentManager.updateQuestionnaire(VSP_ID, VERSION, COMP1_ID, "questionnaire data"); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java index 2713b4ca2f..836767ddda 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/CompositionEntityDataManagerImplTest.java @@ -21,6 +21,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.mockito.Spy; @@ -38,9 +41,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput; import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.ArrayList; import java.util.Collection; @@ -94,12 +94,12 @@ public class CompositionEntityDataManagerImplTest { @Spy private CompositionEntityDataManagerImpl compositionEntityDataManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testAddNullEntity_negative() { compositionEntityDataManager.addEntity(null, null); } @@ -139,8 +139,9 @@ public class CompositionEntityDataManagerImplTest { Assert.assertTrue(errorsById.containsKey(nicId.getParentId())); } - @Test(dependsOnMethods = "testAddEntity") + @Test public void testBuildTrees() { + testAddEntity(); compositionEntityDataManager.buildTrees(); } @@ -249,8 +250,10 @@ public class CompositionEntityDataManagerImplTest { Assert.assertEquals(errorsById.size(), 1); } - @Test(dependsOnMethods = "testNicAndComponentValidQuestionnaire") + @Test public void testComponentInvalidQuestionnaire() { + //JUnit doesn't have depend on logic available + testNicAndComponentValidQuestionnaire(); ComponentEntity componentEntity = new ComponentEntity(VSP1, VERSION, COMPONENT1); componentEntity.setQuestionnaireData(loadFileToString("quesionnaire/invalidComponent.json")); compositionEntityDataManager.addEntity(componentEntity, null); 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 895c9cbd61..ca2c70939d 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,5 +1,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -21,16 +25,17 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.Arrays; import java.util.Collection; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +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; + public class ComputeManagerImplTest { @@ -56,12 +61,12 @@ public class ComputeManagerImplTest { @Spy private ComputeManagerImpl computeManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { computeManager = null; } @@ -78,7 +83,7 @@ public class ComputeManagerImplTest { 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(any()); Collection<ListComputeResponse> computes = @@ -101,7 +106,7 @@ public class ComputeManagerImplTest { @Test public void testCreateManualCompute() { ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); doNothing().when(computeManager) .validateUniqueName(VSP_ID, VERSION, COMPONENT_ID, expected.getComputeCompositionData().getName()); @@ -109,16 +114,16 @@ public class ComputeManagerImplTest { .createUniqueName(VSP_ID, VERSION, COMPONENT_ID, expected.getComputeCompositionData().getName()); String questionnaireSchema = "{}"; - doReturn(questionnaireSchema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + doReturn(questionnaireSchema).when(computeManager).getComputeQuestionnaireSchema(any()); computeManager.createCompute(expected); verify(computeDao).create(expected); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testCreateManualComputeWithDuplicateName() { ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); doThrow(new CoreException( new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) @@ -137,11 +142,11 @@ public class ComputeManagerImplTest { @Test public void testUpdateCompute() { ComputeEntity retrieved = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(retrieved).when(computeDao).get(anyObject()); + doReturn(retrieved).when(computeDao).get(any()); doReturn(new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID)) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); ComputeData computeData = new ComputeData(); @@ -162,16 +167,16 @@ public class ComputeManagerImplTest { @Test public void testIllegalComputeUpdate() { doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) - .when(computeDao).get(anyObject()); + .when(computeDao).get(any()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.compute, COMPUTE1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); ComputeData computeData = new ComputeData(); @@ -190,7 +195,7 @@ public class ComputeManagerImplTest { @Test public void testUpdateHEATComputeName() throws Exception { doReturn(createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID)) - .when(computeDao).get(anyObject()); + .when(computeDao).get(any()); String updatedName = COMPUTE1_ID + " name updated"; CompositionEntityValidationData toBeReturned = @@ -198,7 +203,7 @@ public class ComputeManagerImplTest { toBeReturned.setErrors(Arrays.asList("#/name: "+updatedName+" is not a valid value."+ COMPUTE1_ID+"is the only possible value for this field")); - doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(anyObject(),anyObject(),anyObject()); + doReturn(toBeReturned).when(compositionEntityDataManagerMock).validateEntity(any(),any(),any()); ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); ComputeData computeData = new ComputeData(); @@ -214,8 +219,8 @@ public class ComputeManagerImplTest { @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()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); + doReturn(new ComputeEntity(null, null, null, null)).when(computeDao).get(any()); computeManager .updateComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, json); @@ -231,9 +236,9 @@ public class ComputeManagerImplTest { @Test public void testGet() { ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(expected).when(computeDao).get(anyObject()); + doReturn(expected).when(computeDao).get(any()); String compositionSchema = "schema string"; - doReturn(compositionSchema).when(computeManager).getComputeCompositionSchema(anyObject()); + doReturn(compositionSchema).when(computeManager).getComputeCompositionSchema(any()); CompositionEntityResponse<ComputeData> response = computeManager.getCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); @@ -254,7 +259,7 @@ public class ComputeManagerImplTest { String schema = "schema string"; - doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(anyObject()); + doReturn(schema).when(computeManager).getComputeQuestionnaireSchema(any()); QuestionnaireResponse questionnaire = computeManager.getComputeQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); @@ -268,7 +273,7 @@ public class ComputeManagerImplTest { @Test public void testDeleteOnNotManualCompute() { ComputeEntity expected = createCompute(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID); - doReturn(expected).when(computeDao).get(anyObject()); + doReturn(expected).when(computeDao).get(any()); testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, COMPUTE1_ID, VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } @@ -276,13 +281,13 @@ public class ComputeManagerImplTest { @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()); + doReturn(expected).when(computeDao).get(any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); 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()); + verify(computeDao).delete(any()); } @Test 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 f6c3928d25..4e4e1da096 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,6 +1,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -23,14 +27,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti 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.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; @@ -57,12 +61,12 @@ public class DeploymentFlavorManagerImplTest { @Spy private DeploymentFlavorManagerImpl deploymentFlavorManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { deploymentFlavorManager = null; } @@ -84,11 +88,11 @@ public class DeploymentFlavorManagerImplTest { @Test public void testCreateManualDepFlavor() { DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); vspDetails.setFeatureGroups(fgs); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); deploymentFlavorManager.createDeploymentFlavor(expected); verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected); @@ -97,7 +101,7 @@ public class DeploymentFlavorManagerImplTest { @Test public void testCreateManualDepFlavorWithDuplicateName() { DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); DeploymentFlavorEntity expectedDiffName = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); DeploymentFlavor deploymentFlavor = expectedDiffName.getDeploymentFlavorCompositionData(); @@ -105,7 +109,7 @@ public class DeploymentFlavorManagerImplTest { expectedDiffName.setDeploymentFlavorCompositionData(deploymentFlavor); List<DeploymentFlavorEntity> list = new ArrayList<>(); list.add(expectedDiffName); - doReturn(list).when(deploymentFlavorDaoMock).list(anyObject()); + doReturn(list).when(deploymentFlavorDaoMock).list(any()); try { deploymentFlavorManager.createDeploymentFlavor(expected); @@ -125,7 +129,7 @@ public class DeploymentFlavorManagerImplTest { deploymentFlavor.setFeatureGroupId("fg3"); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); List<String> featureGrps = new ArrayList<>(); featureGrps.add("fg1"); @@ -133,7 +137,7 @@ public class DeploymentFlavorManagerImplTest { VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); vspDetails.setFeatureGroups(featureGrps); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); try { @@ -153,10 +157,10 @@ public class DeploymentFlavorManagerImplTest { deploymentFlavor.setFeatureGroupId(null); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); deploymentFlavorManager.createDeploymentFlavor(expected); verify(compositionEntityDataManagerMock).createDeploymentFlavor(expected); } @@ -174,11 +178,11 @@ public class DeploymentFlavorManagerImplTest { deploymentFlavor.setComponentComputeAssociations(list); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); vspDetails.setFeatureGroups(fgs); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); try { deploymentFlavorManager.createDeploymentFlavor(expected); @@ -204,16 +208,16 @@ public class DeploymentFlavorManagerImplTest { deploymentFlavor.setComponentComputeAssociations(list); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); vspDetails.setFeatureGroups(fgs); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null); - doReturn(component).when(componentDaoMock).get(anyObject()); + doReturn(component).when(componentDaoMock).get(any()); - doReturn(null).when(computeDaoMock).get(anyObject()); + doReturn(null).when(computeDaoMock).get(any()); try { deploymentFlavorManager.createDeploymentFlavor(expected); @@ -237,17 +241,17 @@ public class DeploymentFlavorManagerImplTest { deploymentFlavor.setComponentComputeAssociations(list); expected.setCompositionData(JsonUtil.object2Json(deploymentFlavor)); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); vspDetails.setFeatureGroups(fgs); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); ComponentEntity component = new ComponentEntity(VSP_ID, VERSION, null); - doReturn(component).when(componentDaoMock).get(anyObject()); + doReturn(component).when(componentDaoMock).get(any()); ComputeEntity computeEntity = new ComputeEntity(VSP_ID, VERSION, COMPONENT_ID, "CF1"); - doReturn(computeEntity).when(computeDaoMock).get(anyObject()); + doReturn(computeEntity).when(computeDaoMock).get(any()); try { deploymentFlavorManager.createDeploymentFlavor(expected); @@ -264,7 +268,7 @@ public class DeploymentFlavorManagerImplTest { doReturn(Arrays.asList( createDeploymentFlavor(VSP_ID, VERSION, DF1_ID), createDeploymentFlavor(VSP_ID, VERSION, DF2_ID))) - .when(deploymentFlavorDaoMock).list(anyObject()); + .when(deploymentFlavorDaoMock).list(any()); final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = @@ -284,24 +288,24 @@ public class DeploymentFlavorManagerImplTest { @Test public void testUpdateNonExistingManualDepFlavorId_negative() { - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); testUpdate_negative(VSP_ID, VERSION, DF1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test public void testManualUpdateDepFlavor() { - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); doReturn(createDeploymentFlavor(VSP_ID, VERSION, DF1_ID)) - .when(deploymentFlavorDaoMock).get(anyObject()); + .when(deploymentFlavorDaoMock).get(any()); doReturn(new CompositionEntityValidationData(CompositionEntityType.image, DF1_ID)) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); VspDetails vspDetails = new VspDetails(VSP_ID, VERSION); - doReturn(vspDetails).when(vspInfoDao).get(anyObject()); + doReturn(vspDetails).when(vspInfoDao).get(any()); DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(VSP_ID, VERSION, DF1_ID); @@ -326,7 +330,7 @@ public class DeploymentFlavorManagerImplTest { @Test public void testDeleteDepFlavorOnHEAT() { DeploymentFlavorEntity expected = createDeploymentFlavor(VSP_ID, VERSION, DF1_ID); - doReturn(expected).when(deploymentFlavorDaoMock).get(anyObject()); + doReturn(expected).when(deploymentFlavorDaoMock).get(any()); testDelete_negative(VSP_ID, VERSION, DF1_ID, VendorSoftwareProductErrorCodes.DELETE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @@ -340,10 +344,10 @@ public class DeploymentFlavorManagerImplTest { @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()); + doReturn(expected).when(deploymentFlavorDaoMock).get(any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); deploymentFlavorManager.deleteDeploymentFlavor(VSP_ID, VERSION, DF1_ID); - verify(deploymentFlavorDaoMock).delete(anyObject()); + verify(deploymentFlavorDaoMock).delete(any()); } private void testCreate_negative(DeploymentFlavorEntity deploymentFlavorEntity, 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 6325f983b5..006094cb5e 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,6 +1,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -18,18 +22,16 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; public class ImageManagerImplTest { @@ -63,12 +65,12 @@ public class ImageManagerImplTest { @Spy private ImageManagerImpl imageManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { imageManager = null; } @@ -84,7 +86,7 @@ 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, IMAGE2_ID))).when(imageDao).list(any()); final Collection<ImageEntity> images = imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID); @@ -105,7 +107,7 @@ public class ImageManagerImplTest { @Test public void testCreateManualImage() { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); imageManager.createImage(expected); verify(compositionEntityDataManagerMock).createImage(expected); verify(compositionEntityDataManagerMock).createImage(expected); @@ -119,10 +121,10 @@ public class ImageManagerImplTest { @Test public void testUpdateImage() { - doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject()); + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any()); doReturn(new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID)) - .when(compositionEntityDataManagerMock).validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock).validateEntity(any(), any(), any()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -137,15 +139,15 @@ public class ImageManagerImplTest { @Test public void testIllegalImageUpdate() { - doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject()); + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned).when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -162,7 +164,7 @@ public class ImageManagerImplTest { @Test public void testUpdateHEATImageFileName() throws Exception { - doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(anyObject()); + doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)).when(imageDao).get(any()); String updatedName = IMAGE1_ID + " name updated"; CompositionEntityValidationData toBeReturned = @@ -171,7 +173,7 @@ public class ImageManagerImplTest { toBeReturned.setErrors(Arrays.asList("#/name: " + updatedName + " is not a valid value." + IMAGE1_ID + "is the only possible value for this field")); doReturn(toBeReturned).when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -193,9 +195,9 @@ public class ImageManagerImplTest { @Test public void testGet() { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); - doReturn(expected).when(imageDao).get(anyObject()); + doReturn(expected).when(imageDao).get(any()); String compositionSchema = "schema string"; - doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(anyObject()); + doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(any()); CompositionEntityResponse<Image> response = imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Assert.assertEquals(response.getId(), expected.getId()); @@ -208,7 +210,7 @@ public class ImageManagerImplTest { @Test public void testDeleteOnNotManualImage() { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); - doReturn(expected).when(imageDao).get(anyObject()); + doReturn(expected).when(imageDao).get(any()); testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, VendorSoftwareProductErrorCodes.DELETE_IMAGE_NOT_ALLOWED); } @@ -222,10 +224,10 @@ public class ImageManagerImplTest { @Test public void testDeleteOnManualImage() { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); - doReturn(expected).when(imageDao).get(anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + doReturn(expected).when(imageDao).get(any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); imageManager.deleteImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); - verify(imageDao).delete(anyObject()); + verify(imageDao).delete(any()); } @Test @@ -235,7 +237,7 @@ public class ImageManagerImplTest { doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); String schema = "schema string"; - doReturn(schema).when(imageManager).getImageQuestionnaireSchema(anyObject()); + doReturn(schema).when(imageManager).getImageQuestionnaireSchema(any()); QuestionnaireResponse questionnaire = imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); @@ -248,8 +250,8 @@ public class ImageManagerImplTest { @Test public void testUpdateManualImageQuestionnaire() throws Exception { String json = "{\"md5\" :\"FFDSD33SS\"}"; - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); - doReturn(new ImageEntity()).when(imageDao).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); + doReturn(new ImageEntity()).when(imageDao).get(any()); imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); verify(imageDao).updateQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); @@ -267,13 +269,13 @@ public class ImageManagerImplTest { add(imageEntity); }}; - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); - doReturn(imageEntity).when(imageDao).get(anyObject()); - doReturn(imageEntities).when(imageDao).list(anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); + doReturn(imageEntity).when(imageDao).get(any()); + doReturn(imageEntities).when(imageDao).list(any()); doReturn(imageEntities.get(0)).when(imageDao) - .getQuestionnaireData(anyObject(), anyObject(), anyObject(), anyObject()); + .getQuestionnaireData(any(), any(), any(), any()); - doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(anyObject()); + doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(any()); imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, json); Assert.fail(); @@ -289,10 +291,10 @@ public class ImageManagerImplTest { String json = "{\"format\" :\"qcow2\"}"; ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); image.setQuestionnaireData(json); - doReturn(image).when(imageDao).get(anyObject()); + doReturn(image).when(imageDao).get(any()); - doReturn(false).when(vspInfoDao).isManual(anyObject(), anyObject()); - doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(anyObject()); + doReturn(false).when(vspInfoDao).isManual(any(), any()); + doReturn(IMAGE_QUEST_SCHEMA).when(imageManager).getImageQuestionnaireSchema(any()); doReturn(image).when(imageDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); String updJson = "{\"format\" :\"aki\"}"; try { @@ -308,7 +310,7 @@ public class ImageManagerImplTest { String json = "{\"format\" :\"qcow2\"}"; ImageEntity image = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); image.setQuestionnaireData(json); - doReturn(image).when(imageDao).get(anyObject()); + doReturn(image).when(imageDao).get(any()); String updJson = "{\"format\" :\"a22\"}"; try { 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 817955efc3..4c4d4f7e9d 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 @@ -1,5 +1,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -9,10 +13,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.IOException; import java.io.InputStream; @@ -21,9 +21,10 @@ import java.util.Arrays; import java.util.Optional; import java.util.function.Consumer; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; public class MonitoringUploadsManagerImplTest { @@ -44,17 +45,17 @@ public class MonitoringUploadsManagerImplTest { @InjectMocks private MonitoringUploadsManagerImpl monitoringUploadsManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ monitoringUploadsManager = null; } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testUploadEmptyZip() { processFile(ZIP_DIR + EMPTY_ZIP_FILE_NAME, inputStream -> monitoringUploadsManager @@ -62,8 +63,7 @@ public class MonitoringUploadsManagerImplTest { MonitoringUploadType.SNMP_TRAP)); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = - "Invalid zip file") + @Test(expected = CoreException.class) public void testUploadInvalidZip() { processFile("/notZipFile", inputStream -> monitoringUploadsManager @@ -118,7 +118,7 @@ public class MonitoringUploadsManagerImplTest { artifact3.setArtifactName(VES_FILE_NAME); doReturn(Arrays.asList(artifact1, artifact2, artifact3)) - .when(componentArtifactDaoMock).list(anyObject()); + .when(componentArtifactDaoMock).list(any()); MonitoringUploadStatus monitoringUploadStatus = monitoringUploadsManager.listFilenames(VSP_ID, VERSION, COMPONENT_ID); @@ -128,13 +128,13 @@ public class MonitoringUploadsManagerImplTest { Assert.assertEquals(monitoringUploadStatus.getVesEvent(), VES_FILE_NAME); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testDeleteComponentMibWhenNone() { doReturn(Optional.empty()).when(componentArtifactDaoMock).getByType(any()); monitoringUploadsManager .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL); - verify(componentArtifactDaoMock, never()).delete(anyObject()); + verify(componentArtifactDaoMock, never()).delete(any()); } @Test @@ -142,12 +142,12 @@ public class MonitoringUploadsManagerImplTest { doReturn(Optional .of(new ComponentMonitoringUploadEntity(VSP_ID, VERSION, COMPONENT_ID, "artifactId"))) .when - (componentArtifactDaoMock).getByType(anyObject()); + (componentArtifactDaoMock).getByType(any()); monitoringUploadsManager .delete(VSP_ID, VERSION, COMPONENT_ID, MonitoringUploadType.SNMP_POLL); - verify(componentArtifactDaoMock).delete(anyObject()); + verify(componentArtifactDaoMock).delete(any()); } 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 a12b1219e8..8e7423cab2 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 @@ -17,6 +17,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -34,16 +38,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEnti import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.Arrays; import java.util.Collection; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; public class NetworkManagerImplTest { @@ -74,13 +76,13 @@ public class NetworkManagerImplTest { return networkEntity; } - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); SessionContextProviderFactory.getInstance().createInterface().create(USER_ID, tenant); } - @AfterMethod + @After public void tearDown() { networkManager = null; SessionContextProviderFactory.getInstance().createInterface().close(); @@ -98,7 +100,7 @@ public class NetworkManagerImplTest { doReturn(Arrays.asList( createNetwork(VSP_ID, VERSION, NETWORK1_ID), createNetwork(VSP_ID, VERSION, NETWORK2_ID))) - .when(networkDaoMock).list(anyObject()); + .when(networkDaoMock).list(any()); Collection<NetworkEntity> actual = networkManager.listNetworks(VSP_ID, VERSION); Assert.assertEquals(actual.size(), 2); @@ -119,15 +121,15 @@ public class NetworkManagerImplTest { @Test public void testIllegalUpdateOnUploadVsp() { doReturn(createNetwork(VSP_ID, VERSION, NETWORK1_ID)) - .when(networkDaoMock).get(anyObject()); + .when(networkDaoMock).get(any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.network, NETWORK1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject()); + .validateEntity(any(), any(), any()); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any()); NetworkEntity networkEntity = new NetworkEntity(VSP_ID, VERSION, NETWORK1_ID); Network networkData = new Network(); @@ -153,9 +155,9 @@ public class NetworkManagerImplTest { public void testGet() { NetworkEntity network = createNetwork(VSP_ID, VERSION, NETWORK1_ID); doReturn(network) - .when(networkDaoMock).get(anyObject()); - doReturn("schema string").when(networkManager).getCompositionSchema(anyObject()); - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject()); + .when(networkDaoMock).get(any()); + doReturn("schema string").when(networkManager).getCompositionSchema(any()); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any()); CompositionEntityResponse<Network> response = networkManager.getNetwork(VSP_ID, VERSION, NETWORK1_ID); @@ -164,15 +166,16 @@ public class NetworkManagerImplTest { Assert.assertNotNull(response.getSchema()); } - @Test(dependsOnMethods = "testList") + @Test public void testDeleteOnUploadVsp_negative() { + testList(); testDelete_negative(VSP_ID, VERSION, NETWORK1_ID, VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED); } private void testCreate_negative(NetworkEntity network, String expectedErrorCode) { try { - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject()); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any()); networkManager.createNetwork(network); Assert.fail(); } catch (CoreException exception) { @@ -212,7 +215,7 @@ public class NetworkManagerImplTest { private void testDelete_negative(String vspId, Version version, String networkId, String expectedErrorCode) { try { - doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(),anyObject()); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(),any()); networkManager.deleteNetwork(vspId, version, networkId); Assert.fail(); } catch (CoreException exception) { 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 b095acf6bb..4aca9aeabc 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 @@ -16,6 +16,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -36,17 +40,15 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; public class NicManagerImplTest { @@ -74,12 +76,12 @@ public class NicManagerImplTest { @Spy private NicManagerImpl nicManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { nicManager = null; } @@ -95,7 +97,7 @@ public class NicManagerImplTest { doReturn(Arrays.asList( createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID), createNic(VSP_ID, VERSION, COMPONENT_ID, NIC2_ID, NETWORK2_ID))) - .when(nicDao).list(anyObject()); + .when(nicDao).list(any()); NetworkEntity network1 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK1_ID); NetworkEntity network2 = NetworkManagerImplTest.createNetwork(VSP_ID, VERSION, NETWORK2_ID); @@ -118,10 +120,10 @@ 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(any(), any()); Collection<NicEntity> nicEntities = new ArrayList<>(); - doReturn(nicEntities).when(nicDao).list(anyObject()); - doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + doReturn(nicEntities).when(nicDao).list(any()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any()); NicEntity created = nicManager.createNic(nicEntity); Assert.assertNotNull(created); @@ -133,7 +135,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(any(), any()); Collection<NicEntity> nicEntities = new ArrayList<>(); NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); @@ -141,8 +143,8 @@ public class NicManagerImplTest { newNameNic.setName(NIC1_ID + "_Name/*"); nicEntityDiffName.setNicCompositionData(newNameNic); nicEntities.add(nicEntityDiffName); - doReturn(nicEntities).when(nicDao).list(anyObject()); - doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + doReturn(nicEntities).when(nicDao).list(any()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any()); try { NicEntity created = nicManager.createNic(nicEntity); @@ -158,7 +160,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(any(), any()); Collection<NicEntity> nicEntities = new ArrayList<>(); NicEntity nicEntityDiffName = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); @@ -166,8 +168,8 @@ public class NicManagerImplTest { newNameNic.setName(NIC1_ID + "_Name"); nicEntityDiffName.setNicCompositionData(newNameNic); nicEntities.add(nicEntityDiffName); - doReturn(nicEntities).when(nicDao).list(anyObject()); - doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + doReturn(nicEntities).when(nicDao).list(any()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any()); try { NicEntity created = nicManager.createNic(nicEntity); @@ -186,10 +188,10 @@ 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(any(), any()); Collection<NicEntity> nicEntities = new ArrayList<>(); - doReturn(nicEntities).when(nicDao).list(anyObject()); - doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + doReturn(nicEntities).when(nicDao).list(any()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any()); try { NicEntity created = nicManager.createNic(nicEntity); @@ -209,10 +211,10 @@ 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(any(), any()); Collection<NicEntity> nicEntities = new ArrayList<>(); - doReturn(nicEntities).when(nicDao).list(anyObject()); - doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(anyObject()); + doReturn(nicEntities).when(nicDao).list(any()); + doReturn(nicEntity).when(compositionEntityDataManagerMock).createNic(any()); try { NicEntity created = nicManager.createNic(nicEntity); @@ -227,8 +229,8 @@ public class NicManagerImplTest { @Test public void testDeleteNic() { NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); - doReturn(nicEntity).when(nicDao).get(anyObject()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); + doReturn(nicEntity).when(nicDao).get(any()); nicManager.deleteNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); @@ -238,8 +240,8 @@ public class NicManagerImplTest { public void testUpdateNicQuestionnaire() { NicEntity nicEntity = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); - doReturn(nicEntity).when(nicDao).get(anyObject()); - doReturn("{}").when(nicManager).getNicCompositionSchema(anyObject()); + doReturn(nicEntity).when(nicDao).get(any()); + doReturn("{}").when(nicManager).getNicCompositionSchema(any()); nicManager .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "Ques"); @@ -287,7 +289,7 @@ public class NicManagerImplTest { @Test public void testUpdateNonExistingNicId_negative() { - doReturn(null).when(nicDao).get(anyObject()); + doReturn(null).when(nicDao).get(any()); testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); @@ -296,11 +298,11 @@ public class NicManagerImplTest { @Test public void testUpdateOnUploadVsp() { doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID)) - .when(nicDao).get(anyObject()); + .when(nicDao).get(any()); doReturn(new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID)) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Nic nicData = new Nic(); @@ -318,14 +320,14 @@ public class NicManagerImplTest { @Test public void testIllegalUpdateOnUploadVsp() { doReturn(createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID)) - .when(nicDao).get(anyObject()); + .when(nicDao).get(any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .validateEntity(any(), any(), any()); NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Nic nicData = new Nic(); @@ -344,15 +346,15 @@ 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(any()); CompositionEntityValidationData toBeReturned = new CompositionEntityValidationData(CompositionEntityType.nic, NIC1_ID); toBeReturned.setErrors(Arrays.asList("Field does not conform to predefined criteria:name : must match [a-zA-Z0-9_]*$")); doReturn(toBeReturned) .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); - doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); + .validateEntity(any(), any(), any()); + doReturn(true).when(vspInfoDao).isManual(any(), any()); NicEntity nicEntity = new NicEntity(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); Nic nicData = new Nic(); @@ -377,9 +379,9 @@ public class NicManagerImplTest { @Test public void testGet() { NicEntity expected = createNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, NETWORK1_ID); - doReturn(expected).when(nicDao).get(anyObject()); + doReturn(expected).when(nicDao).get(any()); String compositionSchema = "schema string"; - doReturn(compositionSchema).when(nicManager).getNicCompositionSchema(anyObject()); + doReturn(compositionSchema).when(nicManager).getNicCompositionSchema(any()); CompositionEntityResponse<Nic> response = nicManager.getNic(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); @@ -418,8 +420,7 @@ public class NicManagerImplTest { VendorSoftwareProductErrorCodes.DELETE_NIC_NOT_ALLOWED); } - @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = NIC_NOT_EXIST_MSG) + @Test(expected = CoreException.class) public void testGetNonExistingNicQuestionnaire() throws Exception { nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); } @@ -431,7 +432,7 @@ public class NicManagerImplTest { doReturn(nic).when(nicDao).getQuestionnaireData(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); String schema = "schema string"; - doReturn(schema).when(nicManager).getNicQuestionnaireSchema(anyObject()); + doReturn(schema).when(nicManager).getNicQuestionnaireSchema(any()); QuestionnaireResponse questionnaire = nicManager.getNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID); @@ -441,10 +442,9 @@ public class NicManagerImplTest { Assert.assertNull(questionnaire.getErrorMessage()); } - @Test(expectedExceptions = CoreException.class, - expectedExceptionsMessageRegExp = NIC_NOT_EXIST_MSG) + @Test(expected = CoreException.class) public void testUpdateNonExistingNicQuestionnaire() throws Exception { - doReturn(null).when(nicDao).get(anyObject()); + doReturn(null).when(nicDao).get(any()); nicManager .updateNicQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, NIC1_ID, "questionnaire data"); } 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 b56098fb43..8f33be131c 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 @@ -16,6 +16,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -38,20 +42,20 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStru import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; import java.nio.ByteBuffer; -import java.util.*; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; public class OrchestrationTemplateCandidateManagerImplTest { private static final String VSP_ID = "vspId"; @@ -89,22 +93,18 @@ public class OrchestrationTemplateCandidateManagerImplTest { @InjectMocks private OrchestrationUtil orchestrationUtil; - @BeforeClass + @Before public void setUp() { MockitoAnnotations.initMocks(this); } - @AfterMethod - private void resetMocks() { + @After + public void resetMocks() { Mockito.reset(vspInfoDaoMock); Mockito.reset(candidateServiceMock); Mockito.reset(orchestrationTemplateDaoMock); Mockito.reset(componentDependencyModelDaoMock); Mockito.reset(componentDaoMock); - } - - @AfterClass - public void tearDown() { candidateManager = null; orchestrationUtil = null; } @@ -203,7 +203,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn(initialVspComponents).when(componentDaoMock).list(any()); Map<String, String> vspComponentIdNameInfo = orchestrationUtil.getVspComponentIdNameInfo(VSP_ID, VERSION01); - Assert.assertEquals(vspComponentIdNameInfo.size(), 0); + assertEquals(vspComponentIdNameInfo.size(), 0); } @Test @@ -240,7 +240,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testGetComponentDependenciesBeforeDeleteInvalid() { Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete = orchestrationUtil.getComponentDependenciesBeforeDelete(null, null); - Assert.assertEquals(componentDependenciesBeforeDelete.size(), 0); + assertEquals(componentDependenciesBeforeDelete.size(), 0); } @Test @@ -250,7 +250,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn(existingComponentsDependencies).when(componentDependencyModelDaoMock).list(any()); Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete = orchestrationUtil.getComponentDependenciesBeforeDelete(VSP_ID, VERSION01); - Assert.assertEquals(componentDependenciesBeforeDelete.size(), 2); + assertEquals(componentDependenciesBeforeDelete.size(), 2); } @Test 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 17bc2a3fb8..fdfa7d528a 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 @@ -16,7 +16,16 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import org.mockito.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +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.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; @@ -26,10 +35,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.ByteArrayInputStream; import java.io.File; @@ -37,9 +42,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.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.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; public class ProcessManagerImplTest { @@ -60,12 +69,12 @@ public class ProcessManagerImplTest { @Captor private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { processManager = null; } @@ -133,7 +142,7 @@ public class ProcessManagerImplTest { Assert.assertEquals(process, processToCreate); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testCreateWithExistingName_negative() { ProcessEntity process = createProcess(VSP_ID, VERSION, COMPONENT_ID, null); process.setName("p1 name"); @@ -153,7 +162,7 @@ public class ProcessManagerImplTest { VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testUpdateWithExistingName_negative() { ProcessEntity existingProcess = createProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); doReturn(existingProcess).when(processDaoMock).get(any(ProcessEntity.class)); @@ -210,7 +219,7 @@ public class ProcessManagerImplTest { Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testDeleteNonExistingProcessId_negative() { processManager.deleteProcess(VSP_ID, VERSION, COMPONENT_ID, PROCESS1_ID); } 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 6e9d1ea83c..3900059234 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 @@ -16,7 +16,17 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import org.mockito.*; +import org.apache.commons.io.IOUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +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.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.factory.impl.AbstractFactoryBase; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -33,9 +43,21 @@ import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService; -import org.openecomp.sdc.vendorsoftwareproduct.*; -import org.openecomp.sdc.vendorsoftwareproduct.dao.*; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager; +import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; +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.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +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.types.UploadFileResponse; @@ -46,10 +68,6 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.VersionInfo; import org.openecomp.sdc.versioning.types.VersionableEntityAction; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.File; import java.io.FileInputStream; @@ -57,13 +75,27 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.ByteBuffer; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.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; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; + public class VendorSoftwareProductManagerImplTest { @@ -116,16 +148,60 @@ public class VendorSoftwareProductManagerImplTest { @Captor private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; - @BeforeMethod + @Before public void setUp() { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown() { vendorSoftwareProductManager = null; } + @Test + public void testCreatePackageEtsi(){ + try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"); + InputStream manifestInput = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) { + + FileContentHandler handler = new FileContentHandler(); + handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput)); + handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput)); + ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), ""); + when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata ); + VspDetails vsp = + createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon", + "category", "subCategory", "123", null); + //want to avoid triggering populateVersionsForVlm method + vsp.setVlmVersion(null); + + when(vspInfoDaoMock.get(any())).thenReturn(vsp); + when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler()); + vendorSoftwareProductManager.createPackage("0", new Version()); + } catch (IOException e) { + fail(); + } + } + + @Test(expected = IOException.class) + public void testCreatePackageEtsiNoManifest() throws IOException { + try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta")) + { + FileContentHandler handler = new FileContentHandler(); + handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput)); + ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), ""); + when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata ); + VspDetails vsp = + createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon", + "category", "subCategory", "123", null); + //want to avoid triggering populateVersionsForVlm method + vsp.setVlmVersion(null); + + when(vspInfoDaoMock.get(any())).thenReturn(vsp); + when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler()); + vendorSoftwareProductManager.createPackage("0", new Version()); + fail(); + } + } @Test public void testCreate() { @@ -145,7 +221,7 @@ public class VendorSoftwareProductManagerImplTest { assertVspsEquals(vsp, vspToCreate); } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testUpdateWithExistingName_negative() { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); @@ -238,7 +314,7 @@ public class VendorSoftwareProductManagerImplTest { } - @Test(expectedExceptions = CoreException.class) + @Test(expected = CoreException.class) public void testGetNonExistingVersion_negative() { Version notExistversion = new Version("43, 8"); doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class)); 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 ea2d068bfd..c67c30c73c 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 @@ -20,15 +20,19 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -44,9 +48,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.Module; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; + /** * @author Avrahamg @@ -58,7 +60,7 @@ public class CandidateServiceImplTest { @InjectMocks private CandidateServiceImpl candidateService; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } 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 9aabef6234..c6b4314629 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImplTest.java @@ -26,6 +26,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; @@ -36,9 +39,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; /** * @author shiria @@ -50,7 +50,7 @@ public class CompositionDataExtractorImplTest { @InjectMocks private static CompositionDataExtractorImpl compositionDataExtractor; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java index 61c8f0515f..6b1493f001 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java @@ -16,6 +16,8 @@ package org.openecomp.sdc.vendorsoftwareproduct.tree; +import org.junit.Assert; +import org.junit.Test; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; @@ -23,10 +25,11 @@ import org.openecomp.sdc.heat.services.tree.HeatTreeManager; import java.io.IOException; import java.net.URISyntaxException; -import java.util.*; -import org.testng.Assert; -import org.testng.annotations.Test; - +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; public class HeatTreeManagerTest extends TreeBaseTest { 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 10f09260ef..c21358519a 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,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.tree; -import static org.mockito.Matchers.any; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; -import static org.testng.Assert.assertEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -32,6 +32,9 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.zip.ZipOutputStream; + +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -52,8 +55,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; public class UploadFileTest { private static final String USER1 = "vspTestUser1"; @@ -85,7 +86,7 @@ public class UploadFileTest { public static Version activeVersion002 = null; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } 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 42b7dc37d4..b772c69f4a 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 @@ -17,10 +17,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; -import static org.mockito.Matchers.any; +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.File; @@ -28,6 +28,9 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.function.Predicate; + +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -42,8 +45,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremo import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.versioning.dao.types.Version; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; public class UploadCSARFileTest { @@ -68,7 +69,7 @@ public class UploadCSARFileTest { private static final String CSAR = "csar"; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); candidateService = new CandidateServiceImpl(manifestCreator, orchestrationTemplateCandidateDao); |