diff options
Diffstat (limited to 'catalog-model/src')
10 files changed, 188 insertions, 52 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java index 5c88101b2f..584edad022 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java @@ -33,7 +33,7 @@ public class BaseType { @Setter private String toscaResourceName; - private List<Semver> versions = new ArrayList<>(); + private final List<Semver> versions = new ArrayList<>(); public BaseType(final String toscaResourceName) { this.toscaResourceName = toscaResourceName; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index e0ca719005..1c0cfc4c5d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -638,6 +638,11 @@ public abstract class Component implements PropertiesOwner { } public void setDerivedFromGenericInfo(Resource genericType) { + if (genericType == null) { + derivedFromGenericType = null; + derivedFromGenericVersion = null; + return; + } derivedFromGenericType = genericType.getToscaResourceName(); derivedFromGenericVersion = genericType.getVersion(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java index a06f737c83..bc8efb528d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java @@ -19,16 +19,15 @@ */ package org.openecomp.sdc.be.model; -import static java.util.Optional.ofNullable; - import java.util.HashMap; -import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.config.CategoryBaseTypeConfig; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition; @@ -143,7 +142,7 @@ public class Service extends Component { } private ServiceMetadataDataDefinition getServiceMetadataDefinition() { - return (ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition(); + return getMetadataDefinition(); } public String getServiceFunction() { @@ -167,9 +166,18 @@ public class Service extends Component { } private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) { - final Map<String, List<String>> serviceNodeTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); - final List<String> stringList = ofNullable(serviceNodeTypes).map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null); - return stringList != null ? stringList.get(0) : null; + final Map<String, CategoryBaseTypeConfig> serviceNodeTypesConfig = + ConfigurationManager.getConfigurationManager().getConfiguration().getServiceBaseNodeTypes(); + if (serviceNodeTypesConfig == null) { + return null; + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = serviceNodeTypesConfig.get(serviceCategory); + if (categoryBaseTypeConfig == null || CollectionUtils.isEmpty(categoryBaseTypeConfig.getBaseTypes())) { + return null; + } + + return categoryBaseTypeConfig.getBaseTypes().get(0); } @Override @@ -182,14 +190,22 @@ public class Service extends Component { } public void setAbstract(Boolean isAbstract) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setIsAbstract(isAbstract); + getMetadataDefinition().setIsAbstract(isAbstract); } public void setVendorName(String vendorName) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorName(vendorName); + getMetadataDefinition().setVendorName(vendorName); } public void setVendorRelease(String vendorRelease) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorRelease(vendorRelease); + getMetadataDefinition().setVendorRelease(vendorRelease); + } + + public boolean isSubstituteCandidate() { + return getDerivedFromGenericType() != null; + } + + private ServiceMetadataDataDefinition getMetadataDefinition() { + return (ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition(); } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java index 7457ed727e..ebc563268e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java @@ -86,7 +86,15 @@ public interface IElementOperation { Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction); - List<BaseType> getBaseTypes(String categoryName, String modelName); + List<BaseType> getServiceBaseTypes(String categoryName, String modelName); + + /** + * Checks if a category requires a base type. + * + * @param categoryName the category name + * @return {@code true} if a base type is required, {@code false} otherwise. + */ + boolean isBaseTypeRequired(String categoryName); Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java index b98f8d9dea..127d778f73 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java @@ -21,19 +21,24 @@ package org.openecomp.sdc.be.model.operations.impl; import fj.data.Either; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphVertex; import org.openecomp.sdc.be.config.ArtifactConfigManager; import org.openecomp.sdc.be.config.ArtifactConfiguration; +import org.openecomp.sdc.be.config.CategoryBaseTypeConfig; import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -382,13 +387,18 @@ public class ElementOperation implements IElementOperation { } @Override - public List<BaseType> getBaseTypes(final String categoryName, final String modelName) { - final ArrayList<BaseType> baseTypes = new ArrayList<>(); - final Map<String, List<String>> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); - final List<String> categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName); - final String generalBaseType = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get("Service"); - final List<String> baseToscaResourceNames = categorySpecificBaseType == null ? List.of(generalBaseType) : categorySpecificBaseType; + public List<BaseType> getServiceBaseTypes(final String categoryName, final String modelName) { + + final CategoryBaseTypeConfig categoryBaseTypeConfig = getCategoryBaseTypeConfig(categoryName).orElse(null); + final List<String> baseToscaResourceNames; + if (categoryBaseTypeConfig == null) { + final String generalBaseType = getConfiguration().getGenericAssetNodeTypes().get("Service"); + baseToscaResourceNames = List.of(generalBaseType); + } else { + baseToscaResourceNames = getCategoryBaseTypes(categoryName); + } + final ArrayList<BaseType> baseTypes = new ArrayList<>(); baseToscaResourceNames.forEach(baseToscaResourceName -> { final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class); props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); @@ -413,6 +423,48 @@ public class ElementOperation implements IElementOperation { return baseTypes; } + private Configuration getConfiguration() { + return ConfigurationManager.getConfigurationManager().getConfiguration(); + } + + @Override + public boolean isBaseTypeRequired(final String categoryName) { + final Map<String, CategoryBaseTypeConfig> categoriesSpecificBaseTypeMap = getConfiguration().getServiceBaseNodeTypes(); + if (MapUtils.isEmpty(categoriesSpecificBaseTypeMap)) { + return true; + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = categoriesSpecificBaseTypeMap.get(categoryName); + if (categoryBaseTypeConfig == null) { + return true; + } + + return categoryBaseTypeConfig.isRequired(); + } + + private List<String> getCategoryBaseTypes(final String categoryName) { + final Optional<CategoryBaseTypeConfig> categoryBaseTypeConfigOptional = getCategoryBaseTypeConfig(categoryName); + if (categoryBaseTypeConfigOptional.isEmpty()) { + return Collections.emptyList(); + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = categoryBaseTypeConfigOptional.get(); + if (CollectionUtils.isEmpty(categoryBaseTypeConfig.getBaseTypes())) { + return Collections.emptyList(); + } + + return categoryBaseTypeConfig.getBaseTypes(); + } + + private Optional<CategoryBaseTypeConfig> getCategoryBaseTypeConfig(final String categoryName) { + final Map<String, CategoryBaseTypeConfig> categoriesSpecificBaseTypes = getConfiguration().getServiceBaseNodeTypes(); + if (categoriesSpecificBaseTypes == null) { + return Optional.empty(); + } + + return Optional.ofNullable(categoriesSpecificBaseTypes.get(categoryName)); + } + private Map<String, List<String>> addTypesDerivedFromVertex(final Map<String, List<String>> types, final GraphVertex vertex) { final Either<List<GraphVertex>, JanusGraphOperationStatus> derivedFromVertex = janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); @@ -900,7 +952,7 @@ public class ElementOperation implements IElementOperation { @Override public Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> getDefaultHeatTimeout() { - return Either.left(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout()); + return Either.left(getConfiguration().getHeatArtifactDeploymentTimeout()); } @Override diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java index 3cd14d8b27..1811dff764 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ModelTestBase.java @@ -54,7 +54,8 @@ public class ModelTestBase { appConfigDir); configurationManager = new ConfigurationManager(configurationSource); - Configuration configuration = new Configuration(); + Configuration configuration = configurationManager.getConfiguration(); + configuration.setCassandraConfig(null); configuration.setJanusGraphInMemoryGraph(true); environmentContext.setDefaultValue("General_Revenue-Bearing"); @@ -64,11 +65,10 @@ public class ModelTestBase { configuration.setHeatArtifactDeploymentTimeout(heatDeploymentArtifactTimeout); Map<String, Object> deploymentRIArtifacts = new HashMap<>(); ArtifactDataDefinition artifactInfo = new ArtifactDataDefinition(); - Object artifactDataObj = new HashMap<String, Object>(); - ((HashMap) artifactDataObj).put("1", artifactInfo); + HashMap<String, Object> artifactDataObj = new HashMap<>(); + artifactDataObj.put("1", artifactInfo); deploymentRIArtifacts.put("VfHeatEnv", artifactDataObj); - configurationManager.setConfiguration(configuration); configurationManager.getConfiguration().setDeploymentResourceInstanceArtifacts(deploymentRIArtifacts); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java index 447b053fea..b48acd0940 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java @@ -26,10 +26,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.junit.Assert; import org.junit.Test; import org.openecomp.sdc.be.config.Configuration; -import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest; @@ -212,7 +210,7 @@ public class ResourceTest extends ModelConfDependentTest { Configuration existingConfiguration = configurationManager.getConfiguration(); Configuration newConfiguration = new Configuration(); - newConfiguration.setServiceNodeTypes(null); + newConfiguration.setServiceBaseNodeTypes(null); Map<String, String> genericAssetNodeTypes = new HashMap<>(); genericAssetNodeTypes.put("VFC", "org.openecomp.resource.abstract.nodes.VFC"); newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java index d84d97b547..ebbb3f4f5e 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java @@ -271,10 +271,10 @@ public class ServiceTest { } @Test - public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() throws Exception { + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() { Configuration existingConfiguration = configurationManager.getConfiguration(); Configuration newConfiguration = new Configuration(); - newConfiguration.setServiceNodeTypes(null); + newConfiguration.setServiceBaseNodeTypes(null); Map<String, String> genericAssetNodeTypes = new HashMap<>(); genericAssetNodeTypes.put("Service", "org.openecomp.resource.abstract.nodes.service"); newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes); @@ -290,7 +290,7 @@ public class ServiceTest { } @Test - public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() throws Exception { + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() { Service testSubject = createTestSubject(); CategoryDefinition category = new CategoryDefinition(); category.setName("CategoryD"); @@ -300,17 +300,17 @@ public class ServiceTest { } @Test - public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception { + public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() { Service testSubject = createTestSubject(); CategoryDefinition category = new CategoryDefinition(); - category.setName("CategoryB"); + category.setName("CategoryA"); testSubject.addCategory(category); String result = testSubject.fetchGenericTypeToscaNameFromConfig(); - assertEquals("org.openecomp.resource.abstract.nodes.B", result); + assertEquals("org.openecomp.resource.abstract.nodes.A", result); Configuration configuration = new Configuration(); - configuration.setServiceNodeTypes(null); + configuration.setServiceBaseNodeTypes(null); configurationManager.setConfiguration(configuration); } } 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 cf3b6dad8b..ed9313e697 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 @@ -20,9 +20,10 @@ package org.openecomp.sdc.be.model.operations.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.isNull; @@ -43,6 +44,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.config.ArtifactConfiguration; +import org.openecomp.sdc.be.config.CategoryBaseTypeConfig; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.impl.HealingPipelineDao; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; @@ -77,9 +79,11 @@ public class ElementOperationTest extends ModelTestBase { @Mock private JanusGraphGenericDao janusGraphDao; + @Mock + private HealingJanusGraphDao healingJanusGraphDao; - private static String CATEGORY = "category"; - private static String SUBCATEGORY = "subcategory"; + private static final String CATEGORY = "category"; + private static final String SUBCATEGORY = "subcategory"; @BeforeAll public static void setupBeforeClass() { @@ -448,13 +452,15 @@ public class ElementOperationTest extends ModelTestBase { @Test public void testBaseTypes_serviceSpecific() { - Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes(); + Map<String, CategoryBaseTypeConfig> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceBaseNodeTypes(); Map<String, String> preExistingGenericNodeTypes = configurationManager.getConfiguration().getGenericAssetNodeTypes(); try { - Map<String, List<String>> serviceNodeTypes = new HashMap<>(); - serviceNodeTypes.put("serviceCategoryA", List.of("org.base.type")); - configurationManager.getConfiguration().setServiceNodeTypes(serviceNodeTypes); + final Map<String, CategoryBaseTypeConfig> serviceBaseNodeTypeConfigMap = new HashMap<>(); + final var categoryBaseTypeConfig = new CategoryBaseTypeConfig(); + categoryBaseTypeConfig.setBaseTypes(List.of("org.base.type")); + serviceBaseNodeTypeConfigMap.put("serviceCategoryA", categoryBaseTypeConfig); + configurationManager.getConfiguration().setServiceBaseNodeTypes(serviceBaseNodeTypeConfigMap); Map<String, String> genericNodeTypes = new HashMap<>(); genericNodeTypes.put("service", "org.service.default"); @@ -483,7 +489,7 @@ public class ElementOperationTest extends ModelTestBase { JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME)).thenReturn("org.parent.type"); - List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null); + List<BaseType> baseTypes = elementOperation.getServiceBaseTypes("serviceCategoryA", null); assertEquals(2, baseTypes.size()); assertEquals("org.base.type", baseTypes.get(0).getToscaResourceName()); @@ -491,14 +497,14 @@ public class ElementOperationTest extends ModelTestBase { assertEquals("1.0", baseTypes.get(0).getVersions().get(0)); assertEquals("org.parent.type", baseTypes.get(1).getToscaResourceName()); } finally { - configurationManager.getConfiguration().setServiceNodeTypes(preExistingServiceNodeTypes); + configurationManager.getConfiguration().setServiceBaseNodeTypes(preExistingServiceNodeTypes); configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes); } } @Test public void testBaseTypes_default() { - Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes(); + Map<String, CategoryBaseTypeConfig> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceBaseNodeTypes(); Map<String, String> preExistingGenericNodeTypes = configurationManager.getConfiguration().getGenericAssetNodeTypes(); @@ -506,7 +512,7 @@ public class ElementOperationTest extends ModelTestBase { Map<String, String> genericNodeTypes = new HashMap<>(); genericNodeTypes.put("Service", "org.service.default"); configurationManager.getConfiguration().setGenericAssetNodeTypes(genericNodeTypes); - configurationManager.getConfiguration().setServiceNodeTypes(null); + configurationManager.getConfiguration().setServiceBaseNodeTypes(null); HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class); final var elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao); @@ -519,14 +525,60 @@ public class ElementOperationTest extends ModelTestBase { when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null); + List<BaseType> baseTypes = elementOperation.getServiceBaseTypes("serviceCategoryA", null); assertEquals(1, baseTypes.size()); assertEquals("org.service.default", baseTypes.get(0).getToscaResourceName()); assertEquals(1, baseTypes.get(0).getVersions().size()); } finally { - configurationManager.getConfiguration().setServiceNodeTypes(preExistingServiceNodeTypes); + configurationManager.getConfiguration().setServiceBaseNodeTypes(preExistingServiceNodeTypes); configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes); } } + + @Test + public void testGetServiceBaseTypes_categoryWithRequiredBaseType() { + defaultBaseTypeMock(); + final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryA", null); + assertEquals(actualBaseTypeList.size(), 1); + final BaseType expectedBaseType = actualBaseTypeList.get(0); + assertEquals(expectedBaseType.getToscaResourceName(), "org.openecomp.resource.abstract.nodes.A"); + + } + + @Test + public void testGetServiceBaseTypes_categoryWithOptionalBaseType() { + defaultBaseTypeMock(); + final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryC", null); + assertEquals(actualBaseTypeList.size(), 2); + assertEquals(actualBaseTypeList.get(0).getToscaResourceName(), "org.openecomp.resource.abstract.nodes.C1"); + assertEquals(actualBaseTypeList.get(1).getToscaResourceName(), "org.openecomp.resource.abstract.nodes.C2"); + } + + @Test + public void testGetServiceBaseTypes_categoryWithNoBaseType() { + defaultBaseTypeMock(); + final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryB", null); + assertTrue(actualBaseTypeList.isEmpty()); + } + + @Test + public void testGetServiceBaseTypes_notConfiguredCategoryThatFallsBackToGenericType() { + defaultBaseTypeMock(); + final List<BaseType> actualBaseTypeList = elementOperation.getServiceBaseTypes("CategoryD", null); + + assertEquals(actualBaseTypeList.size(), 1); + final BaseType expectedBaseType = actualBaseTypeList.get(0); + assertEquals(expectedBaseType.getToscaResourceName(), "org.openecomp.resource.abstract.nodes.service"); + } + + private void defaultBaseTypeMock() { + final GraphVertex baseTypeVertex = mock(GraphVertex.class); + when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0"); + when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), isNull(), eq(JsonParseFlagEnum.ParseAll), isNull())) + .thenReturn(Either.left(Collections.singletonList(baseTypeVertex))); + when(healingJanusGraphDao.getParentVertices(eq(baseTypeVertex), eq(EdgeLabelEnum.DERIVED_FROM), eq(JsonParseFlagEnum.ParseAll))) + .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + } + } diff --git a/catalog-model/src/test/resources/config/configuration.yaml b/catalog-model/src/test/resources/config/configuration.yaml index 02b9af9c1b..a3ab97ab60 100644 --- a/catalog-model/src/test/resources/config/configuration.yaml +++ b/catalog-model/src/test/resources/config/configuration.yaml @@ -393,13 +393,18 @@ genericAssetNodeTypes: PNF: org.openecomp.resource.abstract.nodes.PNF Service: org.openecomp.resource.abstract.nodes.service -serviceNodeTypes: +serviceBaseNodeTypes: CategoryA: - - org.openecomp.resource.abstract.nodes.A + required: true + baseTypes: + - org.openecomp.resource.abstract.nodes.A CategoryB: - - org.openecomp.resource.abstract.nodes.B + required: false CategoryC: - - org.openecomp.resource.abstract.nodes.C + required: false + baseTypes: + - org.openecomp.resource.abstract.nodes.C1 + - org.openecomp.resource.abstract.nodes.C2 workloadContext: Production environmentContext: |