diff options
author | Mojahidul Islam <mojahidul.islam@amdocs.com> | 2019-05-14 12:49:31 +0530 |
---|---|---|
committer | Mojahidul Islam <mojahidul.islam@amdocs.com> | 2019-05-14 12:50:27 +0530 |
commit | 82e531a1ee8ffa30e80b27d9097a2272ae18cdee (patch) | |
tree | 900964c5f61e15437e0568f3a5bec3c7083ca5a2 /catalog-model/src/test | |
parent | 3d5b80b9035b9832f86326858b4c6c2cecd952a3 (diff) |
Support Capability Properties
This change includes following changes
1. Get capability properties from global types- BE
2. Show capability properties in cap/req screen
3. Support Capability Properties in assingment, operation and consumption screens
Change-Id: Ieb4fa5705007c8bed3d82eb4fe4604572aa202d7
Issue-ID: SDC-2294
Signed-off-by: Mojahidul Islam <mojahidul.islam@amdocs.com>
Diffstat (limited to 'catalog-model/src/test')
3 files changed, 191 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperationTest.java new file mode 100644 index 0000000000..0c9c35b62a --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperationTest.java @@ -0,0 +1,87 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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 + * + * 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.model.jsontitan.operations; + +import fj.data.Either; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsontitan.utils.CapabilityTestUtils; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +public class CapabilitiesOperationTest { + + @InjectMocks + CapabilitiesOperation operation = new CapabilitiesOperation(); + @Mock + private TitanDao mockTitanDao; + @Mock + private TopologyTemplateOperation topologyTemplateOperation; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); + when(mockTitanDao.getVertexById(anyString(), any())).thenReturn(Either.left(new GraphVertex())); + + when(topologyTemplateOperation.updateFullToscaData(any(), any(), any(), anyMap())).thenReturn(StorageOperationStatus.OK); + TopologyTemplate topologyTemplate = new TopologyTemplate(); + + Map<String, MapPropertiesDataDefinition> capPropsForTopologyTemplate = CapabilityTestUtils + .createCapPropsForTopologyTemplate(topologyTemplate); + topologyTemplate.setCapabilitiesProperties(capPropsForTopologyTemplate); + + when(topologyTemplateOperation.getToscaElement(anyString(), any())).thenReturn(Either.left(topologyTemplate)); + } + + @Test + public void testCreateOrUpdateCapabilitiesProperties() { + + Map<String, PropertyDataDefinition> mapToscaDataDefinition = new HashMap<>(); + PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition(); + propertyDataDefinition.setUniqueId("ComponentInput1_uniqueId"); + propertyDataDefinition.setName("propName"); + mapToscaDataDefinition.put(propertyDataDefinition.getUniqueId(), propertyDataDefinition); + MapPropertiesDataDefinition mapPropertiesDataDefinition = new MapPropertiesDataDefinition(mapToscaDataDefinition); + + Map<String, MapPropertiesDataDefinition> propertiesMap = new HashMap<>(); + propertiesMap.put(propertyDataDefinition.getUniqueId(), mapPropertiesDataDefinition); + + StorageOperationStatus operationStatus = operation.createOrUpdateCapabilityProperties("componentId", + propertiesMap); + + Assert.assertEquals(StorageOperationStatus.OK, operationStatus); + } +}
\ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityTestUtils.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityTestUtils.java new file mode 100644 index 0000000000..6f6b7eacad --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/CapabilityTestUtils.java @@ -0,0 +1,85 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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 + * + * 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.model.jsontitan.utils; + +import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CapabilityTestUtils { + + public static Map<String, MapPropertiesDataDefinition> createCapPropsForTopologyTemplate(TopologyTemplate topologyTemplate) { + Map<String, ListCapabilityDataDefinition> capabilitiesMap = new HashMap<>(); + + List<CapabilityDataDefinition> capabilityDefinitions = new ArrayList<>(); + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + + capabilityDefinitions.add(capabilityDefinition); + ListCapabilityDataDefinition listCapabilityDataDefinition = new ListCapabilityDataDefinition(capabilityDefinitions); + capabilitiesMap.put(capabilityDefinition.getType(), listCapabilityDataDefinition); + topologyTemplate.setCapabilities(capabilitiesMap); + + List<ComponentInstanceProperty> capPropList = new ArrayList<>(); + ComponentInstanceProperty instanceProperty = createProperties(); + capPropList.add(instanceProperty); + + MapPropertiesDataDefinition dataToCreate = new MapPropertiesDataDefinition(); + for (ComponentInstanceProperty cip : capPropList) { + PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition(cip); + dataToCreate.put(cip.getName(), propertyDataDefinition); + } + + Map<String, MapPropertiesDataDefinition> capabilitiesProperties = new HashMap<>(); + capabilitiesProperties.put(capabilityDefinition.getType() + ModelConverter.CAP_PROP_DELIM + + capabilityDefinition.getName(), dataToCreate); + return capabilitiesProperties; + } + + private static CapabilityDefinition createCapabilityDefinition() { + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("cap" + Math.random()); + capabilityDefinition.setType("tosca.capabilities.network.Bindable"); + capabilityDefinition.setOwnerId("resourceId"); + capabilityDefinition.setUniqueId("capUniqueId"); + List<String> path = new ArrayList<>(); + path.add("path1"); + capabilityDefinition.setPath(path); + return capabilityDefinition; + } + + private static ComponentInstanceProperty createProperties() { + ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty(); + instanceProperty.setUniqueId("ComponentInput1_uniqueId"); + instanceProperty.setType("Integer"); + instanceProperty.setName("prop_name"); + instanceProperty.setDescription("prop_description_prop_desc"); + instanceProperty.setOwnerId("capUniqueId"); + instanceProperty.setValue("{\"get_input\":\"extcp20_order\"}"); + instanceProperty.setSchema(new SchemaDefinition()); + return instanceProperty; + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverterTest.java index f8713c6b78..a927f5a461 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverterTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverterTest.java @@ -34,6 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.model.Resource; @@ -42,6 +43,9 @@ import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType; import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum; + +import java.util.Map; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -79,6 +83,21 @@ public class ModelConverterTest { } @Test + public void testConvertFromToscaElementServiceWithSelfCapabilities() + { + TopologyTemplate topologyTemplate = new TopologyTemplate(); + + Map<String, MapPropertiesDataDefinition> capabilitiesProperties = CapabilityTestUtils + .createCapPropsForTopologyTemplate(topologyTemplate); + + topologyTemplate.setCapabilitiesProperties(capabilitiesProperties); + + topologyTemplate.setComponentType(ComponentTypeEnum.SERVICE); + Component component = test.convertFromToscaElement(topologyTemplate); + assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue()); + } + + @Test public void testConvertFromToscaElementResource() { TopologyTemplate topologyTemplate = new TopologyTemplate(); |