From cd6f933375c412c2f79a12e909821322d58a8499 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 29 Jan 2020 17:25:21 +0000 Subject: Configure a new Artifact Type Centralizes artifact configuration in one yaml entry. Allow the configuration of a new artifact type without the need of code changes. The configuration file now is used as a source of artifacts types instead the artifact type enum. The enum will be used as a source of base artifact types and also in hard coded business rules. Change-Id: Id0383d9fca9bce0519a4d52a4ecb3a68c8713f0f Issue-ID: SDC-2754 Signed-off-by: andre.schmid --- .../operations/impl/ElementOperationTest.java | 96 ++++++++-------------- 1 file changed, 33 insertions(+), 63 deletions(-) (limited to 'catalog-model/src/test/java/org') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java index 17e2430d82..3597d02834 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java @@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.openecomp.sdc.be.config.ArtifactConfiguration; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; @@ -47,6 +48,7 @@ import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) @@ -64,52 +66,44 @@ public class ElementOperationTest extends ModelTestBase { @BeforeClass public static void setupBeforeClass() { - // ExternalConfiguration.setAppName("catalog-model"); - // String appConfigDir = "src/test/resources/config/catalog-model"; - // ConfigurationSource configurationSource = new - // FSConfigurationSource(ExternalConfiguration.getChangeListener(), - // appConfigDir); - ModelTestBase.init(); - } @Test public void testGetArtifactsTypes() { - - List artifactTypesCfg = new ArrayList<>(); - artifactTypesCfg.add("type1"); - artifactTypesCfg.add("type2"); - artifactTypesCfg.add("type3"); - artifactTypesCfg.add("type4"); - configurationManager.getConfiguration().setArtifactTypes(artifactTypesCfg); - Either, ActionStatus> allArtifactTypes = elementOperation.getAllArtifactTypes(); - assertTrue(allArtifactTypes.isLeft()); - assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size()); - - artifactTypesCfg.remove(0); - allArtifactTypes = elementOperation.getAllArtifactTypes(); - assertTrue(allArtifactTypes.isLeft()); - assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size()); - - artifactTypesCfg.add("type5"); + final List expectedArtifactConfigurationList = new ArrayList<>(); + final ArtifactConfiguration artifactConfiguration1 = new ArtifactConfiguration(); + artifactConfiguration1.setType("type1"); + expectedArtifactConfigurationList.add(artifactConfiguration1); + final ArtifactConfiguration artifactConfiguration2 = new ArtifactConfiguration(); + artifactConfiguration2.setType("type2"); + expectedArtifactConfigurationList.add(artifactConfiguration2); + final ArtifactConfiguration artifactConfiguration3 = new ArtifactConfiguration(); + artifactConfiguration3.setType("type3"); + expectedArtifactConfigurationList.add(artifactConfiguration3); + configurationManager.getConfiguration().setArtifacts(expectedArtifactConfigurationList); + + List actualArtifactTypes = elementOperation.getAllArtifactTypes(); + assertNotNull(actualArtifactTypes); + assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size()); + boolean allMatch = actualArtifactTypes.stream().allMatch(artifactType -> + expectedArtifactConfigurationList.stream() + .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName())) + ); + assertTrue(allMatch); + + expectedArtifactConfigurationList.remove(0); + actualArtifactTypes = elementOperation.getAllArtifactTypes(); + assertNotNull(actualArtifactTypes); + assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size()); + + allMatch = actualArtifactTypes.stream().allMatch(artifactType -> + expectedArtifactConfigurationList.stream() + .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName())) + ); + assertTrue(allMatch); } - @Test - public void testAllDeploymentArtifactTypes() { - - List artifactTypesCfg = new ArrayList(); - artifactTypesCfg.add("type1"); - artifactTypesCfg.add("type2"); - artifactTypesCfg.add("type3"); - configurationManager.getConfiguration().setArtifactTypes(artifactTypesCfg); - Either, ActionStatus> allDeploymentArtifactTypes = elementOperation - .getAllDeploymentArtifactTypes(); - assertTrue(allDeploymentArtifactTypes.isLeft()); - assertEquals(artifactTypesCfg.size(), allDeploymentArtifactTypes.left().value().size()); - - } - // @Test public void testGetResourceAndServiceCategoty() { String id = OperationTestsUtil.deleteAndCreateResourceCategory(CATEGORY, SUBCATEGORY, janusGraphDao); @@ -431,29 +425,6 @@ public class ElementOperationTest extends ModelTestBase { testSubject = createTestSubject(); result = testSubject.getAllPropertyScopes(); } - - - @Test - public void testGetAllArtifactTypes() throws Exception { - ElementOperation testSubject; - Either, ActionStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAllArtifactTypes(); - } - - - @Test - public void testGetAllDeploymentArtifactTypes() throws Exception { - ElementOperation testSubject; - Either, ActionStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAllDeploymentArtifactTypes(); - } - @Test public void testGetResourceTypesMap() throws Exception { @@ -465,7 +436,6 @@ public class ElementOperationTest extends ModelTestBase { result = testSubject.getResourceTypesMap(); } - @Test public void testGetNewCategoryData() throws Exception { ElementOperation testSubject; -- cgit 1.2.3-korg