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/datamodel/utils/UiComponentDataConverter.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java36
2 files changed, 42 insertions, 14 deletions
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 8439ffbefd..706f7a7304 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
@@ -50,7 +50,6 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
import org.openecomp.sdc.be.tosca.utils.SubstitutionFilterConverter;
-import org.openecomp.sdc.be.ui.model.UINodeFilter;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
@@ -177,10 +176,11 @@ public class UiComponentDataConverter {
}
private void setSubstitutionFilter(final UiComponentDataTransfer dataTransfer, final Component component) {
- if (component.getSubstitutionFilterComponents() == null) {
- dataTransfer.setSubstitutionFilter(null);
+ if (component.getSubstitutionFilter() == null) {
+ dataTransfer.setSubstitutionFilters(null);
} else {
- dataTransfer.setSubstitutionFilter(component.getSubstitutionFilterComponents());
+ final SubstitutionFilterConverter substitutionFilterConverter = new SubstitutionFilterConverter();
+ dataTransfer.setSubstitutionFilters(substitutionFilterConverter.convertToUi(component.getSubstitutionFilter()));
}
}
@@ -387,12 +387,10 @@ public class UiComponentDataConverter {
break;
case SUBSTITUTION_FILTER:
if (resource.getSubstitutionFilter() == null) {
- dataTransfer.setSubstitutionFilterForTopologyTemplate(null);
+ dataTransfer.setSubstitutionFilters(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);
+ dataTransfer.setSubstitutionFilters(substitutionFilterConverter.convertToUi(resource.getSubstitutionFilter()));
}
break;
case NODE_FILTER:
@@ -458,12 +456,10 @@ public class UiComponentDataConverter {
break;
case SUBSTITUTION_FILTER:
if (service.getSubstitutionFilter() == null) {
- dataTransfer.setSubstitutionFilterForTopologyTemplate(null);
+ dataTransfer.setSubstitutionFilters(null);
} else {
final SubstitutionFilterConverter substitutionFilterConverter = new SubstitutionFilterConverter();
- final Map<String, UINodeFilter> filterUiMap = new HashMap<>();
- filterUiMap.put(service.getUniqueId(), substitutionFilterConverter.convertToUi(service.getSubstitutionFilter()));
- dataTransfer.setSubstitutionFilterForTopologyTemplate(filterUiMap);
+ dataTransfer.setSubstitutionFilters(substitutionFilterConverter.convertToUi(service.getSubstitutionFilter()));
}
break;
default:
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 f163b51f66..9864cf456d 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,7 +19,10 @@
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.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,6 +46,8 @@ 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.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
@@ -53,6 +58,7 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
@@ -322,7 +328,7 @@ public class UiComponentDataConverterTest {
UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
Collections.singletonList("substitutionFilter"));
- assertThat(uiComponentDataTransfer.getSubstitutionFilter()).isNull();
+ assertThat(uiComponentDataTransfer.getSubstitutionFilters()).isNull();
}
@Test
@@ -330,13 +336,39 @@ public class UiComponentDataConverterTest {
SubstitutionFilterDataDefinition substitutionFilter = new SubstitutionFilterDataDefinition();
substitutionFilter.setID(SUBSTITUTION_FILTER_UID);
+ final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> expectedPropertyFilters = new ListDataDefinition<>();
+ var filter1 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ filter1.setName("filter1");
+ filter1.setConstraints(Collections.singletonList("constraint1: {equal: testvalue1}\n"));
+ expectedPropertyFilters.add(filter1);
+
+ var filter2 = new RequirementSubstitutionFilterPropertyDataDefinition();
+ filter2.setName("filter2");
+ filter2.setConstraints(Collections.singletonList("constraint2: {equal: testvalue2}\n"));
+ expectedPropertyFilters.add(filter2);
+
+ substitutionFilter.setProperties(expectedPropertyFilters);
+
Resource resource = new ResourceBuilder().build();
resource.setSubstitutionFilter(substitutionFilter);
UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
Collections.singletonList("substitutionFilter"));
+ assertThat(uiComponentDataTransfer.getSubstitutionFilters()).isNotNull();
+
+ List<UIConstraint> propertyFilters = uiComponentDataTransfer.getSubstitutionFilters().getProperties();
+ assertFalse(propertyFilters.isEmpty());
+ assertEquals(propertyFilters.size(), substitutionFilter.getProperties().getListToscaDataDefinition().size());
+
+ verifyPropertyFilters(propertyFilters.get(0), "constraint1", "testvalue1", "static", "equal");
+ verifyPropertyFilters(propertyFilters.get(1), "constraint2", "testvalue2", "static", "equal");
+ }
- assertThat(uiComponentDataTransfer.getSubstitutionFilterForTopologyTemplate()).isNotEmpty();
+ private void verifyPropertyFilters(UIConstraint uiConstraint, String propertyName, String value, String sourceType, String operator){
+ assertEquals(propertyName, uiConstraint.getServicePropertyName());
+ assertEquals(value, uiConstraint.getValue());
+ assertEquals(sourceType, uiConstraint.getSourceType());
+ assertEquals(operator, uiConstraint.getConstraintOperator());
}
private Resource buildResourceWithGroups() {