summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2020-09-17 15:11:30 +0100
committerS�bastien Determe <sebastien.determe@intl.att.com>2020-10-23 14:49:33 +0000
commita5a46f26d043b70cd9a44fed05b0e8ba184318fb (patch)
tree97582d3263a48658f8a84367684e1eb40ba4624e /catalog-be/src/test
parent9714961d2950d00ae66be01e20c1ebb8552a82e9 (diff)
Fix for substitution filter properties
Issue-ID: SDC-3325 Change-Id: If26bf895a0a2f914fb9c2b36e53466df9b7999fe Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java261
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServletTest.java102
2 files changed, 106 insertions, 257 deletions
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 eaeb5ea11a..666d1e7f39 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
@@ -19,7 +19,6 @@
package org.openecomp.sdc.be.components.impl;
-import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
@@ -32,14 +31,12 @@ 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.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -51,8 +48,6 @@ 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.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
@@ -62,16 +57,13 @@ import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
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.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.PropertyDefinition;
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.model.UIConstraint;
-import org.openecomp.sdc.exception.ResponseFormat;
@ExtendWith(MockitoExtension.class)
public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLogicMock {
@@ -82,13 +74,10 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
private static final String sourceName = sourceType;
private static final String propertyValue = "constraintValue";
private static final String componentId = "dac65869-dfb4-40d2-aa20-084324659ec1";
- private static final String componentInstanceId = "dac65869-dfb4-40d2-aa20-084324659ec1.service0";
@InjectMocks
private ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic;
@Mock
- private NodeFilterValidator nodeFilterValidator;
- @Mock
private SubstitutionFilterOperation substitutionFilterOperation;
@Mock
private ToscaOperationFacade toscaOperationFacade;
@@ -103,10 +92,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Mock
private UserValidations userValidations;
@Mock
- private ResponseFormat responseFormat;
+ private NodeFilterValidator nodeFilterValidator;
private Service service;
- private ComponentInstance componentInstance;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
private String constraint;
@@ -130,12 +118,12 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .createSubstitutionFilterIfNotExist(componentId, componentInstanceId, true, ComponentTypeEnum.SERVICE);
+ .createSubstitutionFilterIfNotExist(componentId, true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties()).isEqualTo(substitutionFilterDataDefinition.getProperties());
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
@@ -145,19 +133,19 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
public void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
- .thenReturn(StorageOperationStatus.OK);
- when(substitutionFilterOperation.createSubstitutionFilter(componentId, componentInstanceId))
- .thenReturn(Either.left(substitutionFilterDataDefinition));
+ .thenReturn(StorageOperationStatus.OK);
+ when(substitutionFilterOperation.createSubstitutionFilter(componentId))
+ .thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .createSubstitutionFilterIfNotExist(componentId, componentInstanceId, true, ComponentTypeEnum.SERVICE);
+ .createSubstitutionFilterIfNotExist(componentId, true, ComponentTypeEnum.SERVICE);
assertThat(result).isPresent();
assertThat(result.get().getProperties()).isEqualTo(substitutionFilterDataDefinition.getProperties());
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(substitutionFilterOperation, times(1)).createSubstitutionFilter(componentId, componentInstanceId);
+ verify(substitutionFilterOperation, times(1)).createSubstitutionFilter(componentId);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@@ -165,283 +153,191 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
public void createSubstitutionFilterIfNotExistFailTest() {
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
- .thenReturn(StorageOperationStatus.OK);
- when(substitutionFilterOperation.createSubstitutionFilter(componentId, componentInstanceId))
- .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ .thenReturn(StorageOperationStatus.OK);
+ when(substitutionFilterOperation.createSubstitutionFilter(componentId))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
- .thenReturn(StorageOperationStatus.OK);
+ .thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .createSubstitutionFilterIfNotExist(componentId, componentInstanceId, true, ComponentTypeEnum.SERVICE));
+ .createSubstitutionFilterIfNotExist(componentId, true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(substitutionFilterOperation, times(1)).createSubstitutionFilter(componentId, componentInstanceId);
+ verify(substitutionFilterOperation, times(1)).createSubstitutionFilter(componentId);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void addSubstitutionFilterTest() throws BusinessLogicException {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
- when(nodeFilterValidator.validateComponentInstanceExist(service, componentInstanceId))
- .thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
-
+ when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
when(substitutionFilterOperation
- .addNewProperty(anyString(), anyString(), any(SubstitutionFilterDataDefinition.class),
+ .addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
any(RequirementSubstitutionFilterPropertyDataDefinition.class)))
.thenReturn(Either.left(substitutionFilterDataDefinition));
-
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- servicePropertyName, constraint, true, ComponentTypeEnum.SERVICE);
+ .addSubstitutionFilter(componentId, servicePropertyName, constraint, 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)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
- verify(substitutionFilterOperation, times(0))
- .addNewProperty(componentId, componentInstanceId, substitutionFilterDataDefinition,
- requirementSubstitutionFilterPropertyDataDefinition);
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(substitutionFilterOperation, times(1))
+ .addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
+ any(RequirementSubstitutionFilterPropertyDataDefinition.class));
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void addSubstitutionFilterFailTest() {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId, Collections.singletonList(constraint),
- NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
- when(nodeFilterValidator.validateComponentInstanceExist(service, componentInstanceId))
- .thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
-
+ when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
when(substitutionFilterOperation
- .addNewProperty(anyString(), anyString(), any(SubstitutionFilterDataDefinition.class),
- any(RequirementSubstitutionFilterPropertyDataDefinition.class)))
+ .addPropertyFilter(componentId, substitutionFilterDataDefinition,
+ requirementSubstitutionFilterPropertyDataDefinition))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD,
- servicePropertyName, constraint, true, ComponentTypeEnum.SERVICE));
+ .addSubstitutionFilter(componentId, servicePropertyName, constraint, true,
+ ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
verify(substitutionFilterOperation, times(0))
- .addNewProperty(componentId, componentInstanceId, substitutionFilterDataDefinition,
+ .addPropertyFilter(componentId, substitutionFilterDataDefinition,
requirementSubstitutionFilterPropertyDataDefinition);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void updateSubstitutionFilterTest() throws BusinessLogicException {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
-
- when(substitutionFilterOperation.updateSubstitutionFilter(anyString(), anyString(),
- any(SubstitutionFilterDataDefinition.class), anyList()))
- .thenReturn(Either.left(substitutionFilterDataDefinition));
-
+ when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
+ when(substitutionFilterOperation.updateProperties(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, componentInstanceId, Collections.singletonList(constraint),
+ .updateSubstitutionFilter(componentId, Collections.singletonList(constraint),
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(service,
+ Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
+ verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void updateSubstitutionFilterFailTest() {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
-
- when(substitutionFilterOperation.updateSubstitutionFilter(anyString(), anyString(),
- any(SubstitutionFilterDataDefinition.class), anyList()))
- .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
-
+ when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ NodeFilterConstraintAction.UPDATE)).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, componentInstanceId, constraints, true, ComponentTypeEnum.SERVICE));
+ .updateSubstitutionFilter(componentId, constraints, true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
- }
-
- @Test
- public void updateSubstitutionFilterFailWithFilterNotFoundTest() {
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
-
- assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, componentInstanceId,
- requirementSubstitutionFilterPropertyDataDefinition.getConstraints(), true,
- ComponentTypeEnum.SERVICE));
-
- verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
- }
-
- @Test
- public void updateSubstitutionFilterFailValidationTest() {
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
-
- final UIConstraint uiConstraint =
- new UIConstraint("invalidProperty", constraintOperator, sourceType, sourceName, propertyValue);
- constraint = new ConstraintConvertor().convert(uiConstraint);
- requirementSubstitutionFilterPropertyDataDefinition.setConstraints(Collections.singletonList(constraint));
-
- when(responseFormat.getFormattedMessage()).thenReturn(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT.name());
-
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE))
- .thenReturn(Either.right(responseFormat));
-
- assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .updateSubstitutionFilter(componentId, componentInstanceId,
- requirementSubstitutionFilterPropertyDataDefinition.getConstraints(), true,
- ComponentTypeEnum.SERVICE));
-
- verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
+ verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void deleteSubstitutionFilterTest() throws BusinessLogicException {
substitutionFilterDataDefinition.setProperties(new ListDataDefinition<>());
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
-
- when(nodeFilterValidator.validateComponentInstanceExist(service, componentInstanceId))
- .thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(substitutionFilterOperation.deleteConstraint(anyString(), anyString(),
- any(SubstitutionFilterDataDefinition.class), anyInt()))
+ when(substitutionFilterOperation.deleteConstraint(anyString(), any(SubstitutionFilterDataDefinition.class), anyInt()))
.thenReturn(Either.left(substitutionFilterDataDefinition));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
- .deleteSubstitutionFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.SERVICE);
+ .deleteSubstitutionFilter(componentId, anyInt(), true, ComponentTypeEnum.SERVICE);
- assertThat(result).isPresent();
- assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(0);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE);
- verify(nodeFilterValidator, times(1)).validateComponentInstanceExist(service, componentInstanceId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(substitutionFilterOperation, times(1)).deleteConstraint(componentId, componentInstanceId,
- substitutionFilterDataDefinition, 0);
+ verify(substitutionFilterOperation, times(1)).deleteConstraint(componentId,
+ substitutionFilterDataDefinition, 0);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@Test
public void deleteSubstitutionFilterFailTest() {
- componentInstance.setSubstitutionFilter(substitutionFilterDataDefinition);
+ service.setSubstitutionFilter(substitutionFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
-
- when(nodeFilterValidator.validateComponentInstanceExist(service, componentInstanceId))
- .thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(substitutionFilterOperation.deleteConstraint(anyString(), anyString(),
+ when(substitutionFilterOperation.deleteConstraint(anyString(),
any(SubstitutionFilterDataDefinition.class), anyInt()))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
+ final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .deleteSubstitutionFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.SERVICE));
+ .deleteSubstitutionFilter(componentId, anyInt(),true, ComponentTypeEnum.SERVICE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE);
- verify(nodeFilterValidator, times(1)).validateComponentInstanceExist(service, componentInstanceId);
- verify(substitutionFilterOperation, times(1)).deleteConstraint(componentId, componentInstanceId,
- substitutionFilterDataDefinition, 0);
+ verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
+ verify(substitutionFilterOperation, times(1)).deleteConstraint(componentId,
+ substitutionFilterDataDefinition, 0);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
- @Test
- public void deleteSubstitutionFilterFailValidationTest() {
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
- when(nodeFilterValidator.validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
-
- when(nodeFilterValidator.validateComponentInstanceExist(service, componentInstanceId))
- .thenReturn(Either.left(true));
-
- assertThrows(BusinessLogicException.class, () -> componentSubstitutionFilterBusinessLogic
- .deleteSubstitutionFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint,
- 0, true, ComponentTypeEnum.SERVICE));
-
- verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateFilter(service, componentInstanceId,
- Collections.singletonList(constraint), NodeFilterConstraintAction.DELETE);
- }
-
public void initResource() {
try {
service = new Service();
service.setName("MyTestService");
service.setUniqueId(componentId);
- componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(componentInstanceId);
- componentInstance.setName("myComponentInstance");
- componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDirectives());
-
final UIConstraint uiConstraint =
new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
constraint = new ConstraintConvertor().convert(uiConstraint);
@@ -459,22 +355,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
substitutionFilterDataDefinition.setProperties(listDataDefinition);
substitutionFilterDataDefinition.setID("SUBSTITUTION_FILTER_UID");
- service.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);
-
- service.setComponentInstancesProperties(componentInstanceProps);
service.setProperties(new LinkedList<>(Arrays.asList(property)));
} catch (final Exception e) {
fail(e.getMessage());
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 b6b1dc5cd9..39259a899f 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,9 +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.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;
@@ -44,6 +46,7 @@ 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;
@@ -58,7 +61,6 @@ import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentSubstitutionFilterBusinessLogic;
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.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -89,7 +91,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
private static final String sourceName = sourceType;
private static final String propertyValue = "constraintValue";
private static final String componentId = "dac65869-dfb4-40d2-aa20-084324659ec1";
- private static final String componentInstance = "dac65869-dfb4-40d2-aa20-084324659ec1.service0";
+ private static final String constraintType = "properties";
private static final String componentType = "services";
private static HttpServletRequest request;
@@ -141,9 +143,9 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ public void addSubstitutionFilterTest() throws Exception {
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -164,15 +166,8 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertNotNull(substitutionFilterDataDefinition);
assertThat(substitutionFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
assertThat("controller_actor: {equal: constraintValue}\n").isEqualToIgnoringCase(constraint);
-
- when(componentSubstitutionFilterBusinessLogic.createSubstitutionFilterIfNotExist(componentId,
- componentInstance, true, ComponentTypeEnum.SERVICE))
- .thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
-
- when(componentSubstitutionFilterBusinessLogic
- .addSubstitutionFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
- uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.SERVICE))
- .thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
+ when(componentSubstitutionFilterBusinessLogic.addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
+ true, ComponentTypeEnum.SERVICE)).thenReturn(Optional.of(substitutionFilterDataDefinition));
final Response response = target()
.path(path)
@@ -183,17 +178,14 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentSubstitutionFilterBusinessLogic, times(1))
- .createSubstitutionFilterIfNotExist(componentId, componentInstance, true, ComponentTypeEnum.SERVICE);
-
- verify(componentSubstitutionFilterBusinessLogic, times(1))
- .addSubstitutionFilter(anyString(), anyString(), any(NodeFilterConstraintAction.class), anyString(),
- anyString(), anyBoolean(), any(ComponentTypeEnum.class));
+ .addSubstitutionFilter(componentId, uiConstraint.getServicePropertyName(), constraint,
+ true, ComponentTypeEnum.SERVICE);
}
@Test
public void addSubstitutionFilterFailConstraintParseTest() {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -212,9 +204,9 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void addSubstitutionFilterFailTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ public void addSubstitutionFilterFailTest() {
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -223,10 +215,6 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
.thenReturn(Optional.of(uiConstraint));
- when(componentSubstitutionFilterBusinessLogic.createSubstitutionFilterIfNotExist(componentId,
- componentInstance, true, ComponentTypeEnum.SERVICE))
- .thenReturn(Optional.empty());
-
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -234,15 +222,12 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
.post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
-
- verify(componentSubstitutionFilterBusinessLogic, times(1))
- .createSubstitutionFilterIfNotExist(componentId, componentInstance, true, ComponentTypeEnum.SERVICE);
}
@Test
public void updateSubstitutionFilterTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -253,7 +238,7 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
any(User.class))).thenReturn(Collections.singletonList(uiConstraint));
when(componentSubstitutionFilterBusinessLogic.updateSubstitutionFilter(componentId.toLowerCase(),
- componentInstance, Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE))
+ Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE))
.thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
final Response response = target()
@@ -265,14 +250,13 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentSubstitutionFilterBusinessLogic, times(1))
- .updateSubstitutionFilter(componentId.toLowerCase(), componentInstance,
- Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE);
+ .updateSubstitutionFilter(anyString(), anyList(), anyBoolean(), any(ComponentTypeEnum.class));
}
@Test
public void updateSubstitutionFilterFailConstraintParseTest() {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -291,9 +275,9 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
}
@Test
- public void updateSubstitutionFilterFailTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ public void updateSubstitutionFilterFailTest() {
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
@@ -302,10 +286,6 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(),
any(User.class))).thenReturn(Collections.singletonList(uiConstraint));
- when(componentSubstitutionFilterBusinessLogic.updateSubstitutionFilter(componentId.toLowerCase(),
- componentInstance, Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE))
- .thenReturn(Optional.empty());
-
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -313,24 +293,20 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
.put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
-
- verify(componentSubstitutionFilterBusinessLogic, times(1))
- .updateSubstitutionFilter(componentId.toLowerCase(), componentInstance,
- Collections.singletonList(constraint), true, ComponentTypeEnum.SERVICE);
}
@Test
public void deleteSubstitutionFilterConstraintTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter/0";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentSubstitutionFilterBusinessLogic.deleteSubstitutionFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.SERVICE))
+ when(componentSubstitutionFilterBusinessLogic.deleteSubstitutionFilter(componentId, 0,
+ true, ComponentTypeEnum.SERVICE))
.thenReturn(Optional.ofNullable(substitutionFilterDataDefinition));
final Response response = target()
@@ -342,23 +318,18 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
verify(componentSubstitutionFilterBusinessLogic, times(1))
- .deleteSubstitutionFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.SERVICE);
+ .deleteSubstitutionFilter(anyString(), anyInt(), anyBoolean(), any(ComponentTypeEnum.class));
}
@Test
- public void deleteSubstitutionFilterConstraintFailTest() throws BusinessLogicException {
- final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/substitutionFilter/0";
- final String path = String.format(pathFormat, componentType, componentId, componentInstance);
+ public void deleteSubstitutionFilterConstraintFailTest() {
+ final String pathFormat = "/v1/catalog/%s/%s/substitutionFilter/%s/0";
+ final String path = String.format(pathFormat, componentType, componentId, constraintType);
when(userValidations.validateUserExists(user)).thenReturn(user);
when(componentSubstitutionFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentSubstitutionFilterBusinessLogic.deleteSubstitutionFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.SERVICE))
- .thenReturn(Optional.empty());
-
final Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -366,11 +337,6 @@ public class ComponentSubstitutionFilterServletTest extends JerseyTest {
.delete(Response.class);
assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
-
- verify(componentSubstitutionFilterBusinessLogic, times(1))
- .deleteSubstitutionFilter(componentId, componentInstance,
- NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.SERVICE);
-
}
private static void createMocks() {