summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java322
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java97
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java125
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java391
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java553
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java31
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java)79
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java98
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java23
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java40
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java81
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java73
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml494
17 files changed, 1587 insertions, 905 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
index aae88ab153..1bf075e2f6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
@@ -25,47 +25,42 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import fj.data.Either;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -78,15 +73,18 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.exception.ResponseFormat;
@ExtendWith(MockitoExtension.class)
-public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock {
+class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock {
private static final String servicePropertyName = "resourceType";
private static final String constraintOperator = "equal";
@@ -119,9 +117,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
private Resource resource;
private ComponentInstance componentInstance;
private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
- private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
- private String constraint;
private UIConstraint uiConstraint;
+ private FilterConstraintDto filterConstraintDto;
@BeforeEach
public void init() {
@@ -141,7 +138,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createWhenNodeFilterExistsTest() throws BusinessLogicException {
+ void createWhenNodeFilterExistsTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -155,7 +152,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createNodeFilterFailTest() {
+ void createNodeFilterFailTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -175,7 +172,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void createNodeFilterIfNotExist() throws BusinessLogicException {
+ void createNodeFilterIfNotExist() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -197,7 +194,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterIfExistsTest() throws BusinessLogicException {
+ void deleteNodeFilterIfExistsTest() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
@@ -211,7 +208,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteWhenNodeFilterExistsTest() throws BusinessLogicException {
+ void deleteWhenNodeFilterExistsTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -236,7 +233,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterIfExistsFailTest() {
+ void deleteNodeFilterIfExistsFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
@@ -260,129 +257,130 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void addNodeFilterPropertiesTest() throws BusinessLogicException {
+ void addNodeFilterPropertiesTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, filterConstraintDto))
+ .thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.PROPERTIES, "");
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.PROPERTIES, null);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, "");
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterOperation, times(1))
- .addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class));
+ .addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void addNodeFilterCapabilitiesTest() throws BusinessLogicException {
+ void addNodeFilterCapabilitiesTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
-
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, filterConstraintDto))
+ .thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterOperation.addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ when(nodeFilterOperation.addCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
any(RequirementNodeFilterCapabilityDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.CAPABILITIES, capabilityName);
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName
+ );
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName);
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterOperation, times(1))
- .addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ .addCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
any(RequirementNodeFilterCapabilityDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void addNodeFilterFailTest() {
+ void addNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator
- .validateFilter(resource, componentInstanceId,
- requirementNodeFilterPropertyDataDefinition.getConstraints(),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName)).thenReturn(Either.left(true));
+ .validateFilter(resource, componentInstanceId, filterConstraintDto)).thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
-
- final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
- assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
+ when(nodeFilterOperation
+ .addPropertyFilter(eq(componentId), eq(componentInstanceId), eq(ciNodeFilterDataDefinition), any(PropertyFilterDataDefinition.class)))
+ .thenReturn(Either.right(StorageOperationStatus.COMPONENT_IS_IN_USE));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_IN_USE)).thenReturn(ActionStatus.COMPONENT_IN_USE);
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_IN_USE, resource.getSystemName())).thenReturn(expectedResponse);
+
+ final BusinessLogicException businessLogicException = assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, capabilityName));
+ assertEquals(expectedResponse, businessLogicException.getResponseFormat());
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
- verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
- constraints, NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName);
- verify(nodeFilterOperation, times(0))
- .addNewProperty(componentId, componentInstanceId, ciNodeFilterDataDefinition,
- requirementNodeFilterPropertyDataDefinition);
+
+ verify(nodeFilterValidator, times(1))
+ .validateFilter(resource, componentInstanceId, filterConstraintDto);
+ verify(nodeFilterOperation, times(1))
+ .addPropertyFilter(eq(componentId), eq(componentInstanceId), eq(ciNodeFilterDataDefinition),
+ any(PropertyFilterDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
+ verify(janusGraphDao, times(1)).rollback();
+ verify(janusGraphDao, never()).commit();
}
@Test
- public void addNodeFilterFailFetchComponentTest() {
+ void addNodeFilterFailFetchComponentTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId))
- .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND)).thenReturn(ActionStatus.COMPONENT_NOT_FOUND);
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND)).thenReturn(expectedResponse);
- assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE,
+ final BusinessLogicException businessLogicException = assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
+ .addNodeFilter(componentId, componentInstanceId, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, capabilityName));
+ assertEquals(expectedResponse, businessLogicException.getResponseFormat());
}
@Test
- public void deleteNodeFilterTest() throws BusinessLogicException {
+ void deleteNodeFilterTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -395,8 +393,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
.thenReturn(StorageOperationStatus.OK);
final Optional<CINodeFilterDataDefinition> deleteNodeFilterResult = componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES);
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES);
assertThat(deleteNodeFilterResult).isPresent();
@@ -404,9 +401,6 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
- verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
verify(nodeFilterOperation, times(1))
.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition, 0,
NodeFilterConstraintType.PROPERTIES);
@@ -414,14 +408,12 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void deleteNodeFilterFailTest() {
+ void deleteNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -434,64 +426,48 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
.thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
- verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource);
}
@Test
- public void deleteNodeFilterFailValidationTest() {
+ void deleteNodeFilterFailValidationTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
- .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
+ .deleteNodeFilter(componentId, componentInstanceId, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(nodeFilterValidator, times(1))
- .validateFilter(resource, componentInstanceId, singletonList(constraint),
- NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "");
- verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
}
@Test
- public void updateNodeFilterTest() throws BusinessLogicException {
+ void updateNodeFilterTest() throws BusinessLogicException {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
+ .validateFilter(any(Component.class), anyString(), any(FilterConstraintDto.class))
+ ).thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true));
-
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
when(nodeFilterOperation.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition,
0, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -505,20 +481,16 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void updateNodeFilterFailTest() throws BusinessLogicException {
+ void updateNodeFilterFailTest() {
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true));
+ .validateFilter(any(Component.class), anyString(), any(FilterConstraintDto.class))
+ ).thenReturn(Either.left(true));
+
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -526,8 +498,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(nodeFilterOperation.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition,
0, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -538,14 +510,10 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void updateNodeFilterFailValidationTest() {
+ void updateNodeFilterFailValidationTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator
- .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(),
- ArgumentMatchers.any(NodeFilterConstraintAction.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstanceId, uiConstraint, ComponentTypeEnum.RESOURCE,
@@ -555,55 +523,49 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
- public void testAssociateNodeFilterToComponentInstance() {
+ void testAssociateNodeFilterToComponentInstance() {
CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
propertyDataDefinition.setName("order");
- propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
- List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
- propertyList.add(propertyDataDefinition);
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2}"));
filter.setProperties(Collections.singletonList(propertyDataDefinition));
Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
nodeFilterMap.put(componentInstanceId, filter);
when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId, nodeFilterMap);
assertEquals(StorageOperationStatus.OK, status);
}
@Test
- public void testAssociateNodeFilterToComponentInstanceFail() {
+ void testAssociateNodeFilterToComponentInstanceFail() {
CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
propertyDataDefinition.setName("order");
- propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
- List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
- propertyList.add(propertyDataDefinition);
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2}"));
filter.setProperties(Collections.singletonList(propertyDataDefinition));
Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
nodeFilterMap.put(componentInstanceId, filter);
when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
- any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(nodeFilterOperation.addPropertyFilter(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(PropertyFilterDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
- Assertions.assertThrows(ComponentException.class, () -> componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId,
+ assertThrows(ComponentException.class, () -> componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId,
nodeFilterMap));
}
@Test
- public void validateUserTes() {
+ void validateUserTes() {
final String USER_ID = "jh0003";
final User user = new User();
user.setUserId(USER_ID);
@@ -615,54 +577,54 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
assertTrue(Role.ADMIN.name().equalsIgnoreCase(result.getRole()));
}
- public void initResource() {
- try {
- resource = new Resource();
- resource.setName("MyResource");
- resource.setUniqueId(componentId);
- resource.setToscaResourceName("My_Resource_Tosca_Name");
- resource.addCategory("Network Layer 2-3", "Router");
- resource.setDescription("My short description");
-
- componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(componentInstanceId);
- componentInstance.setName("myComponentInstance");
- componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDirectives());
-
- uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
- constraint = new ConstraintConvertor().convert(uiConstraint);
-
- requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
-
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
-
- ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
- ciNodeFilterDataDefinition.setProperties(listDataDefinition);
- ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
-
- resource.setComponentInstances(singletonList(componentInstance));
-
- final PropertyDefinition property = new PropertyDefinition();
- property.setName(uiConstraint.getServicePropertyName());
-
- final List<ComponentInstanceProperty> origProperties = new ArrayList<>();
- final ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
- origProperty.setName(uiConstraint.getServicePropertyName());
- origProperty.setValue(propertyValue);
- origProperty.setType(uiConstraint.getSourceType());
- origProperties.add(origProperty);
-
- final Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
- componentInstanceProps.put(componentInstanceId, origProperties);
-
- resource.setComponentInstancesProperties(componentInstanceProps);
- resource.setProperties(new LinkedList<>(Arrays.asList(property)));
- } catch (final Exception e) {
- fail(e.getMessage());
- }
+ private void initResource() {
+ resource = new Resource();
+ resource.setName("MyResource");
+ resource.setUniqueId(componentId);
+ resource.setToscaResourceName("My_Resource_Tosca_Name");
+ resource.addCategory("Network Layer 2-3", "Router");
+ resource.setDescription("My short description");
+
+ componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(componentInstanceId);
+ componentInstance.setName("myComponentInstance");
+ componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getDirectives());
+
+ uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
+
+ PropertyFilterDataDefinition propertyFilterDataDefinition = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName(uiConstraint.getServicePropertyName());
+ final PropertyFilterConstraintDataDefinition propertyFilterConstraint =
+ filterConstraintMapper.mapTo(filterConstraintDto);
+ propertyFilterDataDefinition.setConstraints(new LinkedList<>(List.of(propertyFilterConstraint)));
+
+ final ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(new LinkedList<>(singletonList(propertyFilterDataDefinition)));
+
+ ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
+ ciNodeFilterDataDefinition.setProperties(listDataDefinition);
+ ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
+
+ resource.setComponentInstances(singletonList(componentInstance));
+
+ final PropertyDefinition property = new PropertyDefinition();
+ property.setName(uiConstraint.getServicePropertyName());
+
+ final List<ComponentInstanceProperty> origProperties = new ArrayList<>();
+ final ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
+ origProperty.setName(uiConstraint.getServicePropertyName());
+ origProperty.setValue(propertyValue);
+ origProperty.setType(uiConstraint.getSourceType());
+ origProperties.add(origProperty);
+
+ final Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
+ componentInstanceProps.put(componentInstanceId, origProperties);
+
+ resource.setComponentInstancesProperties(componentInstanceProps);
+ resource.setProperties(new LinkedList<>(List.of(property)));
}
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
index 7435a8b6e2..c8692634c4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java
@@ -36,7 +36,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -45,29 +44,30 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.UserValidations;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.SubstitutionFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
@ExtendWith(MockitoExtension.class)
-public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLogicMock {
+class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLogicMock {
private static final String servicePropertyName = "controller_actor";
private static final String constraintOperator = "equal";
@@ -97,8 +97,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
private Component component;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
- private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
+ private SubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition;
private String constraint;
+ private FilterConstraintDto filterConstraintDto;
@BeforeEach
public void init() {
@@ -118,7 +119,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
+ void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
@@ -131,7 +132,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
+ void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
@@ -151,7 +152,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void createSubstitutionFilterIfNotExistFailTest() {
+ void createSubstitutionFilterIfNotExistFailTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
@@ -170,124 +171,111 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void addSubstitutionFilterTest() throws BusinessLogicException {
+ void addSubstitutionFilterTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, filterConstraintDto)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
- any(RequirementSubstitutionFilterPropertyDataDefinition.class)))
+ any(SubstitutionFilterPropertyDataDefinition.class)))
.thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, servicePropertyName, constraint, true,
- ComponentTypeEnum.SERVICE);
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, filterConstraintDto);
verify(substitutionFilterOperation, times(1))
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
- any(RequirementSubstitutionFilterPropertyDataDefinition.class));
+ any(SubstitutionFilterPropertyDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void addSubstitutionFilterFailTest() {
+ void addSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, filterConstraintDto)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
- requirementSubstitutionFilterPropertyDataDefinition))
+ substitutionFilterPropertyDataDefinition))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, servicePropertyName, constraint, true,
- ComponentTypeEnum.SERVICE));
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, filterConstraintDto);
verify(substitutionFilterOperation, times(0))
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
- requirementSubstitutionFilterPropertyDataDefinition);
+ substitutionFilterPropertyDataDefinition);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void updateSubstitutionFilterTest() throws BusinessLogicException {
+ void updateSubstitutionFilterTest() throws BusinessLogicException {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
- when(substitutionFilterOperation.updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList()))
+ when(nodeFilterValidator.validateSubstitutionFilter(component, List.of(filterConstraintDto))).thenReturn(Either.left(true));
+ when(substitutionFilterOperation.updatePropertyFilters(anyString(), any(SubstitutionFilterDataDefinition.class), anyList()))
.thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, Collections.singletonList(constraint),
- true, ComponentTypeEnum.SERVICE);
+ .updateSubstitutionFilter(componentId, List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(substitutionFilterOperation, times(1))
- .updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList());
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ .updatePropertyFilters(anyString(), any(SubstitutionFilterDataDefinition.class), anyList());
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, List.of(filterConstraintDto));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void updateSubstitutionFilterFailTest() {
+ void updateSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
- NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
+ when(nodeFilterValidator.validateSubstitutionFilter(component, List.of(filterConstraintDto))).thenReturn(Either.left(true));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, constraints, true, ComponentTypeEnum.SERVICE));
+ .updateSubstitutionFilter(componentId, List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ verify(nodeFilterValidator, times(1)).validateSubstitutionFilter(component, List.of(filterConstraintDto));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
- public void deleteSubstitutionFilterTest() throws BusinessLogicException {
+ void deleteSubstitutionFilterTest() throws BusinessLogicException {
substitutionFilterDataDefinition.setProperties(new ListDataDefinition<>());
component.setSubstitutionFilter(substitutionFilterDataDefinition);
@@ -310,7 +298,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
}
@Test
- public void deleteSubstitutionFilterFailTest() {
+ void deleteSubstitutionFilterFailTest() {
component.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
@@ -322,7 +310,6 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
.deleteSubstitutionFilter(componentId, anyInt(),true, ComponentTypeEnum.SERVICE));
@@ -341,16 +328,18 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
final UIConstraint uiConstraint =
new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
constraint = new ConstraintConvertor().convert(uiConstraint);
- requirementSubstitutionFilterPropertyDataDefinition = new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementSubstitutionFilterPropertyDataDefinition
- .setConstraints(Collections.singletonList(constraint));
+ substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
+ substitutionFilterPropertyDataDefinition
+ .setConstraints(List.of(filterConstraintMapper.mapTo(filterConstraintDto)));
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> listDataDefinition =
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> listDataDefinition =
new ListDataDefinition<>(
- Collections.singletonList(requirementSubstitutionFilterPropertyDataDefinition));
+ Collections.singletonList(substitutionFilterPropertyDataDefinition));
substitutionFilterDataDefinition = new SubstitutionFilterDataDefinition();
substitutionFilterDataDefinition.setProperties(listDataDefinition);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
index b5baca1b98..eaefe42bdc 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java
@@ -22,26 +22,25 @@
package org.openecomp.sdc.be.components.impl.utils;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
-import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
-import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
-import static org.junit.Assert.assertEquals;
-public class CINodeFilterUtilsTest {
+class CINodeFilterUtilsTest {
- private CINodeFilterUtils ciNodeFilterUtils;
+ private final CINodeFilterUtils ciNodeFilterUtils = new CINodeFilterUtils();
@Test
- public void testNodeFilterDataDefinition(){
- ciNodeFilterUtils = new CINodeFilterUtils();
+ void testNodeFilterDataDefinition() {
UploadNodeFilterInfo uNodeFilterInfo = new UploadNodeFilterInfo();
UploadNodeFilterPropertyInfo propertyInfo = new UploadNodeFilterPropertyInfo();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
index 8095a6d3e7..1f1cc5e1eb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtilsTest.java
@@ -29,7 +29,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.PatternConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java
new file mode 100644
index 0000000000..afa339f95e
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/FilterConstraintValidatorImplTest.java
@@ -0,0 +1,125 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.stream.Stream;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.FilterConstraintExceptionSupplier;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+
+class FilterConstraintValidatorImplTest {
+
+ private final FilterConstraintValidator filterConstraintValidator = new FilterConstraintValidatorImpl();
+
+ @BeforeAll
+ static void setUp() {
+ String appConfigDir = "src/test/resources/config/catalog-be";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
+ new ConfigurationManager(configurationSource);
+ }
+
+ @Test
+ void validatePropertyFilterSuccess() {
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC,
+ PropertyFilterTargetType.PROPERTY, "any");
+ assertDoesNotThrow(() -> filterConstraintValidator.validate(filterConstraintDto));
+ }
+
+ @Test
+ void validateCapabilityFilterSuccess() {
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setCapabilityName("aCapability");
+ filterConstraintDto.setPropertyName("aProperty");
+ filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
+ filterConstraintDto.setOperator(ConstraintType.EQUAL);
+ filterConstraintDto.setValueType(FilterValueType.STATIC);
+ filterConstraintDto.setValue("any");
+ assertDoesNotThrow(() -> filterConstraintValidator.validate(filterConstraintDto));
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideMissingFieldParameters")
+ void missingFieldError(FilterConstraintDto filterConstraintDto, ComponentException expectedException) {
+ final ByActionStatusComponentException actualException =
+ assertThrows(ByActionStatusComponentException.class, () -> filterConstraintValidator.validate(filterConstraintDto));
+ assertEquals(actualException.getActionStatus(), expectedException.getActionStatus());
+ assertArrayEquals(actualException.getParams(), expectedException.getParams());
+ }
+
+ public static Stream<Arguments> provideMissingFieldParameters() {
+ final var filterConstraintMissingValue = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, null);
+ final var filterConstraintMissingValueType = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, null, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingPropertyName = buildFilterConstraintDto(null, null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingCapabilityName = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, PropertyFilterTargetType.CAPABILITY, "any");
+ final var filterConstraintMissingOperator = buildFilterConstraintDto("aProperty", null, null, FilterValueType.STATIC, PropertyFilterTargetType.PROPERTY, "any");
+ final var filterConstraintMissingTargetType = buildFilterConstraintDto("aProperty", null, ConstraintType.EQUAL, FilterValueType.STATIC, null, "any");
+
+ return Stream.of(
+ Arguments.of(filterConstraintMissingValue, FilterConstraintExceptionSupplier.missingField("value").get()),
+ Arguments.of(filterConstraintMissingValueType, FilterConstraintExceptionSupplier.missingField("valueType").get()),
+ Arguments.of(filterConstraintMissingPropertyName, FilterConstraintExceptionSupplier.missingField("propertyName").get()),
+ Arguments.of(filterConstraintMissingCapabilityName, FilterConstraintExceptionSupplier.missingField("capabilityName").get()),
+ Arguments.of(filterConstraintMissingOperator, FilterConstraintExceptionSupplier.missingField("operator").get()),
+ Arguments.of(filterConstraintMissingTargetType, FilterConstraintExceptionSupplier.missingField("targetType").get())
+ );
+ }
+
+ @Test
+ void validateNullFilterConstraint() {
+ final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
+ () -> filterConstraintValidator.validate(null));
+ final ByActionStatusComponentException expectedException = FilterConstraintExceptionSupplier.filterConstraintNotProvided().get();
+ assertEquals(actualException.getActionStatus(), expectedException.getActionStatus());
+ assertArrayEquals(actualException.getParams(), expectedException.getParams());
+ }
+
+ private static FilterConstraintDto buildFilterConstraintDto(String propertyName, String capabilityName, ConstraintType constraintType,
+ FilterValueType filterValueType, PropertyFilterTargetType targetType, Object value) {
+ final var filterConstraintMissingValueType = new FilterConstraintDto();
+ filterConstraintMissingValueType.setPropertyName(propertyName);
+ filterConstraintMissingValueType.setCapabilityName(capabilityName);
+ filterConstraintMissingValueType.setTargetType(targetType);
+ filterConstraintMissingValueType.setOperator(constraintType);
+ filterConstraintMissingValueType.setValueType(filterValueType);
+ filterConstraintMissingValueType.setValue(value);
+ return filterConstraintMissingValueType;
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
deleted file mode 100644
index 621b14102f..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.components.validation;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import fj.data.Either;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import org.junit.Assert;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
-import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-public class NodeFilterValidationTest {
-
- private static final String EMPTY_STR = "";
- private static final String UI_CONSTRAINT_STATIC = "Prop1: {equal: 'value'}";
- private static final String INNER_SERVICE = "innerService";
- private static final String PROPERTY_NAME = "Prop1";
- private static final String VALUE = "value";
- private static final String FLOAT_TYPE = "float";
- private static final String STRING_TYPE = "string";
- private static final String LIST_TYPE = "list";
- private static final String COMPONENT1_ID = "component1";
- private static final String INTEGER_TYPE = "integer";
- private static final String PARENTSERVICE_ID = "parentservice";
- private static final String COMPONENT2_ID = "component2";
- private ComponentsUtils componentsUtils;
-
- @InjectMocks
- private NodeFilterValidator nodeFilterValidator;
-
- @BeforeEach
- public void setup() {
- componentsUtils = Mockito.mock(ComponentsUtils.class);
- MockitoAnnotations.openMocks(this);
- new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- }
-
- @Test
- public void testValidateComponentInstanceExist() {
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
- assertTrue(either.isRight());
- assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText());
- assertEquals(500, either.right().value().getStatus());
-
- Service service = createService("booleanIncorrect");
- either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
- assertTrue(either.isRight());
- assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText());
- assertEquals(500, either.right().value().getStatus());
-
- List<ComponentInstance> list = new LinkedList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setUniqueId("uniqueId");
- list.add(instance);
- service.setComponentInstances(list);
- either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
- assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
- Service service = createService("booleanIncorrect");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
- assertTrue(either.isRight());
-
- either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, EMPTY_STR);
- assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateComponentFilter() {
- Service service = createService("booleanIncorrect");
- String property = "Prop1: {equal: {get_property: ['test','test2']}}";
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- property = "Prop1: {equal: {get_property: ['parentservice','Prop1']}}";
- either =
- nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isLeft());
-
- String staticStr = "Prop1: {equal: 1}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isLeft());
- assertTrue(either.left().value());
-
- staticStr = "Prop1: {equal: 'true'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- staticStr = "Prop1: {greater_than: '3'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
-
- staticStr = "test: {greater_than: '3'}";
- either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr),
- NodeFilterConstraintAction.ADD);
- assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
- Service service = createService("boolean");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
- .replace("equal", "greater_than")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
- Service service = createService("boolean");
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "trues")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
- .replace("equal", "greater_than")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterIntegerValueSuccess() {
- Service service = createService(INTEGER_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterIntegerValueFail() {
- Service service = createService(INTEGER_TYPE);
-
- Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
- .thenReturn(new ResponseFormat());
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterFloatValueSuccess() {
- Service service = createService(FLOAT_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
- NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidateNodeFilterFloatValueFail() {
- Service service = createService(FLOAT_TYPE);
-
- Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
- .thenReturn(new ResponseFormat());
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isRight());
- }
-
- @Test
- public void testValidateNodeFilterStringValueSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE,
- Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintBrotherSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property :[component2, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentSuccess() {
- Service service = createService(STRING_TYPE);
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [SELF, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertTrue(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(INTEGER_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [component2, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertyTypeMismatch() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(INTEGER_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertyNotFound() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testvalidatePropertyConstraintBrotherPropertyNotFound() {
- Service service = createService(STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- @Test
- public void testValidatePropertyConstraintParentPropertySchemaMismatch() {
- Service service = createService(LIST_TYPE,STRING_TYPE);
- service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(LIST_TYPE);
-
- Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
- + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
- NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
-
- Assert.assertFalse(either.isLeft());
- }
-
- private Service createService(String type) {
- return createService(type, null);
- }
-
- private Service createService(String type, String schemaType) {
- Service service = new Service();
- service.setName(PARENTSERVICE_ID);
-
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setName(PROPERTY_NAME);
- propertyDefinition.setType(type);
- if (schemaType != null){
- SchemaDefinition schemaDefinition = new SchemaDefinition();
- PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
- schemaProperty.setType(schemaType);
- schemaDefinition.setProperty(schemaProperty);
- propertyDefinition.setSchema(schemaDefinition);
- }
- service.setProperties(Collections.singletonList(propertyDefinition));
-
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(COMPONENT1_ID);
- componentInstance.setName(COMPONENT1_ID);
-
- ComponentInstance componentInstance2 = new ComponentInstance();
- componentInstance2.setUniqueId(COMPONENT2_ID);
- componentInstance2.setName(COMPONENT2_ID);
-
- service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
-
- ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
- componentInstanceProperty.setName(PROPERTY_NAME);
- componentInstanceProperty.setType(type);
-
- ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
- componentInstanceProperty2.setName(PROPERTY_NAME);
- componentInstanceProperty2.setType(type);
-
- Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
- componentInstancePropertyMap.put(componentInstance.getUniqueId(),
- Collections.singletonList(componentInstanceProperty));
- componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
- Collections.singletonList(componentInstanceProperty2));
- componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
-
- service.setComponentInstancesProperties(componentInstancePropertyMap);
-
- return service;
- }
-
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java
new file mode 100644
index 0000000000..e1d8e46d74
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java
@@ -0,0 +1,553 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+class NodeFilterValidatorTest {
+
+ private static final String INNER_SERVICE = "innerService";
+ private static final String PROPERTY_NAME = "Prop1";
+ private static final String COMPONENT1_ID = "component1";
+ private static final String PARENTSERVICE_ID = "parentservice";
+ private static final String COMPONENT2_ID = "component2";
+ private ComponentsUtils componentsUtils;
+
+ @Mock
+ ApplicationDataTypeCache applicationDataTypeCache;
+ @Mock
+ private FilterConstraintValidator filterConstraintValidator;
+ @InjectMocks
+ private NodeFilterValidator nodeFilterValidator;
+ private FilterConstraintDto baseFilterConstraintDto;
+
+ @BeforeEach
+ void setup() {
+ componentsUtils = Mockito.mock(ComponentsUtils.class);
+ MockitoAnnotations.openMocks(this);
+ baseFilterConstraintDto = new FilterConstraintDto();
+ baseFilterConstraintDto.setPropertyName(PROPERTY_NAME);
+ baseFilterConstraintDto.setValueType(FilterValueType.STATIC);
+ baseFilterConstraintDto.setOperator(ConstraintType.EQUAL);
+ baseFilterConstraintDto.setTargetType(PropertyFilterTargetType.PROPERTY);
+ baseFilterConstraintDto.setValue("value");
+ when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(Map.of()));
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ }
+
+ @Test
+ void testValidateComponentInstanceExist() {
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+
+ Service service = createService("booleanIncorrect");
+ when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, service.getName(), INNER_SERVICE))
+ .thenReturn(expectedResponse);
+ either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+
+ List<ComponentInstance> list = new LinkedList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("uniqueId");
+ list.add(instance);
+ service.setComponentInstances(list);
+ either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
+ final Service service = createService("booleanIncorrect");
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY, "true");
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
+ assertTrue(either.isRight());
+ filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
+ either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
+ assertTrue(either.isRight());
+ }
+
+ @Test
+ void testValidateComponentFilter() {
+ Service service = createService("integer");
+ final var filterConstraint1 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"))
+ );
+ Either<Boolean, ResponseFormat> actualValidationResult =
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
+ assertTrue(actualValidationResult.isRight());
+
+ final var filterConstraint2 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"))
+ );
+ actualValidationResult =
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
+ assertTrue(actualValidationResult.isLeft());
+
+ final var staticFilter1 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ 1
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
+ assertTrue(actualValidationResult.isLeft());
+ assertTrue(actualValidationResult.left().value());
+
+ final var staticFilter2 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ "true"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
+ assertTrue(actualValidationResult.isRight());
+
+ service = createService(ToscaPropertyType.BOOLEAN.getType());
+ final var staticFilter3 = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "3"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
+ assertTrue(actualValidationResult.isRight());
+
+ final var staticFilter4 = buildFilterConstraintDto(
+ "test",
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "3"
+ );
+ actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
+ assertTrue(actualValidationResult.isRight());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
+ Service service = createService(ToscaPropertyType.BOOLEAN.getType());
+ final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.STATIC,
+ ConstraintType.GREATER_THAN,
+ PropertyFilterTargetType.PROPERTY,
+ "true"
+ );
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraintDto.getPropertyName(),
+ filterConstraintDto.getOperator().getType())
+ ).thenReturn(expectedResponse);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
+ final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
+ baseFilterConstraintDto.setValue("trues");
+
+ final ResponseFormat responseFormat = new ResponseFormat();
+ when(componentsUtils
+ .getResponseFormat(eq(ActionStatus.UNSUPPORTED_VALUE_PROVIDED), eq(ToscaPropertyType.BOOLEAN.getType()), eq(PROPERTY_NAME), any())
+ ).thenReturn(responseFormat);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(responseFormat, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ baseFilterConstraintDto.setValue("true");
+ baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterIntegerValueSuccess() {
+ Service service = createService(ToscaPropertyType.INTEGER.getType());
+ baseFilterConstraintDto.setValue(1);
+ Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ }
+
+ @Test
+ void testValidateNodeFilterIntegerValueFail() {
+ Service service = createService(ToscaPropertyType.INTEGER.getType());
+
+ baseFilterConstraintDto.setValue(1.0);
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.INTEGER.getType(),
+ baseFilterConstraintDto.getPropertyName(), "1.0")
+ ).thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidateNodeFilterFloatValueSuccess() {
+ final Service service = createService(ToscaPropertyType.FLOAT.getType());
+ baseFilterConstraintDto.setValue(1.0);
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ assertTrue(validationResult.left().value());
+ }
+
+ @Test
+ void testValidateNodeFilterFloatValueFail() {
+ Service service = createService(ToscaPropertyType.FLOAT.getType());
+
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isRight());
+ }
+
+ @Test
+ void testValidateNodeFilterStringValueSuccess() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+
+ assertTrue(either.isLeft());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherSuccess() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isLeft());
+ assertTrue(either.left().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentSuccess() {
+ final var service = createService(ToscaPropertyType.STRING.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(validationResult.isLeft());
+ assertTrue(validationResult.left().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
+ PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(), PROPERTY_NAME, ToscaPropertyType.STRING.getType())
+ ).thenReturn(expectedResponse);
+
+ final Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertyTypeMismatch() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
+ PROPERTY_NAME, ToscaPropertyType.STRING.getType(), PROPERTY_NAME, ToscaPropertyType.INTEGER.getType())
+ ).thenReturn(expectedResponse);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertyNotFound() {
+ final Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
+ .thenReturn(expectedResponse);
+
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final Either<Boolean, ResponseFormat> validationResult =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(validationResult.isRight());
+ assertEquals(expectedResponse, validationResult.right().value());
+ }
+
+ @Test
+ void testValidatePropertyConstraintBrotherPropertyNotFound() {
+ Service service = createService(ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, "Target", PROPERTY_NAME))
+ .thenReturn(expectedResponse);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
+ final PropertySource propertySource,
+ final ToscaGetFunctionType toscaGetFunctionType,
+ final List<String> propertyPathFromSource) {
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(toscaGetFunctionType);
+ toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
+ toscaGetFunction.setSourceName(sourceName);
+ toscaGetFunction.setPropertySource(propertySource);
+ toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
+ return toscaGetFunction;
+ }
+
+ @Test
+ void testValidatePropertyConstraintParentPropertySchemaMismatch() {
+ final Service service = createService(ToscaPropertyType.LIST.getType(), ToscaPropertyType.STRING.getType());
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.LIST.getType());
+ final var schemaProperty = new PropertyDataDefinition();
+ schemaProperty.setType(ToscaPropertyType.INTEGER.getType());
+ final var schemaDefinition = new SchemaDefinition();
+ schemaDefinition.setProperty(schemaProperty);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);
+
+ final ToscaGetFunctionDataDefinition toscaGetFunction =
+ createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ final var filterConstraintDto = buildFilterConstraintDto(
+ PROPERTY_NAME,
+ FilterValueType.GET_PROPERTY,
+ ConstraintType.EQUAL,
+ PropertyFilterTargetType.PROPERTY,
+ toscaGetFunction
+ );
+
+ final ResponseFormat expectedResponse = new ResponseFormat();
+ when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(),
+ PROPERTY_NAME, ToscaPropertyType.STRING.getType())
+ ).thenReturn(expectedResponse);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
+
+ assertTrue(either.isRight());
+ assertEquals(expectedResponse, either.right().value());
+ }
+
+ private Service createService(String type) {
+ return createService(type, null);
+ }
+
+ private Service createService(String type, String schemaType) {
+ Service service = new Service();
+ service.setName(PARENTSERVICE_ID);
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName(PROPERTY_NAME);
+ propertyDefinition.setType(type);
+ if (schemaType != null){
+ SchemaDefinition schemaDefinition = new SchemaDefinition();
+ PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
+ schemaProperty.setType(schemaType);
+ schemaDefinition.setProperty(schemaProperty);
+ propertyDefinition.setSchema(schemaDefinition);
+ }
+ service.setProperties(Collections.singletonList(propertyDefinition));
+
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT1_ID);
+ componentInstance.setName(COMPONENT1_ID);
+
+ ComponentInstance componentInstance2 = new ComponentInstance();
+ componentInstance2.setUniqueId(COMPONENT2_ID);
+ componentInstance2.setName(COMPONENT2_ID);
+
+ service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
+
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(PROPERTY_NAME);
+ componentInstanceProperty.setType(type);
+
+ ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
+ componentInstanceProperty2.setName(PROPERTY_NAME);
+ componentInstanceProperty2.setType(type);
+
+ Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
+ componentInstancePropertyMap.put(componentInstance.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty));
+ componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty2));
+ componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
+
+ service.setComponentInstancesProperties(componentInstancePropertyMap);
+
+ return service;
+ }
+
+ private static FilterConstraintDto buildFilterConstraintDto(final String propertyName, final FilterValueType valueType,
+ final ConstraintType constraintType,
+ final PropertyFilterTargetType targetType, Object value) {
+ final var filterConstraintDto = new FilterConstraintDto();
+ filterConstraintDto.setPropertyName(propertyName);
+ filterConstraintDto.setValueType(valueType);
+ filterConstraintDto.setOperator(constraintType);
+ filterConstraintDto.setTargetType(targetType);
+ filterConstraintDto.setValue(value);
+ return filterConstraintDto;
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
index 9864cf456d..a66b19d1b3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
@@ -19,10 +19,9 @@
package org.openecomp.sdc.be.datamodel;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.hibernate.validator.internal.util.CollectionHelper.asSet;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,8 +46,12 @@ import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -336,15 +339,27 @@ public class UiComponentDataConverterTest {
SubstitutionFilterDataDefinition substitutionFilter = new SubstitutionFilterDataDefinition();
substitutionFilter.setID(SUBSTITUTION_FILTER_UID);
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> expectedPropertyFilters = new ListDataDefinition<>();
- var filter1 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> expectedPropertyFilters = new ListDataDefinition<>();
+ var filter1 = new SubstitutionFilterPropertyDataDefinition();
filter1.setName("filter1");
- filter1.setConstraints(Collections.singletonList("constraint1: {equal: testvalue1}\n"));
+ var propertyFilter1 = new PropertyFilterConstraintDataDefinition();
+ propertyFilter1.setPropertyName("constraint1");
+ propertyFilter1.setOperator(ConstraintType.EQUAL);
+ propertyFilter1.setValueType(FilterValueType.STATIC);
+ propertyFilter1.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilter1.setValue("testvalue1");
+ filter1.setConstraints(List.of(propertyFilter1));
expectedPropertyFilters.add(filter1);
- var filter2 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ var filter2 = new SubstitutionFilterPropertyDataDefinition();
filter2.setName("filter2");
- filter2.setConstraints(Collections.singletonList("constraint2: {equal: testvalue2}\n"));
+ var propertyFilter2 = new PropertyFilterConstraintDataDefinition();
+ propertyFilter2.setPropertyName("constraint2");
+ propertyFilter2.setOperator(ConstraintType.EQUAL);
+ propertyFilter2.setValueType(FilterValueType.STATIC);
+ propertyFilter2.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilter2.setValue("testvalue2");
+ filter2.setConstraints(List.of(propertyFilter2));
expectedPropertyFilters.add(filter2);
substitutionFilter.setProperties(expectedPropertyFilters);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java
index 109af5562a..75eb48b86c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertorTest.java
@@ -13,33 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openecomp.sdc.be.tosca.model;
-import org.junit.Test;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
-import org.openecomp.sdc.be.ui.model.UIConstraint;
+package org.openecomp.sdc.be.datamodel.utils;
+
+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 java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-public class ConstraintConvertorTest {
+class ConstraintConvertorTest {
@Test
- public void convertStatic(){
+ void convertStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: some static}\n");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"some static");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals("some static",uiConstraint.getValue());
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
}
@Test
- public void convertFromStatic(){
+ void convertFromStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "some static");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -48,19 +49,19 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertSelfProperty(){
+ void convertSelfProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n {equal: { get_property: [SELF, size] }}");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"size");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
- assertEquals(uiConstraint.getSourceName().trim(),"SELF");
- assertEquals(uiConstraint.getSourceType(), ConstraintConvertor.PROPERTY_CONSTRAINT);
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals(uiConstraint.getValue(), Map.of(ToscaFunctionType.GET_PROPERTY.getName(), List.of("SELF", "size")));
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
+ assertEquals("SELF",uiConstraint.getSourceName().trim());
+ assertEquals(uiConstraint.getSourceType(), ToscaFunctionType.GET_PROPERTY.getName());
}
@Test
- public void convertFromSelfProperty(){
+ void convertFromSelfProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "SELF" ,"some static");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -69,19 +70,19 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertCIProperty(){
+ void convertCIProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: { get_property: [A, size]}");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"equal");
- assertEquals(uiConstraint.getValue(),"size");
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
- assertEquals(uiConstraint.getSourceName().trim(),"A");
+ assertEquals("equal",uiConstraint.getConstraintOperator());
+ assertEquals(uiConstraint.getValue(),Map.of(ToscaFunctionType.GET_PROPERTY.getName(), List.of("A", "size")));
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
+ assertEquals("A",uiConstraint.getSourceName().trim());
}
@Test
- public void convertFromCIProperty(){
+ void convertFromCIProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "A" ,"size");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -90,14 +91,14 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertServiceTemplateInput(){
+ void convertServiceTemplateInput(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: {get_input: InputName}}\n");
assertNotNull(uiConstraint);
}
@Test
- public void convertFromServiceTemplateInput(){
+ void convertFromServiceTemplateInput(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -106,17 +107,17 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertGreaterThanStatic(){
+ void convertGreaterThanStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {greater_than: 2}\n");
assertNotNull(uiConstraint);
- assertEquals(uiConstraint.getConstraintOperator(),"greater_than");
- assertEquals(uiConstraint.getValue(),2);
- assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals("greater_than",uiConstraint.getConstraintOperator());
+ assertEquals(2,uiConstraint.getValue());
+ assertEquals("mem_size",uiConstraint.getServicePropertyName().trim());
}
@Test
- public void convertFromGreaterThanStatic(){
+ void convertFromGreaterThanStatic(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "greater_than" , ConstraintConvertor.STATIC_CONSTRAINT, 2);
String constraint = constraintConvertor.convert(uiConstraint);
@@ -125,14 +126,14 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertLessThanServiceProperty(){
+ void convertLessThanServiceProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {less_then: {get_input: InputName}}");
assertNotNull(uiConstraint);
}
@Test
- public void convertFromLessThanServiceProperty(){
+ void convertFromLessThanServiceProperty(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "less_then" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -141,7 +142,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertFromEqualStaticMap(){
+ void convertFromEqualStaticMap(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "{x: xx,"+
" y: yy}\n");
@@ -151,7 +152,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertStringToMap(){
+ void convertStringToMap(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: {x: xx, y: yy}\n");
assertNotNull(uiConstraint);
@@ -159,7 +160,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertFromEqualStaticList(){
+ void convertFromEqualStaticList(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "[x, y]\n");
String constraint = constraintConvertor.convert(uiConstraint);
@@ -168,7 +169,7 @@ public class ConstraintConvertorTest {
}
@Test
- public void convertStringToList(){
+ void convertStringToList(){
ConstraintConvertor constraintConvertor = new ConstraintConvertor();
UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: [x, y]\n");
assertNotNull(uiConstraint);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
index 68ceaca0a6..7948f84f96 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java
@@ -16,13 +16,18 @@
package org.openecomp.sdc.be.nodeFilter;
-import java.util.Arrays;
-import org.junit.Assert;
-import org.junit.Before;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Service;
@@ -32,47 +37,60 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource;
public class BaseServiceFilterUtilsTest {
protected Service service;
- protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
- protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2;
+ protected PropertyFilterDataDefinition propertyFilterDataDefinition;
+ protected PropertyFilterDataDefinition propertyFilterDataDefinition2;
protected static final String CI_NAME = "AAAAAA";
protected static final String A_PROP_NAME = "A_PROP";
protected static final String SIZE_PROP = "size";
- protected static final String ORIG_COMP_INSTANCE_ID = "54355645457457";
- @Before
- public void initService() {
- try {
- new ConfigurationManager(new FSConfigurationSource(
- ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- service = new Service();
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(CI_NAME);
- componentInstance.setName(CI_NAME);
- service.setComponentInstances(Arrays.asList(componentInstance));
- componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDirectives());
- CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
- componentInstance.setNodeFilter(serviceFilter);
- requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName("Name1");
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n" + " equal: { get_property : [" + CI_NAME + ", size]}\n"));
- requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition2.setName("Name2");
- requirementNodeFilterPropertyDataDefinition2
- .setConstraints(Arrays.asList("mem_size:\n {equal: { get_property : [SELF, "+A_PROP_NAME+"]}}\n"));
+ @BeforeEach
+ void initService() {
+ new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ service = new Service();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(CI_NAME);
+ componentInstance.setName(CI_NAME);
+ service.setComponentInstances(List.of(componentInstance));
+ componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getDirectives());
+ CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
+ componentInstance.setNodeFilter(serviceFilter);
+ propertyFilterDataDefinition = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName("Name1");
+ final var propertyFilterConstraint1 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint1.setPropertyName("mem_size");
+ propertyFilterConstraint1.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint1.setValue(createToscaGetFunction(CI_NAME, ToscaGetFunctionType.GET_PROPERTY, List.of("size")));
+ propertyFilterConstraint1.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint1.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint1));
+ propertyFilterDataDefinition2 = new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition2.setName("Name2");
+ final var propertyFilterConstraint2 = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint2.setPropertyName("mem_size");
+ propertyFilterConstraint2.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint2.setValue(createToscaGetFunction("SELF", ToscaGetFunctionType.GET_PROPERTY, List.of(A_PROP_NAME)));
+ propertyFilterConstraint2.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint2.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition2.setConstraints(List.of(propertyFilterConstraint2));
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(Arrays.asList(
- requirementNodeFilterPropertyDataDefinition,
- requirementNodeFilterPropertyDataDefinition2));
- serviceFilter.setProperties(listDataDefinition);
- PropertyDefinition property = new PropertyDefinition();
- property.setName(A_PROP_NAME);
- service.setProperties(Arrays.asList(property));
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
+ ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(List.of(propertyFilterDataDefinition, propertyFilterDataDefinition2));
+ serviceFilter.setProperties(listDataDefinition);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(A_PROP_NAME);
+ service.setProperties(List.of(property));
+ }
+
+ protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
+ final ToscaGetFunctionType toscaGetFunctionType,
+ final List<String> propertyPathFromSource) {
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(toscaGetFunctionType);
+ toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
+ toscaGetFunction.setSourceName(sourceName);
+ toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
+ return toscaGetFunction;
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
index 8e94b94e61..d18f6039f2 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java
@@ -16,31 +16,28 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.List;
import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterRenameCiTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterRenameCiTest extends BaseServiceFilterUtilsTest {
protected static final String CI_NEW_NAME = "BBBBB";
@Test
- public void renameCI() {
+ void renameCI() {
Map<String, CINodeFilterDataDefinition> renamedNodeFilters = getRenamedNodeFilters(CI_NAME, CI_NEW_NAME);
assertNotNull(renamedNodeFilters);
- final List<String> constraints =
+ final List<PropertyFilterConstraintDataDefinition> constraints =
renamedNodeFilters.get(CI_NAME).getProperties().getListToscaDataDefinition().iterator().next()
.getConstraints();
- assertEquals(1,constraints.size());
- final String constraint = constraints.iterator().next();
- assertTrue(constraint.contains(CI_NEW_NAME));
+ assertEquals(1, constraints.size());
}
private Map<String, CINodeFilterDataDefinition> getRenamedNodeFilters(String oldName, String newName) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
index 57b95e2fbe..374e8209ed 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java
@@ -16,13 +16,25 @@
package org.openecomp.sdc.be.nodeFilter;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import fj.data.Either;
-import org.junit.Test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServiceFilterUtils;
import org.openecomp.sdc.be.model.ComponentInstance;
@@ -31,43 +43,38 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Set;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest {
-
+class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest {
@Test
- public void checkComponentInstanceIsFound() {
+ void checkComponentInstanceIsFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME);
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
}
private Set<String> getNodeFiltersToBeDeleted(String inCiName) {
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n" + " equal:\n" + " get_property: ["+CI_NAME+", some static]\n"));
- ComponentInstance ci = new ComponentInstance();
- ci.setName(inCiName);
- return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, ci);
+ final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setPropertyName("mem_size");
+ propertyFilterConstraint.setOperator(ConstraintType.EQUAL);
+ propertyFilterConstraint.setValue(createToscaGetFunction(CI_NAME, ToscaGetFunctionType.GET_PROPERTY, List.of("some static")));
+ propertyFilterConstraint.setValueType(FilterValueType.GET_PROPERTY);
+ propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition
+ .setConstraints(List.of(propertyFilterConstraint));
+ final var componentInstance = new ComponentInstance();
+ componentInstance.setName(inCiName);
+ return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, componentInstance);
}
@Test
- public void checkComponentInstanceIsNotFound() {
+ void checkComponentInstanceIsNotFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME + " aaa bbb");
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.isEmpty());
- assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME));
}
@Test
- public void testServiceConstraintPairSerialization() throws IOException {
+ void testServiceConstraintPairSerialization() throws IOException {
UIConstraint uiConstraint =new UIConstraint();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
index 0b40359d60..47f462bb15 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java
@@ -16,23 +16,24 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-public class ServiceFilterUtilsPropertyRemovedTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterUtilsPropertyRemovedTest extends BaseServiceFilterUtilsTest {
@Test
- public void checkPropertyIsFound() {
+ void checkPropertyIsFound() {
assertTrue(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, SIZE_PROP));
}
@Test
- public void checkPropertyIsNotFound() {
+ void checkPropertyIsNotFound() {
assertFalse(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, A_PROP_NAME + "XXXX"));
}
}
+
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
index e17da93b0e..0d473518cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java
@@ -16,42 +16,52 @@
package org.openecomp.sdc.be.nodeFilter;
-import org.junit.Test;
-import org.openecomp.sdc.be.impl.ServiceFilterUtils;
-import org.openecomp.sdc.be.model.InputDefinition;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Arrays;
+import java.util.List;
import java.util.Set;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
+import org.openecomp.sdc.be.model.InputDefinition;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest {
+class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest {
private static final String CONSTRAINT_NAME = "InputName";
-
@Test
- public void checkInputStreamIsFound() {
+ void checkInputStreamIsFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME);
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
}
private Set<String> getNodeFiltersToBeDeleted(String constraintName) {
- requirementNodeFilterPropertyDataDefinition
- .setConstraints(Arrays.asList("mem_size:\n equal: {get_input: " + CONSTRAINT_NAME + "}\n"));
+ final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
+ propertyFilterConstraint.setPropertyName("mem_size");
+ propertyFilterConstraint.setOperator(ConstraintType.EQUAL);
+
+ propertyFilterConstraint.setValue(
+ createToscaGetFunction(PropertySource.SELF.getName(), ToscaGetFunctionType.GET_INPUT, List.of(CONSTRAINT_NAME))
+ );
+ propertyFilterConstraint.setValueType(FilterValueType.GET_INPUT);
+ propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
+ propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint));
InputDefinition inputDefinition = new InputDefinition();
inputDefinition.setName(constraintName);
return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, inputDefinition);
}
@Test
- public void checkInputStreamIsNOtFound() {
+ public void checkInputStreamIsNotFound() {
Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME + " aaa bbb");
assertNotNull(nodesFiltersToBeDeleted);
assertTrue(nodesFiltersToBeDeleted.isEmpty());
- assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
index 548a046229..49252109cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.servlets;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -35,8 +34,8 @@ import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.Arrays;
import java.util.LinkedList;
+import java.util.List;
import java.util.Optional;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -49,7 +48,6 @@ import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
-import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -57,7 +55,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -65,7 +62,6 @@ import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
@@ -73,14 +69,16 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -111,6 +109,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
private static final String V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER = "/v1/catalog/%s/%s/componentInstance/%s/%s/nodeFilter";
private final UIConstraint uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
private final String constraint = new ConstraintConvertor().convert(uiConstraint);
+ private final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint);
private final String inputJson = buildConstraintDataJson(uiConstraint);
private final User user = new User("", "", USER_ID, "", Role.ADMIN.name(), null);
@Mock
@@ -176,7 +175,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
}
@Test
- void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
+ void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException {
initComponentData();
final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
final String path = String.format(pathFormat, componentType, componentId, componentInstance,
@@ -194,7 +193,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
doReturn(Optional.of(uiConstraint)).when(componentsUtils)
- .parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class));
+ .parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class));
assertNotNull(constraint);
assertNotNull(ciNodeFilterDataDefinition);
@@ -202,8 +201,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
doReturn(Optional.of(ciNodeFilterDataDefinition)).when(componentNodeFilterBusinessLogic)
- .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
- uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
NodeFilterConstraintType.PROPERTIES, "");
final Response response = target()
@@ -213,9 +211,9 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
- anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
+ .addNodeFilter(anyString(), anyString(), any(FilterConstraintDto.class), anyBoolean(), any(ComponentTypeEnum.class),
+ any(NodeFilterConstraintType.class), anyString()
+ );
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -224,8 +222,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
@Test
void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
initComponentData();
- final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
- final String path = String.format(pathFormat, componentType, componentId, componentInstance,
+ final String path = String.format(V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER, componentType, componentId, componentInstance,
NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
final UIConstraint uiConstraint1 = new UIConstraint(uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator(),
uiConstraint.getSourceType(), uiConstraint.getSourceName(), uiConstraint.getValue());
@@ -234,27 +231,24 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
uiConstraint1.setCapabilityName(capabilityName);
-
- when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
- .thenReturn(Optional.of(uiConstraint1));
+ final String requestPayload = buildConstraintDataJson(uiConstraint1);
+ when(componentsUtils.parseToConstraint(requestPayload, user, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(uiConstraint1));
assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
+ final FilterConstraintDto filterConstraintDto1 = new FilterConstraintMapper().mapFrom(uiConstraint1);
when(componentNodeFilterBusinessLogic
- .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
- uiConstraint1.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.CAPABILITIES, capabilityName))
- .thenReturn(Optional.of(ciNodeFilterDataDefinition));
-
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName)
+ ).thenReturn(Optional.of(ciNodeFilterDataDefinition));
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
.header(USER_ID_HEADER, USER_ID)
- .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
+ .post(Entity.entity(requestPayload, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
- anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
+ .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
+ NodeFilterConstraintType.CAPABILITIES, capabilityName);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -352,7 +346,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
- when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
+ when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
.thenReturn(Optional.of(uiConstraint));
doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
@@ -370,8 +364,8 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
verify(componentNodeFilterBusinessLogic, times(1))
- .updateNodeFilter(anyString(), anyString(), ArgumentMatchers.any(UIConstraint.class),
- ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class),
+ .updateNodeFilter(anyString(), anyString(), any(UIConstraint.class),
+ any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class),
anyInt());
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
@@ -447,9 +441,8 @@ class ComponentNodeFilterServletTest extends JerseyTest {
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentNodeFilterBusinessLogic.deleteNodeFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.RESOURCE,
- NodeFilterConstraintType.PROPERTIES))
+ when(componentNodeFilterBusinessLogic
+ .deleteNodeFilter(componentId, componentInstance, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
.thenReturn(Optional.of(ciNodeFilterDataDefinition));
final Response response = target()
@@ -460,9 +453,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.delete(Response.class);
verify(componentNodeFilterBusinessLogic, times(1))
- .deleteNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class),
- nullable(String.class), anyInt(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
- ArgumentMatchers.any(NodeFilterConstraintType.class));
+ .deleteNodeFilter(anyString(), anyString(), anyInt(), anyBoolean(), any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class));
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
@@ -503,14 +494,14 @@ class ComponentNodeFilterServletTest extends JerseyTest {
.property("contextConfig", context);
}
- private void initComponentData() throws JsonProcessingException {
- final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
- new RequirementNodeFilterPropertyDataDefinition();
- requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
+ private void initComponentData() {
+ final PropertyFilterDataDefinition propertyFilterDataDefinition =
+ new PropertyFilterDataDefinition();
+ propertyFilterDataDefinition.setName(uiConstraint.getServicePropertyName());
+ propertyFilterDataDefinition.setConstraints(new LinkedList<>(List.of(new FilterConstraintMapper().mapTo(filterConstraintDto))));
- final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
+ final ListDataDefinition<PropertyFilterDataDefinition> propertyDataDefinitionList =
+ new ListDataDefinition<>(new LinkedList<>(List.of(propertyFilterDataDefinition)));
final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
new RequirementNodeFilterCapabilityDataDefinition();
@@ -518,7 +509,7 @@ class ComponentNodeFilterServletTest extends JerseyTest {
requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
- new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterCapabilityDataDefinition)));
+ new ListDataDefinition<>(new LinkedList<>(List.of(requirementNodeFilterCapabilityDataDefinition)));
ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
index bcc0f2eadb..9bd7244e04 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java
@@ -22,11 +22,11 @@ package org.openecomp.sdc.be.servlets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
@@ -36,9 +36,8 @@ import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.Arrays;
import java.util.Collections;
-import java.util.LinkedList;
+import java.util.List;
import java.util.Optional;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -46,7 +45,6 @@ import javax.servlet.http.HttpSession;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
import org.eclipse.jetty.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
@@ -62,24 +60,24 @@ import org.openecomp.sdc.be.components.impl.ComponentSubstitutionFilterBusinessL
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.validation.UserValidations;
-import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
+import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -112,13 +110,11 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
private static ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic;
private static ResponseFormat responseFormat;
private static UserValidations userValidations;
- private static ConfigurationManager configurationManager;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
- private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
private UIConstraint uiConstraint;
- private String constraint;
private String inputJson;
private User user;
+ private FilterConstraintDto filterConstraintDto;
@BeforeAll
public static void initClass() {
@@ -135,7 +131,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
String appConfigDir = "src/test/resources/config/catalog-be";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- configurationManager = new ConfigurationManager(configurationSource);
+ ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
configuration.setJanusGraphInMemoryGraph(true);
configurationManager.setConfiguration(configuration);
@@ -155,7 +151,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterTest() throws Exception {
+ void addSubstitutionFilterTest() throws Exception {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -165,21 +161,19 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
assertNotNull(uiConstraint);
- assertThat(servicePropertyName).isEqualToIgnoringCase(uiConstraint.getServicePropertyName());
- assertThat(constraintOperator).isEqualToIgnoringCase(uiConstraint.getConstraintOperator());
- assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
- assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
- assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
+ assertThat(uiConstraint.getServicePropertyName()).isEqualToIgnoringCase(servicePropertyName);
+ assertThat(uiConstraint.getConstraintOperator()).isEqualToIgnoringCase(constraintOperator);
+ assertThat(uiConstraint.getSourceType()).isEqualToIgnoringCase(sourceType);
+ assertThat(uiConstraint.getSourceName()).isEqualToIgnoringCase(sourceName);
+ assertThat(uiConstraint.getValue().toString()).isEqualToIgnoringCase(propertyValue);
when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
.thenReturn(Optional.of(uiConstraint));
- assertNotNull(constraint);
assertNotNull(substitutionFilterDataDefinition);
assertThat(substitutionFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
- assertThat("controller_actor: {equal: constraintValue}\n").isEqualToIgnoringCase(constraint);
- when(componentSubstitutionFilterBusinessLogic.addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
- true, ComponentTypeEnum.SERVICE)).thenReturn(Optional.of(substitutionFilterDataDefinition));
+ when(componentSubstitutionFilterBusinessLogic.addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE))
+ .thenReturn(Optional.of(substitutionFilterDataDefinition));
final Response response = target()
.path(path)
@@ -190,12 +184,11 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentSubstitutionFilterBusinessLogic, times(1))
- .addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
- true, ComponentTypeEnum.SERVICE);
+ .addSubstitutionFilter(componentId, filterConstraintDto, true, ComponentTypeEnum.SERVICE);
}
@Test
- public void addSubstitutionFilterFailConstraintParseTest() {
+ void addSubstitutionFilterFailConstraintParseTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -216,7 +209,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterFailTest() {
+ void addSubstitutionFilterFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -237,7 +230,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterTest() throws BusinessLogicException {
+ void updateSubstitutionFilterTest() throws BusinessLogicException {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -250,7 +243,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
any(User.class))).thenReturn(Collections.singletonList(uiConstraint));
when(componentSubstitutionFilterBusinessLogic.updateSubstitutionFilter(componentId.toLowerCase(),
- Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE))
+ List.of(filterConstraintDto), true, ComponentTypeEnum.SERVICE))
.thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
final Response response = target()
@@ -266,7 +259,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterFailConstraintParseTest() {
+ void updateSubstitutionFilterFailConstraintParseTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -287,7 +280,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterFailTest() {
+ void updateSubstitutionFilterFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -308,7 +301,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void deleteSubstitutionFilterConstraintTest() throws BusinessLogicException {
+ void deleteSubstitutionFilterConstraintTest() throws BusinessLogicException {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -334,7 +327,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void deleteSubstitutionFilterConstraintFailTest() {
+ void deleteSubstitutionFilterConstraintFailTest() {
final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
final String path = String.format(pathFormat, componentType, componentId, constraintType);
@@ -390,16 +383,16 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
private void initComponentData() throws JsonProcessingException {
uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
- constraint = new ConstraintConvertor().convert(uiConstraint);
+ final FilterConstraintMapper filterConstraintMapper = new FilterConstraintMapper();
+ filterConstraintDto = filterConstraintMapper.mapFrom(uiConstraint);
inputJson = buildConstraintDataJson(uiConstraint);
- requirementSubstitutionFilterPropertyDataDefinition = new RequirementSubstitutionFilterPropertyDataDefinition();
- requirementSubstitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
- requirementSubstitutionFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
+ SubstitutionFilterPropertyDataDefinition substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition();
+ substitutionFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
+ substitutionFilterPropertyDataDefinition.setConstraints(List.of(filterConstraintMapper.mapTo(filterConstraintDto)));
- final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> listDataDefinition =
- new ListDataDefinition<>(
- new LinkedList<>(Arrays.asList(requirementSubstitutionFilterPropertyDataDefinition)));
+ final ListDataDefinition<SubstitutionFilterPropertyDataDefinition> listDataDefinition =
+ new ListDataDefinition<>(List.of(substitutionFilterPropertyDataDefinition));
substitutionFilterDataDefinition = new SubstitutionFilterDataDefinition();
substitutionFilterDataDefinition.setProperties(listDataDefinition);
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
index 293bd49632..81e302f8bd 100644
--- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -111,6 +111,12 @@ errors:
message: "Error: Invalid userId '%1'.",
messageId: "SVC4008"
}
+ #---------SVC4009-----------------------------
+ USER_DEFINED: {
+ code: 400,
+ message: "Error: User Defined '%1'.",
+ messageId: "SVC4009"
+ }
#---------SVC4049------------------------------
# %1 - service/resource
COMPONENT_MISSING_CONTACT: {
@@ -1430,10 +1436,10 @@ errors:
message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
messageId: "SVC4618"
}
-#---------SVC4619------------------------------
-# %1 - artifact name
-# %2 - artifact type
-# %3 - existing artifact type
+ #---------SVC4619------------------------------
+ # %1 - artifact name
+ # %2 - artifact type
+ # %3 - existing artifact type
ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR: {
code: 400,
message: "Error: artifact %1 in type %2 already exists in type %3.",
@@ -1797,9 +1803,11 @@ errors:
messageId: "SVC4669"
}
#---------SVC4670------------------------------
+ # %1 - artifactname
+ # %2 - validname
ARTIFACT_NAME_INVALID: {
code: 400,
- message: "Error: Artifact name is invalid.",
+ message: "Error: Artifact name '%1' is invalid. Only the following characters are allowed in the Artifact Name: '%2'.",
messageId: "SVC4670"
}
#---------SVC4671------------------------------
@@ -1909,6 +1917,22 @@ errors:
message: "Error: Invalid policy name %1 received.",
messageId: "SVC4684"
}
+ #---------SVC4801------------------------------
+ # %1 - policy type
+ POLICY_TYPE_IS_INVALID: {
+ code: 400,
+ message: "Error: Invalid content. Policy type %1 does not exist",
+ messageId: "SVC4801"
+ }
+
+ #---------SVC4802------------------------------
+ # %1 - policy name
+ POLICY_MISSING_POLICY_TYPE: {
+ code: 400,
+ message: "Error: Invalid content. Type name is not defined for policy %1",
+ messageId: "SVC4802"
+ }
+
#---------SVC4685------------------------------
# %1 - policy name
POLICY_NAME_ALREADY_EXIST: {
@@ -1988,7 +2012,7 @@ errors:
#---------SVC4695-----------------------------
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_ALREADY_IN_USE: {
- code: 400,
+ code: 409,
message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4695"
}
@@ -1996,20 +2020,20 @@ errors:
# %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_INVALID: {
code: 400,
- message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space, numbers and should not be greater than 200 characters.",
+ message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space and should not be greater than 200 characters.",
messageId: "SVC4696"
}
#---------SVC4697-----------------------------
INTERFACE_OPERATION_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
messageId: "SVC4697"
}
#---------SVC4698-----------------------------
- # %1 - Interface Operation description
- INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: {
+ # %1 - Interface type
+ INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE: {
code: 400,
- message: "Error: Interface Operation description '%1' is invalid, maximum 200 characters allowed.",
+ message: "Error: Invalid input, only one operation is allowed in local interface type '%1'.",
messageId: "SVC4698"
}
#---------SVC4699-----------------------------
@@ -2021,20 +2045,20 @@ errors:
}
#---------SVC4700-----------------------------
INTERFACE_OPERATION_INPUT_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface operation input parameter name should not be empty.",
messageId: "SVC4700"
}
#---------SVC4701-----------------------------
- # %1 - resource Id
+ # %1 - component Id
INTERFACE_OPERATION_NOT_FOUND: {
code: 404,
- message: "Error: Interface operation not found in the resource '%1'.",
+ message: "Error: Interface operation not found in the component '%1'.",
messageId: "SVC4701"
}
#---------SVC4702-----------------------------
INTERFACE_OPERATION_NOT_DELETED: {
- code: 404,
+ code: 400,
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
@@ -2107,25 +2131,32 @@ errors:
message: "Error: CSAR packaging failed for %1 %2.",
messageId: "SVC4706"
}
- #---------SVC4704-----------------------------
- # %1 - Interface Operation input property name
+ #---------SVC4708-----------------------------
+ # %1 - Interface Operation input property name, component type
INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: {
code: 404,
- message: "Error: Interface operation input parameter property '%1' not found in component input properties.",
- messageId: "SVC4704"
+ message: "Error: Interface operation input parameter property '%1' not found in '%2' input properties, capability properties or outputs of other operations.",
+ messageId: "SVC4708"
}
- #---------SVC4705-----------------------------
+ #---------SVC4709-----------------------------
# %1 - Interface Operation output parameter name
INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: {
code: 400,
message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.",
- messageId: "SVC4705"
+ messageId: "SVC4708"
}
- #---------SVC4706-----------------------------
+ #---------SVC4710-----------------------------
INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: {
- code: 404,
+ code: 400,
message: "Error: Interface operation output parameter name should not be empty.",
- messageId: "SVC4706"
+ messageId: "SVC4710"
+ }
+ #---------SVC4711-----------------------------
+ # %1 - interface Id
+ INTERFACE_NOT_FOUND_IN_COMPONENT: {
+ code: 404,
+ message: "Error: Interface not found in the component '%1'.",
+ messageId: "SVC4711"
}
#---------SVC4709-----------------------------
INVALID_PROPERTY_CONSTRAINTS: {
@@ -2237,34 +2268,177 @@ errors:
message: "Error: Missing value for the mandatory %1 property" ,
messageId: "SVC4721"
}
+ #---------SVC4712-----------------------------
+ INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: {
+ code: 404,
+ message: "Error: Interface Lifecycle types not found.",
+ messageId: "SVC4712"
+ }
+ #---------SVC4713-----------------------------
+ # %1 - Interface Operation Name
+ INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE: {
+ code: 400,
+ message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
+ messageId: "SVC4713"
+ }
+
+ #---------SVC4714-----------------------------
+ NODE_FILTER_NOT_FOUND: {
+ code: 400,
+ message: "Error: Node Filter was not found",
+ messageId: "SVC4714"
+ }
+ #---------SVC4715----------------------------
+ UNSUPPORTED_VALUE_PROVIDED: {
+ code: 400,
+ message: "Error: Supported value type is %1 for %2 property. Provided Value: %3",
+ messageId: "SVC4715"
+ }
+ #---------SVC4716----------------------------
+ # %1 - Property Name
+ SELECTED_PROPERTY_NOT_PRESENT: {
+ code: 400,
+ message: "Error: %1 property does not exists in Service anymore.",
+ messageId: "SVC4716"
+ }
+
+ #---------SVC4184----------------------------
+ # %1 - Source type
+ # %2 - Property Type
+ # %3 - Property Name
+ FILTER_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "%1 %2 %3 does not exist."
+ messageId: "SVC4184"
+
+ #---------SVC4718----------------------------
+ # %1 - Property Name
+ # %2 - Operator Name
+ UNSUPPORTED_OPERATOR_PROVIDED: {
+ code: 400,
+ message: "Error: %1 property does not support %2 operator.",
+ messageId: "SVC4718"
+ }
+
+ #---------SVC4719----------------------------
+ CONSTRAINT_FORMAT_INCORRECT: {
+ code: 400,
+ message: "Error: Constraint provided does not contains expected values.",
+ messageId: "SVC4719"
+ }
+
+ #---------SVC4182----------------------------
+ # %1 - Property Name
+ # %2 - Operator Type
+ SOURCE_TARGET_PROPERTY_TYPE_MISMATCH: {
+ code: 400,
+ message: "Error: Property '%1' type '%2' does not match with property '%3' type '%4'.",
+ messageId: "SVC4182"
+ }
+
+ #---------SVC4721----------------------------
+ # %1 - Property Type
+ # %2 - Operator Type
+ UNSUPPORTED_PROPERTY_TYPE: {
+ code: 400,
+ message: "Error: Property type %1 provided against %2 is not supported for static value.",
+ messageId: "SVC4721"
+ }
+
#---------SVC4722------------------------------
+ # %1 Directive value set
+ DIRECTIVES_INVALID_VALUE: {
+ code: 404,
+ message: "Error: Invalid directive value : '%1' .",
+ messageId: "SVC4722"
+ }
+ #---------SVC4723-----------------------------
+ # %1 - Interface Operation output name
+ INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED: {
+ code: 400,
+ message: "Error: Cannot update or delete interface operation output(s) '%1' mapped to an operation input",
+ messageId: "SVC4723"
+ }
+ #---------SVC4724-----------------------------
+ # %1 - Interface Operation output name
+ INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT: {
+ code: 400,
+ message: "Error: Cannot delete interface operation with output(s) '%1' mapped to another operation input",
+ messageId: "SVC4724"
+ }
+ #---------SVC4725-----------------------------
+ INVALID_CONSUMPTION_TYPE: {
+ code: 400,
+ message: "Error: Given value is different than input type. Needs to be %1",
+ messageId: "SVC4725"
+ }
+ #---------SVC4726-----------------------------
+ INVALID_PROPERTY_VALUES: {
+ code: 400,
+ message: "Error: Invalid property values provided:\n %1",
+ messageId: "SVC4726"
+ }
+ #---------SVC4727------------------------------
+ INVALID_PROPERTY_NAME: {
+ code: 400,
+ message: "Error: Property name contains invalid characters. It should have only letters, numbers and underscores.",
+ messageId: "SVC4727"
+ }
+
+ #---------SVC4728------------------------------
+ FAILED_TO_CREATE_OR_UPDATE_CAPABILITY_PROPERTIES: {
+ code: 500,
+ message: "Error: Failed to create or update capabilities properties",
+ messageId: "SVC4728"
+ }
+
+ #---------SVC4729------------------------------
+ # %1 - resource Id
+ CAPABILITY_PROPERTIES_NOT_FOUND: {
+ code: 400,
+ message: "Error: Capability properties not found in the resource '%1'.",
+ messageId: "SVC4729"
+ }
+ #---------SVC4730------------------------------
# %1 - property name
PROPERTY_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 exceeds limit.",
messageId: "SVC4722"
}
- #---------SVC4723------------------------------
+ #---------SVC4731------------------------------
INVALID_PROPERY: {
# %1 - property name
code: 400,
message: 'Error: Invalid Content. %1 has invalid format.',
messageId: "SVC4723"
}
- #---------SVC4801------------------------------
- # %1 - policy type
- POLICY_TYPE_IS_INVALID: {
+ #---------SVC4734------------------------------
+ # %1 - list of validation errors
+ INVALID_PM_DICTIONARY_FILE: {
code: 400,
- message: "Error: Invalid content. Policy type %1 does not exist",
- messageId: "SVC4801"
+ message: 'Error: Invalid PM Dictionary File. %1',
+ messageId: "SVC4734"
}
-
- #---------SVC4802------------------------------
- # %1 - policy name
- POLICY_MISSING_POLICY_TYPE: {
+ #-----------SVC4735---------------------------
+ #%1 - input name
+ INPUT_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Input with '%1' name already exists.",
+ messageId: "SVC4735"
+ }
+ #---------SVC4736------------------------------
+ INVALID_INPUT_NAME: {
code: 400,
- message: "Error: Invalid content. Type name is not defined for policy %1",
- messageId: "SVC4802"
+ message: "Error: Input name contains invalid characters. It should have only letters, numbers and underscores.",
+ messageId: "SVC4736"
+ }
+ #---------SVC4139------------------------------
+ # %1 - The action that is not supported
+ NOT_SUPPORTED: {
+ code: 400,
+ message: '%1 is not yet supported',
+ messageId: "SVC4139"
}
#---------SVC4140------------------------------
# %1 - Component uid
@@ -2294,31 +2468,172 @@ errors:
message: "An unexpected error occurred while updating the capability '%1'.",
messageId: "SVC4143"
}
+
+ #---------SVC4144------------------------------
+ # %1 - "Model name"
+ MODEL_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Model name '%1' already exists.",
+ messageId: "SVC4144"
+ }
+
+ #---------SVC4145------------------------------
+ # %1 - "Model name"
+ INVALID_MODEL: {
+ code: 400,
+ message: "Invalid model '%1'.",
+ messageId: "SVC4145"
+ }
+
+ #---------SVC4146------------------------------
+ MODEL_IMPORTS_IS_EMPTY: {
+ code: 400,
+ message: "Given model imports zip is empty.",
+ messageId: "SVC4146"
+ }
+
+ #---------SVC4147------------------------------
+ COULD_NOT_READ_MODEL_IMPORTS: {
+ code: 400,
+ message: "Could not read imports zip.",
+ messageId: "SVC4147"
+ }
+
+ #---------SVC4148------------------------------
+ # %1 - "Model name"
+ MODEL_NOT_FOUND: {
+ code: 404,
+ message: "Error: Model name '%1' not found. Please, make sure the model is created.",
+ messageId: "SVC4148"
+ }
+
+ #---------SVC4149------------------------------
+ MODEL_NAME_CANNOT_BE_EMPTY: {
+ code: 409,
+ message: "Error: Model name cannot be empty.",
+ messageId: "SVC4149"
+ }
+
+ #-----------SVC4150---------------------------
+ # %1 - "Component name"
+ # %2 - "Model name"
+ COMPONENT_WITH_MODEL_ALREADY_EXIST: {
+ code: 409,
+ message: "Error: Component %1 with Model %2 already exist.",
+ messageId: "SVC4150"
+ }
+ #-----------SVC4151---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ # %3 - "Model name"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists in Model '%3'.",
+ messageId: "SVC4151"
+ }
+ #-----------SVC4152---------------------------
+ # %1 - "Component name"
+ # %2 - "Vendor release"
+ COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS: {
+ code: 409,
+ message: "Error: Component '%1' with Vendor Release '%2' already exists.",
+ messageId: "SVC4152"
+ }
+
+ #-----------SVC4153---------------------------
+ # %1 - "Model name"
+ DATA_TYPES_NOT_LOADED: {
+ code: 500,
+ message: "Could not fetch data types from data base with model %1",
+ messageId: "SVC4153"
+ }
+
#-----------SVC4154---------------------------
+ # %1 - "Model name"
+ UNKNOWN_MODEL_TYPE: {
+ code: 400,
+ message: "Error: Model type %1 not known in the system",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4154---------------------------
+ CSAR_TOSCA_IMPORTS_ERROR: {
+ code: 500,
+ message: "Error: An error has occurred while including the default TOSCA imports in the CSAR",
+ messageId: "SVC4154"
+ }
+
+ #-----------SVC4155---------------------------
# %1 - "VSP id"
# %2 - "VSP version id"
VSP_FIND_ERROR: {
code: 500,
message: "An error has occurred while retrieving the Vendor Software Product of id '%1', version id '%2'",
- messageId: "SVC4154"
+ messageId: "SVC4155"
}
- #-----------SVC4155---------------------------
+ #-----------SVC4156---------------------------
# %1 - "VSP id"
# %2 - "VSP version id"
VSP_NOT_FOUND: {
code: 404,
message: "Could not find Vendor Software Product of id '%1', version id '%2'",
- messageId: "SVC4155"
+ messageId: "SVC4156"
}
- #-----------SVC4156---------------------------
+ #-----------SVC4157---------------------------
# %1 - "The model name"
# %2 - "List of allowed models"
VSP_MODEL_NOT_ALLOWED: {
code: 400,
message: "The Model '%1' is not allowed for the imported Vendor Software Product. Allowed Models: '%2'",
- messageId: "SVC4156"
+ messageId: "SVC4157"
+ }
+
+ #---------SVC4158-----------------------------
+ # %1 - Valid artifact label name
+ INVALID_ARTIFACT_LABEL_NAME: {
+ code: 400,
+ message: "Invalid label name. Only the following characters are allowed in label name: '%1'",
+ messageId: "SVC4158"
+ }
+
+ #---------SVC4159-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL: {
+ code: 500,
+ message: "Could not delete the model '%1'.",
+ messageId: "SVC4159"
+ }
+
+ #---------SVC4160-----------------------------
+ # %1 - The model name
+ COULD_NOT_DELETE_MODEL_ELEMENTS: {
+ code: 500,
+ message: "Could not delete the model '%1' elements.",
+ messageId: "SVC4160"
+ }
+ #---------SVC4161-----------------------------
+ INVALID_NODE_TYPES_YAML: {
+ code: 400,
+ message: "Invalid node_types TOSCA yaml",
+ messageId: "SVC4161"
+ }
+
+ #---------SVC4162-----------------------------
+ # %1 - The janusgraph status
+ FAILED_CREATE_ARTIFACTS_TYPES: {
+ code: 500,
+ message: "Failed to create artifact types with status '%1'.",
+ messageId: "SVC4162"
+ }
+
+ #---------SVC4163-----------------------------
+ # %1 - The janusgraph status
+ ARTIFACT_TYPE_ALREADY_EXIST: {
+ code: 409,
+ message: "Artifact type '%1' already exist.",
+ messageId: "SVC4163"
}
#---------SVC4692-----------------------------
@@ -2336,6 +2651,16 @@ errors:
message: "Component is in use by '%1'",
messageId: "SVC4693"
}
+
+ #---------SVC4164-----------------------------
+ # %1 - componentType
+ # %2 - component name
+ CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES: {
+ code: 409,
+ message: "System deployed '%1' cannot be deleted '%2'",
+ messageId: "SVC4164"
+ }
+
#---------SVC4165-----------------------------
# %1 - input origin
TOSCA_GET_FUNCTION_INPUTS_ONLY_SELF_ERROR: {
@@ -2393,6 +2718,14 @@ errors:
messageId: "SVC4170"
}
+ #---------SVC4171-----------------------------
+ # %1 - Instance name
+ TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "The instance '%1' was not found.",
+ messageId: "SVC4171"
+ }
+
#-----------SVC4172---------------------------
#%1 - TOSCA function attribute
TOSCA_FUNCTION_MISSING_ATTRIBUTE: {
@@ -2401,3 +2734,82 @@ errors:
messageId: "SVC4172"
}
+ #-----------SVC4173---------------------------
+ RELATIONSHIP_TEMPLATE_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates entry not found in TOSCA CSAR.",
+ messageId: "SVC4173"
+ }
+
+ #-----------SVC4174---------------------------
+ RELATIONSHIP_TEMPLATE_DEFINITION_NOT_FOUND: {
+ code: 404,
+ message: "Relationship_templates definition not found in TOSCA CSAR.",
+ messageId: "SVC4174"
+ }
+
+ #-----------SVC4175---------------------------
+ TOSCA_FUNCTION_EXPECTED_ERROR: {
+ code: 400,
+ message: "Expecting a Tosca Function value.",
+ messageId: "SVC4175"
+ }
+
+ #-----------SVC4176---------------------------
+ FILTER_CONSTRAINT_MISSING: {
+ code: 400,
+ message: "The filter constraint was not provided.",
+ messageId: "SVC4176"
+ }
+
+ #-----------SVC4177---------------------------
+ #%1 - The missing field
+ FILTER_CONSTRAINT_MISSING_FIELD: {
+ code: 400,
+ message: "Required field '%1' is missing in the filter constraint.",
+ messageId: "SVC4177"
+ }
+
+ #%1 - the component id
+ SUBSTITUTION_FILTER_NOT_FOUND: {
+ code: 404,
+ message: 'Substitution filter not found in the component "%1"',
+ messageId: "SVC4178"
+ }
+
+ # %1 - Component name
+ COMPONENT_DOES_NOT_HAVE_INPUTS: {
+ code: 400,
+ message: "Component '%1' does not have inputs.",
+ messageId: "SVC4179"
+ }
+
+ # %1 - Input name
+ # %2 - Component name
+ COMPONENT_INPUT_NOT_FOUND: {
+ code: 400,
+ message: "Input '%1' does not exist in '%2'.",
+ messageId: "SVC4180"
+ }
+
+ # %1 - Target property name
+ # %2 - Source property name
+ SOURCE_TARGET_SCHEMA_MISMATCH: {
+ code: 400,
+ message: "Target property '%1' schema '%2' does not match with source property '%3' schema '%4'.",
+ messageId: "SVC4181"
+ }
+
+ # %1 - Property name
+ # %2 - Component name
+ COMPONENT_PROPERTY_NOT_FOUND:
+ code: 400
+ message: "Property '%1' does not exist in '%2'."
+ messageId: "SVC4183"
+
+ # %1 - The component type
+ # %2 - The expected component types
+ INVALID_COMPONENT_TYPE:
+ code: 400
+ message: "Invalid component type '%1'. Expected types are: %2"
+ messageId: "SVC4185"