aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2021-06-24 11:19:45 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-15 13:22:58 +0000
commit4f4f7fb796475bb4a332e798c80438b33ce7712a (patch)
tree88b0f7285acfa2e49c5ba3ad3cc4b04bf9c58dc7 /catalog-model
parent53df976426f8845adf58e8ff9355764343a38549 (diff)
Allow only types from selected model in service creation
Issue-ID: SDC-3629 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I98edb8a1133b2df8d884782f3fb2758b42b94158
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java30
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java83
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java8
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java40
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java17
8 files changed, 134 insertions, 63 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index d08d705a2b..bfb6cae3aa 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -206,6 +206,9 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
}
if (result == null) {
+ result = createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex);
+ }
+ if (result == null) {
status = janusGraphDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
@@ -260,6 +263,33 @@ public abstract class ToscaElementOperation extends BaseOperation {
return result;
}
+ /**
+ * Creates the MODEL in case it exits on the previous version
+ * @param previousToscaElement previous element version
+ * @param nextToscaElement latest element version
+ * @param user user
+ * @param createdToscaElementVertex created tosca element
+ * @return
+ */
+ private Either<GraphVertex, StorageOperationStatus> createModelEdge(final GraphVertex previousToscaElement,
+ final GraphVertex nextToscaElement, GraphVertex user,
+ final GraphVertex createdToscaElementVertex) {
+ Either<GraphVertex, StorageOperationStatus> result = null;
+ final Either<GraphVertex, JanusGraphOperationStatus> modelElementVertexResponse = janusGraphDao
+ .getParentVertex(previousToscaElement, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse);
+ if (modelElementVertexResponse.isLeft()) {
+ final JanusGraphOperationStatus status = janusGraphDao
+ .createEdge(nextToscaElement.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>());
+ if (JanusGraphOperationStatus.OK != status) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.MODEL,
+ user.getUniqueId(), nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ }
+ return result;
+ }
+
protected JanusGraphOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
Either<GraphVertex, JanusGraphOperationStatus> parentVertex = janusGraphDao
.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 814ac01eac..25bac1642c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -43,7 +43,9 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiPredicate;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -531,8 +533,12 @@ public class ToscaOperationFacade {
if (vertex.isRight() || Objects.isNull(vertex.left().value())) {
return Optional.empty();
}
+ return getElementModelVertex(model, vertex.left().value());
+ }
+
+ private Optional<GraphVertex> getElementModelVertex(final String model, final GraphVertex vertex) {
final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao
- .getParentVertices(vertex.left().value(), EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse);
+ .getParentVertices(vertex, EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse);
if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) {
return Optional.empty();
}
@@ -1884,7 +1890,8 @@ public class ToscaOperationFacade {
}
private Either<List<Service>, StorageOperationStatus> getLatestVersionNonCheckoutServicesMetadataOnly(Map<GraphPropertyEnum, Object> hasProps,
- Map<GraphPropertyEnum, Object> hasNotProps) {
+ Map<GraphPropertyEnum, Object> hasNotProps,
+ String modelName) {
List<Service> services = new ArrayList<>();
List<LifecycleStateEnum> states = new ArrayList<>();
// include props
@@ -1895,30 +1902,27 @@ public class ToscaOperationFacade {
hasNotProps.put(GraphPropertyEnum.STATE, states);
hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
hasNotProps.put(GraphPropertyEnum.IS_ARCHIVED, true);
- return fetchServicesByCriteria(services, hasProps, hasNotProps);
+ return fetchServicesByCriteria(services, hasProps, hasNotProps, modelName);
}
private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract,
ComponentTypeEnum componentTypeEnum,
String internalComponentType,
- VertexTypeEnum vertexType) {
+ VertexTypeEnum vertexType,
+ String modelName) {
List<Service> services = null;
Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType);
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
.getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
- if (getRes.isRight()) {
- if (getRes.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) {
- return Either.left(new ArrayList<>());
- } else {
- return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
- }
+ if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) {
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
// region -> Fetch non checked-out services
if (internalComponentType != null && internalComponentType.toLowerCase().trim().equals(SERVICE) && VertexTypeEnum.NODE_TYPE == vertexType) {
Either<List<Service>, StorageOperationStatus> result = getLatestVersionNonCheckoutServicesMetadataOnly(
- new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class));
+ new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class), modelName);
if (result.isRight()) {
log.debug("Failed to fetch services for");
return Either.right(result.right().value());
@@ -1932,15 +1936,17 @@ public class ToscaOperationFacade {
List<Component> nonAbstractLatestComponents = new ArrayList<>();
ComponentParametersView params = new ComponentParametersView(true);
params.setIgnoreAllVersions(false);
- for (GraphVertex vertexComponent : getRes.left().value()) {
- Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation
- .getLightComponent(vertexComponent, componentTypeEnum, params);
- if (componentRes.isRight()) {
- log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
- return Either.right(componentRes.right().value());
- } else {
- Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
- nonAbstractLatestComponents.add(component);
+ if (getRes.isLeft()) {
+ for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) {
+ Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation
+ .getLightComponent(vertexComponent, componentTypeEnum, params);
+ if (componentRes.isRight()) {
+ log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
+ return Either.right(componentRes.right().value());
+ } else {
+ Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
+ nonAbstractLatestComponents.add(component);
+ }
}
}
if (CollectionUtils.isNotEmpty(services)) {
@@ -2034,7 +2040,7 @@ public class ToscaOperationFacade {
private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum,
String internalComponentType) {
Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, componentTypeEnum,
- internalComponentType);
+ internalComponentType, null);
if (getToscaElementsRes.isRight()) {
return Either.right(getToscaElementsRes.right().value());
}
@@ -2178,12 +2184,13 @@ public class ToscaOperationFacade {
public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract,
ComponentTypeEnum componentTypeEnum,
- String internalComponentType) {
+ String internalComponentType,
+ String modelName) {
List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
List<Component> result = new ArrayList<>();
for (VertexTypeEnum vertexType : internalVertexTypes) {
Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract,
- componentTypeEnum, internalComponentType, vertexType);
+ componentTypeEnum, internalComponentType, vertexType, modelName);
if (listByVertexType.isRight()) {
return listByVertexType;
}
@@ -2533,7 +2540,7 @@ public class ToscaOperationFacade {
for (DistributionStatusEnum state : distStatus) {
propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name());
Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch,
- propertiesNotToMatch);
+ propertiesNotToMatch, null);
if (fetchServicesByCriteria.isRight()) {
return fetchServicesByCriteria;
} else {
@@ -2542,13 +2549,14 @@ public class ToscaOperationFacade {
}
return Either.left(servicesAll);
} else {
- return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
+ return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch, null);
}
}
private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll,
Map<GraphPropertyEnum, Object> propertiesToMatch,
- Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch,
+ String modelName) {
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
if (getRes.isRight()) {
@@ -2559,7 +2567,7 @@ public class ToscaOperationFacade {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
} else {
- for (GraphVertex vertex : getRes.left().value()) {
+ for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) {
Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation
.getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true));
if (getServiceRes.isRight()) {
@@ -2574,6 +2582,27 @@ public class ToscaOperationFacade {
return Either.left(servicesAll);
}
+ private List<GraphVertex> getVerticesForModel(final String modelName, final List<GraphVertex> graphVertexList) {
+ final Predicate<? super GraphVertex> filterPredicate =
+ StringUtils.isEmpty(modelName) ? this::vertexNotConnectedToAnyModel
+ : graphVertex -> vertexValidForModel(graphVertex, modelName).isPresent();
+ return StreamSupport.stream(graphVertexList.spliterator(), false).filter(filterPredicate).collect(Collectors.toList());
+ }
+
+ private boolean vertexNotConnectedToAnyModel(final GraphVertex vertex) {
+ return !vertex.getVertex().edges(Direction.OUT, EdgeLabelEnum.MODEL.name()).hasNext();
+ }
+
+ private Optional<GraphVertex> vertexValidForModel(final GraphVertex vertex, final String model) {
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao
+ .getParentVertices(vertex, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse);
+ if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) {
+ return Optional.empty();
+ }
+ return nodeModelVertices.left().value().stream().filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.MODEL).equals(model))
+ .findFirst();
+ }
+
public void rollback() {
janusGraphDao.rollback();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
index bda3e95e0b..bba124ec0d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
@@ -33,5 +33,5 @@ public interface IPolicyTypeOperation {
Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition updatedPolicyType,
PolicyTypeDefinition currPolicyType);
- List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes);
+ List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 542d4cf0c0..488ab78cab 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -273,13 +273,11 @@ public class GroupTypeOperation implements IGroupTypeOperation {
return janusGraphGenericDao.createRelation(groupTypeData, capabilityData, GraphEdgeLabels.GROUP_TYPE_CAPABILITY, properties);
}
- public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes) {
+ public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes, String modelName) {
Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(),
excludedGroupTypes);
- List<GroupTypeData> groupTypes = janusGraphGenericDao
- .getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class).left()
- .on(operationUtils::onJanusGraphOperationFailure);
- return convertGroupTypesToDefinition(groupTypes);
+ return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class, modelName).left()
+ .map(this::convertGroupTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure);
}
private List<GroupTypeDefinition> convertGroupTypesToDefinition(List<GroupTypeData> groupTypes) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
index 947b2168b9..c30c39835b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -60,4 +62,11 @@ public class OperationUtils {
janusGraphDao.rollback();
throw new StorageException(status);
}
+
+ public <T> List<T> validateJanusGraphOperationFailure(final JanusGraphOperationStatus status) {
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(status)) {
+ return Collections.emptyList();
+ }
+ return onJanusGraphOperationFailure(status);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 2b3695fc13..03b531b3b1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -18,7 +18,6 @@
* ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.be.model.operations.impl;
-
import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate;
import fj.data.Either;
@@ -95,12 +94,11 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return updatePolicyTypeOnGraph(updatedPolicyType, currPolicyType);
}
- @Override
- public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes) {
+ public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName) {
Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(),
excludedPolicyTypes);
- return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class).left()
- .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::onJanusGraphOperationFailure);
+ return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class, modelName).left()
+ .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure);
}
private List<PolicyTypeDefinition> convertPolicyTypesToDefinition(List<PolicyTypeData> policiesTypes) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
index 9187604f66..062f668b05 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
@@ -20,11 +20,24 @@
package org.openecomp.sdc.be.model.operations.impl;
-import org.janusgraph.core.JanusGraph;
-import org.janusgraph.core.JanusGraphVertex;
+import static com.google.common.collect.Sets.newHashSet;
+import static java.util.Arrays.asList;
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import fj.data.Either;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphVertex;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -36,7 +49,12 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.GroupTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
@@ -44,18 +62,6 @@ import org.openecomp.sdc.be.resources.data.GroupTypeData;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import static com.google.common.collect.Sets.newHashSet;
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.*;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class GroupTypeOperationTest extends ModelTestBase {
@@ -92,7 +98,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
groupTypeOperation.addGroupType(type1);
groupTypeOperation.addGroupType(type2);
- List<GroupTypeDefinition> allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null);
+ List<GroupTypeDefinition> allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null, null);
assertThat(allGroupTypesNoExclusion)
.usingElementComparatorOnFields("type", "icon", "name")
.containsExactlyInAnyOrder(rootGroupDefinition, type1, type2);
@@ -107,7 +113,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
groupTypeOperation.addGroupType(type1);
groupTypeOperation.addGroupType(type2);
- List<GroupTypeDefinition> allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2"));
+ List<GroupTypeDefinition> allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2"), null);
assertThat(allGroupTypes)
.usingElementComparatorOnFields("type")
.containsExactly(rootGroupDefinition);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
index 518de1eb1d..47bc484193 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
@@ -26,29 +26,28 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.janusgraph.core.JanusGraph;
-import org.janusgraph.core.JanusGraphVertex;
import fj.data.Either;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphVertex;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ModelTestBase;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.PolicyTypeData;
import org.springframework.beans.factory.annotation.Autowired;
@@ -156,9 +155,10 @@ public class PolicyTypeOperationTest extends ModelTestBase {
.containsExactlyInAnyOrder(prop1, prop2, prop3);
}
- @Test(expected = StorageException.class)
+ @Test
public void getAllPolicyTypes_noPolicies() {
- policyTypeOperation.getAllPolicyTypes(null);
+ final List<PolicyTypeDefinition> result = policyTypeOperation.getAllPolicyTypes(null, null);
+ assertThat(result).isEmpty();
}
@Test
@@ -166,7 +166,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
PolicyTypeDefinition policyType1 = createPolicyTypeDef();
PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.test1", "desc1", "tosca.policies.Root");
addPolicyTypesToDB(policyType1, policyType2);
- List<PolicyTypeDefinition> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null);
+ List<PolicyTypeDefinition> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null, null);
assertThat(allPolicyTypesWithNoExcluded).hasSize(2);
assertThat(allPolicyTypesWithNoExcluded).usingElementComparatorOnFields("uniqueId", "description", "version", "type")
.containsExactlyInAnyOrder(policyType1, policyType2);
@@ -180,7 +180,8 @@ public class PolicyTypeOperationTest extends ModelTestBase {
policyTypeOperation.addPolicyType(policyType1);
policyTypeOperation.addPolicyType(policyType2);
policyTypeOperation.addPolicyType(policyType3);
- List<PolicyTypeDefinition> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(newHashSet("tosca.policies.test1", "tosca.policies.test2"));
+ List<PolicyTypeDefinition> allPolicyTypes = policyTypeOperation.getAllPolicyTypes(newHashSet("tosca.policies.test1", "tosca.policies.test2"),
+ null);
assertThat(allPolicyTypes).hasSize(1);
assertThat(allPolicyTypes).usingElementComparatorOnFields("type")
.containsExactly(policyType1);