diff options
author | talio <tali.orenbach@amdocs.com> | 2019-05-14 10:33:22 +0300 |
---|---|---|
committer | talio <tali.orenbach@amdocs.com> | 2019-05-14 10:33:22 +0300 |
commit | fc7d74662932f476b305a904e5007dcf473551c1 (patch) | |
tree | d80106c3fad71bd5ef257369b67c8f9d2f041b7f | |
parent | 0cf08bff1f9b50d227d7047b5fdd7776c667ca25 (diff) |
Fix test coverage
Fix test coverage for UiComponentDataConverter.java
Change-Id: I2ff8cc69e3bbd5693199d3fe71d9f913d0719c2e
Issue-ID: SDC-2298
Signed-off-by: talio <tali.orenbach@amdocs.com>
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 eb123771a9..e7190b1255 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); @@ -265,6 +260,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) |