aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2022-08-05 10:43:18 +0100
committerMichael Morris <michael.morris@est.tech>2022-08-11 14:10:16 +0000
commit7e49c060458ff13b72bc997ffff9ea668e934676 (patch)
tree6e00b4c19d3a78624fe222c2a67d006fbaf5c250
parent33538725267c361efe813f1a4e6eff8b69c09c9f (diff)
Empty node filter is removed when no filter is added
Null and empty check is added before adding a node filter object Signed-off-by: Imam hussain <imam.hussain@est.tech> Issue-ID: SDC-4124 Change-Id: I1e1e992881cd51dff209bac0111a472793dd41d1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java62
3 files changed, 65 insertions, 10 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index a8aa6b33a9..9591e6b1a7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -937,8 +937,10 @@ public class ToscaExportHandler {
}
nodeTemplate.setType(componentInstance.getToscaComponentName());
nodeTemplate.setDirectives(componentInstance.getDirectives());
- nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter()));
-
+ NodeFilter nodeFilter = convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter());
+ if(nodeFilter != null && nodeFilter.hasData()){
+ nodeTemplate.setNode_filter(nodeFilter);
+ }
final Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
.getOriginComponent(componentCache, componentInstance);
if (originComponentRes.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java
index 6cad788a1e..ba93e09c13 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java
@@ -17,6 +17,9 @@ package org.openecomp.sdc.be.tosca.model;
import java.util.List;
import java.util.Map;
+
+import org.apache.commons.collections.CollectionUtils;
+
import lombok.Getter;
import lombok.Setter;
@@ -27,4 +30,8 @@ public class NodeFilter {
private Object tosca_id;
private List<Map<String, List<Object>>> properties;
private List<Map<String, CapabilityFilter>> capabilities;
+
+ public boolean hasData() {
+ return CollectionUtils.isNotEmpty(properties) || CollectionUtils.isNotEmpty(capabilities);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java
index 72fcf5f2dc..84732e2cdf 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java
@@ -20,20 +20,66 @@
package org.openecomp.sdc.be.tosca.model;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
-import static org.hamcrest.MatcherAssert.assertThat;
+import org.junit.jupiter.api.Test;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
public class NodeFilterTest {
+
+ private void createCapabilities(NodeFilter nodeFilter) {
+ List<Map<String, CapabilityFilter>> capabilitiesCopy = new ArrayList<>();
+ Map<String, CapabilityFilter> capabilityDataMap = new HashMap<>();
+ CapabilityFilter capabilityFilter = new CapabilityFilter();
+ capabilityDataMap.put("test", capabilityFilter);
+ capabilitiesCopy.add(capabilityDataMap);
+ nodeFilter.setCapabilities(capabilitiesCopy);
+ }
+
+ private void createProperties(NodeFilter nodeFilter) {
+ List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+ Map<String, List<Object>> propertyDataMap = new HashMap<>();
+ List<Object> dataObjectList = new ArrayList<>();
+ Object object = new Object();
+ dataObjectList.add(object);
+ propertyDataMap.put("test", dataObjectList);
+ propertiesCopy.add(propertyDataMap);
+ nodeFilter.setProperties(propertiesCopy);
+ }
+
+ @Test
+ public void testHasDataTrue() {
+ NodeFilter nodeFilter = new NodeFilter();
+ createCapabilities(nodeFilter);
+ createProperties(nodeFilter);
+ boolean result = nodeFilter.hasData();
+ assertTrue(result);
+ }
+
+ @Test
+ public void testHasDataCapabilityTrue() {
+ NodeFilter nodeFilter = new NodeFilter();
+ createCapabilities(nodeFilter);
+ boolean result = nodeFilter.hasData();
+ assertTrue(result);
+ }
+
@Test
- public void testDefaultCtor() {
- assertThat(NodeFilter.class, hasValidBeanConstructor());
+ public void testHasDataPropertiesTrue() {
+ NodeFilter nodeFilter = new NodeFilter();
+ createProperties(nodeFilter);
+ boolean result = nodeFilter.hasData();
+ assertTrue(result);
}
@Test
- public void testGettersSetters() {
- assertThat(NodeFilter.class, hasValidGettersAndSetters());
+ public void testHasDataFalse() {
+ NodeFilter nodeFilter = new NodeFilter();
+ boolean result = nodeFilter.hasData();
+ assertFalse(result);
}
} \ No newline at end of file