summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java11
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java60
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java25
4 files changed, 68 insertions, 30 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
index c02db7a9e3..0f55ddfff1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
@@ -237,7 +237,7 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
boolean wasLocked = false;
try {
if (shouldLock) {
- lockComponent(component.getUniqueId(), component,"Add Node Filter on Component");
+ lockComponent(component.getUniqueId(), component,"Delete substitution Filter on Component");
wasLocked = true;
}
final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index 65c3b0e78e..d742fb3aea 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -378,6 +378,17 @@ public class UiComponentDataConverter {
.getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
+ case SUBSTITUTION_FILTER:
+ if (resource.getSubstitutionFilter() == null) {
+ dataTransfer.setSubstitutionFilterForTopologyTemplate(null);
+ } else {
+ final SubstitutionFilterConverter substitutionFilterConverter = new SubstitutionFilterConverter();
+ final Map<String, UINodeFilter> filterUiMap = new HashMap<>();
+ filterUiMap.put(resource.getUniqueId(),
+ substitutionFilterConverter.convertToUi(resource.getSubstitutionFilter()));
+ dataTransfer.setSubstitutionFilterForTopologyTemplate(filterUiMap);
+ }
+ break;
default:
setUiTranferDataByFieldName(dataTransfer, resource, fieldName);
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 666d1e7f39..1d643b704c 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
@@ -57,6 +57,8 @@ 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.Component;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.SubstitutionFilterOperation;
@@ -94,7 +96,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Mock
private NodeFilterValidator nodeFilterValidator;
- private Service service;
+ private Component component;
private SubstitutionFilterDataDefinition substitutionFilterDataDefinition;
private RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition;
private String constraint;
@@ -118,9 +120,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void doNotCreateSubstitutionFilterAsExistsTest() throws BusinessLogicException {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
final Optional<SubstitutionFilterDataDefinition> result = componentSubstitutionFilterBusinessLogic
.createSubstitutionFilterIfNotExist(componentId, true, ComponentTypeEnum.SERVICE);
@@ -131,7 +133,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void createSubstitutionFilterIfNotExistTest() throws BusinessLogicException {
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
when(substitutionFilterOperation.createSubstitutionFilter(componentId))
@@ -151,7 +153,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void createSubstitutionFilterIfNotExistFailTest() {
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
when(substitutionFilterOperation.createSubstitutionFilter(componentId))
@@ -170,12 +172,12 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void addSubstitutionFilterTest() throws BusinessLogicException {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
@@ -192,7 +194,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
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(service,
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
verify(substitutionFilterOperation, times(1))
.addPropertyFilter(anyString(), any(SubstitutionFilterDataDefinition.class),
@@ -203,12 +205,12 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void addSubstitutionFilterFailTest() {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
when(substitutionFilterOperation
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
@@ -224,7 +226,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
Collections.singletonList(constraint), NodeFilterConstraintAction.ADD);
verify(substitutionFilterOperation, times(0))
.addPropertyFilter(componentId, substitutionFilterDataDefinition,
@@ -234,13 +236,13 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void updateSubstitutionFilterTest() throws BusinessLogicException {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
final List<String> constraints = requirementSubstitutionFilterPropertyDataDefinition.getConstraints();
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
when(substitutionFilterOperation.updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList()))
.thenReturn(Either.left(substitutionFilterDataDefinition));
@@ -255,7 +257,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1);
verify(substitutionFilterOperation, times(1))
.updateProperties(anyString(), any(SubstitutionFilterDataDefinition.class), anyList());
- verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
@@ -264,12 +266,12 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void updateSubstitutionFilterFailTest() {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
- when(nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(constraint),
+ when(nodeFilterValidator.validateComponentFilter(component, Collections.singletonList(constraint),
NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
@@ -280,7 +282,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Service);
- verify(nodeFilterValidator, times(1)).validateComponentFilter(service,
+ verify(nodeFilterValidator, times(1)).validateComponentFilter(component,
Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE);
verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Service);
}
@@ -288,9 +290,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void deleteSubstitutionFilterTest() throws BusinessLogicException {
substitutionFilterDataDefinition.setProperties(new ListDataDefinition<>());
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
when(substitutionFilterOperation.deleteConstraint(anyString(), any(SubstitutionFilterDataDefinition.class), anyInt()))
@@ -310,9 +312,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
@Test
public void deleteSubstitutionFilterFailTest() {
- service.setSubstitutionFilter(substitutionFilterDataDefinition);
+ component.setSubstitutionFilter(substitutionFilterDataDefinition);
- when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
.thenReturn(StorageOperationStatus.OK);
when(substitutionFilterOperation.deleteConstraint(anyString(),
@@ -334,9 +336,9 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
public void initResource() {
try {
- service = new Service();
- service.setName("MyTestService");
- service.setUniqueId(componentId);
+ component = new Service();
+ component.setName("MyTestService");
+ component.setUniqueId(componentId);
final UIConstraint uiConstraint =
new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue);
@@ -358,7 +360,7 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo
final PropertyDefinition property = new PropertyDefinition();
property.setName(uiConstraint.getServicePropertyName());
- service.setProperties(new LinkedList<>(Arrays.asList(property)));
+ component.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/datamodel/UiComponentDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java
index 1b65912e48..84dd3b1e8c 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
@@ -34,6 +34,7 @@ import org.openecomp.sdc.be.components.utils.ServiceBuilder;
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.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -73,6 +74,7 @@ public class UiComponentDataConverterTest {
private static final String PROPERTY_UID = "propertyUid";
private static final String NODE_FILTER_UID = "nodeFilterUid";
+ private static final String SUBSTITUTION_FILTER_UID = "substitutionFilterUid";
private static final String COMPONENT_UID = "componentUid";
@BeforeClass
@@ -313,6 +315,29 @@ public class UiComponentDataConverterTest {
assertThat(uiComponentDataTransfer.getNodeFilter()).isNotEmpty();
}
+ @Test
+ public void testGetSubstitutionFilterEmptyList() {
+ Resource resource = new ResourceBuilder().build();
+ UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
+ Collections.singletonList("substitutionFilter"));
+
+ assertThat(uiComponentDataTransfer.getSubstitutionFilter()).isNull();
+ }
+
+ @Test
+ public void testGetSubstitutionFilter() {
+ SubstitutionFilterDataDefinition substitutionFilter = new SubstitutionFilterDataDefinition();
+ substitutionFilter.setID(SUBSTITUTION_FILTER_UID);
+
+ Resource resource = new ResourceBuilder().build();
+ resource.setSubstitutionFilter(substitutionFilter);
+
+ UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
+ Collections.singletonList("substitutionFilter"));
+
+ assertThat(uiComponentDataTransfer.getSubstitutionFilterForTopologyTemplate()).isNotEmpty();
+ }
+
private Resource buildResourceWithGroups() {
return new ResourceBuilder()
.addGroup(group1)