aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java72
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java775
-rw-r--r--catalog-model/src/test/resources/config/configuration.yaml9
4 files changed, 426 insertions, 439 deletions
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 9728e8ccb8..a06f737c83 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,9 +19,11 @@
*/
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 java.util.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -165,8 +167,9 @@ public class Service extends Component {
}
private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) {
- return Optional.ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes())
- .map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null);
+ 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;
}
@Override
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 4c97b45830..b98f8d9dea 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
@@ -40,10 +40,10 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -80,10 +80,12 @@ public class ElementOperation implements IElementOperation {
private static final String COULDN_T_FETCH_janusGraph_GRAPH = "Couldn't fetch janusgraph graph";
private static final String UNKNOWN_CATEGORY_TYPE = "Unknown category type {}";
private static final Logger log = Logger.getLogger(ElementOperation.class.getName());
+ private static final String PROBLEM_WHILE_CREATING_CATEGORY_REASON = "Problem while creating category, reason {}";
private JanusGraphGenericDao janusGraphGenericDao;
private HealingJanusGraphDao janusGraphDao;
- public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao, @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) {
+ public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao,
+ @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) {
super();
this.janusGraphGenericDao = janusGraphGenericDao;
this.janusGraphDao = janusGraphDao;
@@ -143,7 +145,7 @@ public class ElementOperation implements IElementOperation {
if (createNode.isRight()) {
JanusGraphOperationStatus value = createNode.right().value();
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
- log.debug("Problem while creating category, reason {}", value);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value);
if (value == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) {
actionStatus = ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS;
}
@@ -179,7 +181,7 @@ public class ElementOperation implements IElementOperation {
if (updatedNode.isRight()) {
JanusGraphOperationStatus value = updatedNode.right().value();
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
- log.debug("Problem while creating category, reason {}", value);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value);
result = Either.right(actionStatus);
return result;
}
@@ -228,7 +230,7 @@ public class ElementOperation implements IElementOperation {
.createNode(subCategoryData, SubCategoryData.class);
if (subCategoryNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value();
- log.debug("Problem while creating category, reason {}", janusGraphOperationStatus);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, janusGraphOperationStatus);
if (janusGraphOperationStatus == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) {
actionStatus = ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY;
}
@@ -380,50 +382,54 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public List<BaseType> getBaseTypes(final String categoryName, final String modelName){
+ public List<BaseType> getBaseTypes(final String categoryName, final String modelName) {
final ArrayList<BaseType> baseTypes = new ArrayList<>();
- final Map<String, String> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
- final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName);
+ 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 String baseToscaResourceName = categorySpecificBaseType == null? generalBaseType : categorySpecificBaseType;
+ final List<String> baseToscaResourceNames = categorySpecificBaseType == null ? List.of(generalBaseType) : categorySpecificBaseType;
- final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
- props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
- props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
+ baseToscaResourceNames.forEach(baseToscaResourceName -> {
+ final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
.getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName);
-
- if (baseTypeVertex.isLeft()) {
- BaseType baseType = new BaseType(baseToscaResourceName);
- baseTypes.add(baseType);
-
- final Map<String, List<String>> typesDerivedFromBaseType = new LinkedHashMap<>();
- baseTypeVertex.left().value().forEach(v -> {
- baseType.addVersion((String)v.getMetadataProperty(GraphPropertyEnum.VERSION));
- addTypesDerivedFromVertex(typesDerivedFromBaseType, v);
- });
-
- typesDerivedFromBaseType.forEach((k,v) -> baseTypes.add(new BaseType(k, v)));
- }
+
+ if (baseTypeVertex.isLeft()) {
+ BaseType baseType = new BaseType(baseToscaResourceName);
+ baseTypes.add(baseType);
+
+ final Map<String, List<String>> typesDerivedFromBaseType = new LinkedHashMap<>();
+ baseTypeVertex.left().value().forEach(v -> {
+ baseType.addVersion((String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(typesDerivedFromBaseType, v);
+ });
+
+ typesDerivedFromBaseType.forEach((k, v) -> baseTypes.add(new BaseType(k, v)));
+ }
+ });
return baseTypes;
}
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);
+ janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll);
if (derivedFromVertex.isLeft()) {
- derivedFromVertex.left().value().stream().filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name()))
+ derivedFromVertex.left().value().stream()
+ .filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name()))
.forEach(v -> {
- addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), (String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
- addTypesDerivedFromVertex(types, v);
+ addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME),
+ (String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(types, v);
});
}
return types;
}
private void addBaseTypeVersion(final Map<String, List<String>> baseTypes, final String baseTypeToscaResourceName, final String baseTypeVersion) {
- List<String> versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>(): baseTypes.get(baseTypeToscaResourceName);
+ List<String> versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>() : baseTypes.get(baseTypeToscaResourceName);
versions.add(baseTypeVersion);
baseTypes.put(baseTypeToscaResourceName, versions);
}
@@ -619,7 +625,7 @@ public class ElementOperation implements IElementOperation {
}
Vertex artifactV = iterator.next();
artifactV.remove();
- ;
+
SubCategoryDefinition deleted = new SubCategoryDefinition(subCategoryDataEither.left().value().getSubCategoryDataDefinition());
result = Either.left(deleted);
return result;
@@ -664,7 +670,7 @@ public class ElementOperation implements IElementOperation {
}
Vertex artifactV = iterator.next();
artifactV.remove();
- ;
+
GroupingDefinition deleted = new GroupingDefinition(groupingDataEither.left().value().getGroupingDataDefinition());
result = Either.left(deleted);
return result;
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 58ee0d52af..cf3b6dad8b 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,19 +20,36 @@
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.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.tinkerpop.gremlin.structure.T;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -51,70 +68,62 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-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;
-import static org.mockito.Mockito.*;
-
-@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class ElementOperationTest extends ModelTestBase {
- @javax.annotation.Resource(name = "element-operation")
+ @InjectMocks
private ElementOperation elementOperation;
- @javax.annotation.Resource(name = "janusgraph-generic-dao")
+ @Mock
private JanusGraphGenericDao janusGraphDao;
private static String CATEGORY = "category";
private static String SUBCATEGORY = "subcategory";
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() {
ModelTestBase.init();
}
+ @BeforeEach
+ void beforeEachInit() {
+ MockitoAnnotations.openMocks(this);
+ }
+
@Test
public void testGetArtifactsTypes() {
final List<ArtifactConfiguration> 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);
+ 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<ArtifactType> actualArtifactTypes = elementOperation.getAllArtifactTypes();
- assertNotNull(actualArtifactTypes);
+ assertNotNull(actualArtifactTypes);
assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size());
- boolean allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
- expectedArtifactConfigurationList.stream()
- .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
- );
- assertTrue(allMatch);
+ 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);
+ assertNotNull(actualArtifactTypes);
assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size());
- allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
- expectedArtifactConfigurationList.stream()
- .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
- );
- assertTrue(allMatch);
+ allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
+ expectedArtifactConfigurationList.stream()
+ .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
+ );
+ assertTrue(allMatch);
}
// @Test
@@ -133,350 +142,318 @@ public class ElementOperationTest extends ModelTestBase {
assertTrue(res.isLeft());
categoryDefinition = (CategoryDefinition) res.left().value();
assertEquals(CATEGORY, categoryDefinition.getName());
- }
-
- private ElementOperation createTestSubject() {
- return new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), new HealingJanusGraphDao(new HealingPipelineDao(), new JanusGraphClient()));
- }
-
-
- @Test
- public void testGetAllServiceCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllServiceCategories();
- }
-
-
- @Test
- public void testGetAllResourceCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllResourceCategories();
- }
-
-
- @Test
- public void testGetAllProductCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllProductCategories();
- }
-
-
- @Test
- public void testCreateCategory() throws Exception {
- ElementOperation testSubject;
- CategoryDefinition category = new CategoryDefinition();
- NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createCategory(category, nodeType);
- }
-
-
- @Test
- public void testCreateCategory_1() throws Exception {
- ElementOperation testSubject;
- CategoryDefinition category = new CategoryDefinition();
- NodeTypeEnum nodeType = NodeTypeEnum.ArtifactRef;
- boolean inTransaction = false;
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createCategory(category, nodeType, inTransaction);
- }
-
-
- @Test
- public void testCreateSubCategory() throws Exception {
- ElementOperation testSubject;
- String categoryId = "";
- SubCategoryDefinition subCategory = null;
- NodeTypeEnum nodeType = null;
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
- }
-
-
- @Test
- public void testCreateSubCategory_1() throws Exception {
- ElementOperation testSubject;
- String categoryId = "";
- SubCategoryDefinition subCategory = null;
- NodeTypeEnum nodeType = null;
- boolean inTransaction = false;
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
- }
-
-
- @Test
- public void testCreateGrouping() throws Exception {
- ElementOperation testSubject;
- String subCategoryId = "";
- GroupingDefinition grouping = null;
- NodeTypeEnum nodeType = null;
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
- }
-
-
- @Test
- public void testGetAllCategories() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Capability;
- boolean inTransaction = false;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllCategories(nodeType, inTransaction);
- }
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
- String categoryId = "";
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCategory(nodeType, categoryId);
- }
-
-
- @Test
- public void testGetSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Group;
- String subCategoryId = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubCategory(nodeType, subCategoryId);
- }
-
-
- @Test
- public void testDeleteCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
- String categoryId = "";
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteCategory(nodeType, categoryId);
- }
-
-
- @Test
- public void testDeleteSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
- String subCategoryId = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteSubCategory(nodeType, subCategoryId);
- }
-
-
- @Test
- public void testDeleteGrouping() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.DataType;
- String groupingId = "";
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteGrouping(nodeType, groupingId);
- }
-
-
- @Test
- public void testIsCategoryUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String normalizedName = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
- }
-
-
- @Test
- public void testIsSubCategoryUniqueForCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String subCategoryNormName = "";
- String parentCategoryId = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
- }
-
-
- @Test
- public void testIsGroupingUniqueForSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String groupingNormName = "";
- String parentSubCategoryId = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
- }
-
-
- @Test
- public void testGetSubCategoryUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String normalizedName = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
- }
-
-
- @Test
- public void testGetGroupingUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String groupingNormalizedName = "";
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
- }
-
-
- @Test
- public void testGetAllTags() throws Exception {
- ElementOperation testSubject;
- Either<List<Tag>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllTags();
- }
-
-
- @Test
- public void testGetCategoryData() throws Exception {
- ElementOperation testSubject;
- String name = "";
- NodeTypeEnum type = NodeTypeEnum.DataType;
- Class<T> clazz = null;
- Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
-
- // test 1
- testSubject = createTestSubject();
- name = null;
- result = testSubject.getCategoryData(name, type, null);
-
- // test 2
- testSubject = createTestSubject();
- name = "";
- result = testSubject.getCategoryData(name, type, null);
- }
-
-
-
-
-
- @Test
- public void testGetAllPropertyScopes() throws Exception {
- ElementOperation testSubject;
- Either<List<PropertyScope>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllPropertyScopes();
- }
-
- @Test
- public void testGetResourceTypesMap() throws Exception {
- ElementOperation testSubject;
- Either<Map<String, String>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResourceTypesMap();
- }
-
- @Test
- public void testGetNewCategoryData() throws Exception {
- ElementOperation testSubject;
- String name = "";
- NodeTypeEnum type = NodeTypeEnum.HeatParameter;
- Class<T> clazz = null;
- Either<CategoryData, StorageOperationStatus> result;
-
- // test 1
- testSubject = createTestSubject();
- name = null;
- result = testSubject.getNewCategoryData(name, type, null);
-
- // test 2
- testSubject = createTestSubject();
- name = "";
- result = testSubject.getNewCategoryData(name, type, null);
}
-
+
+ private ElementOperation createTestSubject() {
+ return new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()),
+ new HealingJanusGraphDao(new HealingPipelineDao(), new JanusGraphClient()));
+ }
+
+ @Test
+ public void testGetAllServiceCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllServiceCategories();
+ }
+
+ @Test
+ public void testGetAllResourceCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllResourceCategories();
+ }
+
+ @Test
+ public void testGetAllProductCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllProductCategories();
+ }
+
+ @Test
+ public void testCreateCategory() throws Exception {
+ ElementOperation testSubject;
+ CategoryDefinition category = new CategoryDefinition();
+ NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createCategory(category, nodeType);
+ }
+
+ @Test
+ public void testCreateCategory_1() throws Exception {
+ ElementOperation testSubject;
+ CategoryDefinition category = new CategoryDefinition();
+ NodeTypeEnum nodeType = NodeTypeEnum.ArtifactRef;
+ boolean inTransaction = false;
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createCategory(category, nodeType, inTransaction);
+ }
+
+ @Test
+ public void testCreateSubCategory() throws Exception {
+ ElementOperation testSubject;
+ String categoryId = "";
+ SubCategoryDefinition subCategory = null;
+ NodeTypeEnum nodeType = null;
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
+ }
+
+ @Test
+ public void testCreateSubCategory_1() throws Exception {
+ ElementOperation testSubject;
+ String categoryId = "";
+ SubCategoryDefinition subCategory = null;
+ NodeTypeEnum nodeType = null;
+ boolean inTransaction = false;
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
+ }
+
+ @Test
+ public void testCreateGrouping() throws Exception {
+ ElementOperation testSubject;
+ String subCategoryId = "";
+ GroupingDefinition grouping = null;
+ NodeTypeEnum nodeType = null;
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
+ }
+
+ @Test
+ public void testGetAllCategories() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Capability;
+ boolean inTransaction = false;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllCategories(nodeType, inTransaction);
+ }
+
+ @Test
+ public void testGetCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
+ String categoryId = "";
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getCategory(nodeType, categoryId);
+ }
+
+ @Test
+ public void testGetSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Group;
+ String subCategoryId = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getSubCategory(nodeType, subCategoryId);
+ }
+
+ @Test
+ public void testDeleteCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
+ String categoryId = "";
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteCategory(nodeType, categoryId);
+ }
+
+ @Test
+ public void testDeleteSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
+ String subCategoryId = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteSubCategory(nodeType, subCategoryId);
+ }
+
+ @Test
+ public void testDeleteGrouping() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.DataType;
+ String groupingId = "";
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteGrouping(nodeType, groupingId);
+ }
+
+ @Test
+ public void testIsCategoryUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String normalizedName = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
+ }
+
+ @Test
+ public void testIsSubCategoryUniqueForCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String subCategoryNormName = "";
+ String parentCategoryId = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
+ }
+
+ @Test
+ public void testIsGroupingUniqueForSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String groupingNormName = "";
+ String parentSubCategoryId = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
+ }
+
+ @Test
+ public void testGetSubCategoryUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String normalizedName = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
+ }
+
+ @Test
+ public void testGetGroupingUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String groupingNormalizedName = "";
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
+ }
+
+ @Test
+ public void testGetAllTags() throws Exception {
+ ElementOperation testSubject;
+ Either<List<Tag>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllTags();
+ }
+
+ @Test
+ public void testGetCategoryData() throws Exception {
+ ElementOperation testSubject;
+ String name = "";
+ NodeTypeEnum type = NodeTypeEnum.DataType;
+ Class<T> clazz = null;
+ Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
+
+ // test 1
+ testSubject = createTestSubject();
+ name = null;
+ result = testSubject.getCategoryData(name, type, null);
+
+ // test 2
+ testSubject = createTestSubject();
+ name = "";
+ result = testSubject.getCategoryData(name, type, null);
+ }
+
+ @Test
+ public void testGetAllPropertyScopes() throws Exception {
+ ElementOperation testSubject;
+ Either<List<PropertyScope>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllPropertyScopes();
+ }
+
+ @Test
+ public void testGetResourceTypesMap() throws Exception {
+ ElementOperation testSubject;
+ Either<Map<String, String>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getResourceTypesMap();
+ }
+
+ @Test
+ public void testGetNewCategoryData() throws Exception {
+ ElementOperation testSubject;
+ String name = "";
+ NodeTypeEnum type = NodeTypeEnum.HeatParameter;
+ Class<T> clazz = null;
+ Either<CategoryData, StorageOperationStatus> result;
+
+ // test 1
+ testSubject = createTestSubject();
+ name = null;
+ result = testSubject.getNewCategoryData(name, type, null);
+
+ // test 2
+ testSubject = createTestSubject();
+ name = "";
+ result = testSubject.getNewCategoryData(name, type, null);
+ }
+
@Test
public void testBaseTypes_serviceSpecific() {
- Map<String, String> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
- Map<String, String> preExistingGenericNodeTypes =
- configurationManager.getConfiguration().getGenericAssetNodeTypes();
+ Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, String> preExistingGenericNodeTypes = configurationManager.getConfiguration().getGenericAssetNodeTypes();
try {
- Map<String, String> serviceNodeTypes = new HashMap<>();
- serviceNodeTypes.put("serviceCategoryA", "org.base.type");
+ Map<String, List<String>> serviceNodeTypes = new HashMap<>();
+ serviceNodeTypes.put("serviceCategoryA", List.of("org.base.type"));
configurationManager.getConfiguration().setServiceNodeTypes(serviceNodeTypes);
Map<String, String> genericNodeTypes = new HashMap<>();
@@ -484,28 +461,27 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setGenericAssetNodeTypes(genericNodeTypes);
HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class);
- ElementOperation elementOperation =
- new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
+ ElementOperation elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
- .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
+ .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
GraphVertex derivedTypeVertex = mock(GraphVertex.class);
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(LifecycleStateEnum.CERTIFIED.name());
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
-
+
GraphVertex derivedTypeVertexUncertified = mock(GraphVertex.class);
- when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
+ when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(
+ LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.1");
-
+
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(Collections.singletonList(derivedTypeVertex)));
+ JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(Collections.singletonList(derivedTypeVertex)));
when(healingJanusGraphDao.getParentVertices(derivedTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME))
- .thenReturn("org.parent.type");
+ 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);
@@ -519,12 +495,12 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes);
}
}
-
+
@Test
public void testBaseTypes_default() {
- Map<String, String> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
Map<String, String> preExistingGenericNodeTypes =
- configurationManager.getConfiguration().getGenericAssetNodeTypes();
+ configurationManager.getConfiguration().getGenericAssetNodeTypes();
try {
Map<String, String> genericNodeTypes = new HashMap<>();
@@ -533,16 +509,15 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setServiceNodeTypes(null);
HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class);
- ElementOperation elementOperation =
- new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
+ final var elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
- .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
+ .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
diff --git a/catalog-model/src/test/resources/config/configuration.yaml b/catalog-model/src/test/resources/config/configuration.yaml
index 95695b7ce8..02b9af9c1b 100644
--- a/catalog-model/src/test/resources/config/configuration.yaml
+++ b/catalog-model/src/test/resources/config/configuration.yaml
@@ -394,9 +394,12 @@ genericAssetNodeTypes:
Service: org.openecomp.resource.abstract.nodes.service
serviceNodeTypes:
- CategoryA: org.openecomp.resource.abstract.nodes.A
- CategoryB: org.openecomp.resource.abstract.nodes.B
- CategoryC: org.openecomp.resource.abstract.nodes.C
+ CategoryA:
+ - org.openecomp.resource.abstract.nodes.A
+ CategoryB:
+ - org.openecomp.resource.abstract.nodes.B
+ CategoryC:
+ - org.openecomp.resource.abstract.nodes.C
workloadContext: Production
environmentContext: