summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-08-10 14:50:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-09-08 18:24:44 +0000
commit92b18f188105d5ba4b2c469cdfaedc7d2953d593 (patch)
treedf7c7562faa99a76b0e6b5bc079de8d514b35006 /catalog-be/src/test/java
parentc0c2637f201f488a74cb1916f05eece0cc207e9d (diff)
Support TOSCA functions in Node Filters
Adds support to use tosca functions as value in the node property filters and substitution filters Change-Id: Id242691cc9ddd233245b58f052b9f0e2c7bbd66b Issue-ID: SDC-4128 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/test/java')
-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
16 files changed, 1134 insertions, 864 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);