summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2019-05-14 10:33:22 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-05-14 12:01:13 +0000
commit1c410e5603e2536ea1517158681a0d0aef5a1e74 (patch)
tree2790aeccc52ff1db5a31310cd991c595db771fa7 /catalog-be
parent4a1d486523e13df2469fead292690593a01d9be3 (diff)
Fix test coverage
Fix test coverage for UiComponentDataConverter.java Change-Id: I745acb3bd3e40c58c12d1d359bb3b06c8bc95f09 Issue-ID: SDC-2298 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/UiComponentDataConverterTest.java91
2 files changed, 76 insertions, 30 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 858d15ab9e..fbc451dd11 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
@@ -124,12 +124,7 @@ public class UiComponentDataConverter {
setComponentInstanceInputs(dataTransfer, component);
break;
case NODE_FILTER:
- if(component.getNodeFilterComponents() == null) {
- dataTransfer.setNodeFilterData(null);
- } else {
- NodeFilterConverter nodeFilterConverter = new NodeFilterConverter();
- dataTransfer.setNodeFilterData(nodeFilterConverter.convertDataMapToUI(component.getNodeFilterComponents()));
- }
+ setNodeFilter(dataTransfer, component);
break;
case COMPONENT_INSTANCES_INTERFACES:
setComponentInstanceInterfaces(dataTransfer, component);
@@ -145,6 +140,14 @@ public class UiComponentDataConverter {
}
}
+ private void setNodeFilter(UiComponentDataTransfer dataTransfer, Component component) {
+ if(component.getNodeFilterComponents() == null) {
+ dataTransfer.setNodeFilter(null);
+ } else {
+ dataTransfer.setNodeFilter(component.getNodeFilterComponents());
+ }
+ }
+
private void setPolicies(UiComponentDataTransfer dataTransfer, Component component) {
Map<String, PolicyDefinition> policies = component.getPolicies();
Set<PolicyDefinition> policyDefinitions =
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 3922dd8de7..92e6a6a792 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
@@ -1,35 +1,23 @@
/*
-
- * Copyright (c) 2018 AT&T Intellectual Property.
-
+ * ============LICENSE_START=============================================================================================================
+ * Copyright (c) 2019 <Company or Individual>.
+ * ===================================================================
+ * 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
*
-
- * 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
*
-
- * 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===============================================================================================================
*
-
- * 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.
-
*/
package org.openecomp.sdc.be.datamodel;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -42,6 +30,9 @@ import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
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.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.Resource;
@@ -77,6 +68,10 @@ public class UiComponentDataConverterTest {
private static PolicyTypeBusinessLogic policyTypeBusinessLogic;
private static UiComponentDataConverter uiComponentDataConverter;
+ private static final String PROPERTY_UID = "propertyUid";
+ private static final String NODE_FILTER_UID = "nodeFilterUid";
+ private static final String COMPONENT_UID = "componentUid";
+
@BeforeClass
public static void initClass() {
groupTypeBusinessLogic = mock(GroupTypeBusinessLogic.class);
@@ -267,6 +262,54 @@ public class UiComponentDataConverterTest {
assertThat(groups.size()).isZero();
}
+ @Test
+ public void testGetDeclaredPolicies() {
+ ComponentInstanceProperty property = new ComponentInstanceProperty();
+ property.setName(PROPERTY_UID);
+
+ GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
+ getPolicy.setPolicyId(PROPERTY_UID);
+ getPolicy.setPropertyName(PROPERTY_UID);
+ property.setGetPolicyValues(Collections.singletonList(getPolicy));
+
+ Map<String, List<ComponentInstanceProperty>> instanceProperties = new HashMap<>();
+ instanceProperties.put(COMPONENT_UID, Collections.singletonList(property));
+
+ Resource resource = new ResourceBuilder().build();
+ resource.setComponentInstancesProperties(instanceProperties);
+
+ UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
+ Collections.singletonList("policies"));
+
+ assertThat(CollectionUtils.isNotEmpty(uiComponentDataTransfer.getPolicies()));
+ }
+
+ @Test
+ public void testGetNodeFilterEmptyList() {
+ Resource resource = new ResourceBuilder().build();
+ UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
+ Collections.singletonList("nodeFilter"));
+
+ assertThat(MapUtils.isEmpty(uiComponentDataTransfer.getNodeFilter()));
+ }
+
+ @Test
+ public void testGetNodeFilter() {
+ CINodeFilterDataDefinition nodeFilter = new CINodeFilterDataDefinition();
+ nodeFilter.setID(NODE_FILTER_UID);
+
+ Map<String, CINodeFilterDataDefinition> nodeFilterMap = new HashMap<>();
+ nodeFilterMap.put(NODE_FILTER_UID, nodeFilter);
+
+ Resource resource = new ResourceBuilder().build();
+ resource.setNodeFilterComponents(nodeFilterMap);
+
+ UiComponentDataTransfer uiComponentDataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource,
+ Collections.singletonList("nodeFilter"));
+
+ assertThat(MapUtils.isNotEmpty(uiComponentDataTransfer.getNodeFilter()));
+ }
+
private Resource buildResourceWithGroups() {
return new ResourceBuilder()
.addGroup(group1)