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-be/src/test/java/org | |
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-be/src/test/java/org')
8 files changed, 568 insertions, 26 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogicTest.java index 393ef58d1d..55b87f41cf 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogicTest.java @@ -30,11 +30,14 @@ import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.CapabilityRequirementRelationship; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.RelationshipInfo; @@ -111,17 +114,17 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(StorageOperationStatus.OK); //CapabilityOperation - when(capabilitiesValidation.validateCapabilities(anyCollection(), anyObject(), anyBoolean()) - ).thenReturn(Either.left(true)); + when(capabilitiesValidation.validateCapabilities(anyCollection(), anyObject(), anyBoolean())) + .thenReturn(Either.left(true)); when(capabilitiesOperation.addCapabilities(anyString(), anyObject())) .thenReturn(Either.left(createMockCapabilityListToReturn( createCapability("capName", "capDesc", "capType", "source1", - "0", "10")))); + "0", "10")))); when(capabilitiesOperation.updateCapabilities(anyString(), anyObject())) .thenReturn(Either.left(createMockCapabilityListToReturn( createCapability("capName", "capDesc", "capType", "source1", - "0", "10")))); + "0", "10")))); when(capabilitiesOperation.deleteCapabilities( anyObject(), anyString())) .thenReturn(StorageOperationStatus.OK); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); @@ -141,7 +144,7 @@ public class CapabilitiesBusinessLogicTest { public void shouldPassCreateCapabilitiesFirstTimeInComponentForHappyScenario(){ List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName", "capDesc", "capType", "source1", - "0", "10")); + "0", "10")); Resource resource = createComponent(false); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -149,7 +152,7 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(Either.left(resource)); Either<List<CapabilityDefinition>, ResponseFormat> capabilities = capabilitiesBusinessLogicMock .createCapabilities(componentId, capabilityDefinitions, user, - "createCapabilities", true); + "createCapabilities", true); Assert.assertTrue(capabilities.isLeft()); Assert.assertTrue(capabilities.left().value().stream().anyMatch(capabilityDefinition -> capabilityDefinition.getName().equals("capName"))); @@ -159,7 +162,7 @@ public class CapabilitiesBusinessLogicTest { public void shouldPassCreateCapabilitiesForHappyScenario(){ List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName2", "capDesc", "capType", "source1", - "0", "10")); + "0", "10")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -178,7 +181,7 @@ public class CapabilitiesBusinessLogicTest { public void shouldFailCreateCapabilitiesWhenOperationFailedInTitan(){ List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName2", "capDesc", "capType", "source1", - "0", "10")); + "0", "10")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -190,7 +193,7 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(Either.left(resource)); Either<List<CapabilityDefinition>, ResponseFormat> capabilities = capabilitiesBusinessLogicMock .createCapabilities(componentId, capabilityDefinitions, user, - "createCapabilities", true); + "createCapabilities", true); Assert.assertTrue(capabilities.isRight()); } @@ -199,7 +202,7 @@ public class CapabilitiesBusinessLogicTest { List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName", "capDesc updated", "capType", "source1", - "6", "11")); + "6", "11")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -220,7 +223,7 @@ public class CapabilitiesBusinessLogicTest { List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName", "capDesc updated", "capTypeUpdate", "source1", - "6", "11")); + "6", "11")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -228,6 +231,8 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(Either.left(resource)); when(toscaOperationFacade.getParentComponents(anyString())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when((capabilitiesOperation.deleteCapabilityProperties(any(Component.class), anyString()))) + .thenReturn(StorageOperationStatus.OK); Either<List<CapabilityDefinition>, ResponseFormat> capabilities = capabilitiesBusinessLogicMock .updateCapabilities(componentId, capabilityDefinitions, user, "updateCapabilities",true); @@ -241,7 +246,7 @@ public class CapabilitiesBusinessLogicTest { List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName", "capDesc updated", "capTypeUpdate1", "source1", - "6", "11")); + "6", "11")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); @@ -258,6 +263,8 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(Either.left(resource)); when(toscaOperationFacade.getParentComponents(anyString())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when((capabilitiesOperation.deleteCapabilityProperties(any(Component.class), anyString()))) + .thenReturn(StorageOperationStatus.OK); Either<List<CapabilityDefinition>, ResponseFormat> capabilities = capabilitiesBusinessLogicMock .updateCapabilities(componentId, capabilityDefinitions, user, "updateCapabilities",true); @@ -267,10 +274,10 @@ public class CapabilitiesBusinessLogicTest { } @Test - public void shouldFailUpdateCapabilitiesWhenOperaitonFailedInTitan(){ + public void shouldFailUpdateCapabilitiesWhenOperationFailedInTitan(){ List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName2", "capDesc", "capType", "source1", - "0", "10")); + "0", "10")); Resource resource = createComponent(true); resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); @@ -296,6 +303,8 @@ public class CapabilitiesBusinessLogicTest { .thenReturn(Either.left(resource)); when(toscaOperationFacade.getParentComponents(anyString())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when((capabilitiesOperation.deleteCapabilityProperties(any(Component.class), anyString()))) + .thenReturn(StorageOperationStatus.OK); Either<CapabilityDefinition, ResponseFormat> deleteCapabilityEither = capabilitiesBusinessLogicMock.deleteCapability(componentId, capabilityId, user, true); Assert.assertTrue(deleteCapabilityEither.isLeft()); @@ -362,6 +371,38 @@ public class CapabilitiesBusinessLogicTest { } + private ComponentInstanceProperty createCIP(String type, String name) { + ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty(); + instanceProperty.setType(type); + instanceProperty.setName(name); + instanceProperty.setDescription("prop_description"); + instanceProperty.setParentUniqueId(capabilityId); + instanceProperty.setSchema(new SchemaDefinition()); + return instanceProperty; + } + + @Test + public void shouldPassCreateCapabilitiesWithPropertiesForHappyScenario(){ + CapabilityDefinition capability = createCapability("capName", "capDesc", "capType", "source1", + "0", "10"); + capability.setProperties(Collections.singletonList(createCIP("name", "type"))); + List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn(capability); + Resource resource = createComponent(false); + resource.setComponentType(ComponentTypeEnum.RESOURCE); + validateUserRoles(Role.ADMIN, Role.DESIGNER); + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) + .thenReturn(Either.left(resource)); + when(capabilitiesOperation.createOrUpdateCapabilityProperties(anyString(), any())).thenReturn(StorageOperationStatus.OK); + Either<List<CapabilityDefinition>, ResponseFormat> capabilities = capabilitiesBusinessLogicMock + .createCapabilities(componentId, capabilityDefinitions, user, + "createCapabilities", true); + Assert.assertTrue(capabilities.isLeft()); + Assert.assertTrue(capabilities.left().value().stream().anyMatch(capabilityDefinition -> + capabilityDefinition.getName().equals("capName"))); + Assert.assertTrue(capabilities.left().value().stream().anyMatch(capabilityDefinition -> + capabilityDefinition.getProperties().size() == 1)); + } + private Resource createComponent(boolean needCapability) { Resource resource = new Resource(); resource.setName("Resource1"); @@ -375,17 +416,17 @@ public class CapabilitiesBusinessLogicTest { if(needCapability) { List<CapabilityDefinition> capabilityDefinitions = createMockCapabilityListToReturn( createCapability("capName", "capDesc", "capType", "source1", - "0", "10")); + "0", "10")); Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); capabilityMap.put("capType", capabilityDefinitions); resource.setCapabilities(capabilityMap); } - resource.setName(resource.getName()); - resource.setVersion("0.1"); - resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion()); - resource.setCreatorUserId(user.getUserId()); - resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); - resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + resource.setName(resource.getName()); + resource.setVersion("0.1"); + resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion()); + resource.setCreatorUserId(user.getUserId()); + resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); + resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); return resource; } @@ -410,7 +451,6 @@ public class CapabilitiesBusinessLogicTest { capabilityDefinition.setMaxOccurrences(maxOccurrences); capabilityDefinition.setMinOccurrences(minOccurrences); capabilityDefinition.setUniqueId(capabilityId); - return capabilityDefinition; } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index 963823c261..d5b1f06b82 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -45,10 +46,13 @@ import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; @@ -146,6 +150,44 @@ public class InterfaceOperationBusinessLogicTest { } @Test + public void createInterfaceOperationTestOnExistingInterfaceInputsFromCapProp() { + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) + .thenReturn(Either.left(Collections.emptyMap())); + when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left( + Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)))); + + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("cap" + Math.random()); + capabilityDefinition.setType("tosca.capabilities.network.Bindable"); + capabilityDefinition.setOwnerId(resourceId); + capabilityDefinition.setUniqueId("capUniqueId"); + + List<ComponentInstanceProperty> properties = new ArrayList<>(); + 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.setSchema(new SchemaDefinition()); + properties.add(instanceProperty); + capabilityDefinition.setProperties(properties); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + + resource.setCapabilities(capabilityMap); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + + Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither = + interfaceOperationBusinessLogic.createInterfaceOperation(resourceId, + Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, + operationId, operationName)), + user, true); + Assert.assertTrue(interfaceOperationEither.isLeft()); + } + + + @Test public void createInterfaceOperationWithoutInterfaceTest() { resource.getInterfaces().clear(); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()) diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java new file mode 100644 index 0000000000..7e15eaa862 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/PropertiesUtilsTest.java @@ -0,0 +1,195 @@ +/* + * 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.components.impl.utils; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.utils.PropertiesUtils; +import org.openecomp.sdc.be.components.utils.ResourceBuilder; +import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; +@RunWith(MockitoJUnitRunner.class) +public class PropertiesUtilsTest { + @Mock + Service service; + + + @Test + public void testProxyServiceProperties(){ + when(service.getProperties()).thenReturn(Arrays.asList(buildPropertyDefinition("a"),buildPropertyDefinition("b"))); + when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefiniton("a"),buildInputDefiniton("c"))); + + final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service); + assertEquals(3, properties.size()); + } + + @Test + public void testProxyServiceNullInputs(){ + when(service.getProperties()).thenReturn(Arrays.asList(buildPropertyDefinition("a"),buildPropertyDefinition("b"))); + when(service.getInputs()).thenReturn(null); + + final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service); + assertEquals(2, properties.size()); + } + + @Test + public void testProxyServiceNullProperties(){ + when(service.getProperties()).thenReturn(null); + when(service.getInputs()).thenReturn(Arrays.asList(buildInputDefiniton("a"),buildInputDefiniton("c"))); + + final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service); + assertEquals(2, properties.size()); + } + + @Test + public void testGetCapabilityProperty() { + + Assert.assertEquals(1, PropertiesUtils.getCapabilityProperty(createProperties(), + "inputId").size()); + } + + @Test + public void testGetPropertyCapabilityOfChildInstance() { + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + capabilityDefinition.setPath(Collections.singletonList("path")); + Map<String, List<CapabilityDefinition>> capMap = new HashMap<>(); + capMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + Assert.assertTrue(PropertiesUtils.getPropertyCapabilityOfChildInstance("capUniqueId", + capMap).isPresent()); + } + + @Test + public void testGetPropertyCapabilityFromAllCapProps() { + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + Map<String, List<CapabilityDefinition>> capMap = new HashMap<>(); + capMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + Assert.assertTrue(PropertiesUtils.getPropertyCapabilityOfChildInstance("capUniqueId", + capMap).isPresent()); + } + + @Test + + public void testGetPropertyByInputId() { + Resource resource = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId("resourceId") + .setName("name").build(); + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + + List<ComponentInstanceProperty> properties = new ArrayList<>(); + ComponentInstanceProperty instanceProperty = createProperties(); + + List<GetInputValueDataDefinition> valueDataDefinitionList = new ArrayList<>(); + GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); + getInputValueDataDefinition.setInputId("inputId"); + getInputValueDataDefinition.setPropName("prop_name"); + valueDataDefinitionList.add(getInputValueDataDefinition); + + instanceProperty.setGetInputValues(valueDataDefinitionList); + properties.add(instanceProperty); + capabilityDefinition.setProperties(properties); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + resource.setCapabilities(capabilityMap); + + InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setUniqueId("inputId"); + inputDefinition.setInputId("inputId"); + inputDefinition.setPropertyId("inputId"); + resource.setInputs(Collections.singletonList(inputDefinition)); + Assert.assertTrue(PropertiesUtils.getPropertyByInputId(resource, "inputId").isPresent()); + } + + @Test + public void testIsNodeServiceProxy() { + Resource resource = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId("resourceId") + .setName("name").build(); + resource.setResourceType(ResourceTypeEnum.ServiceProxy); + Assert.assertTrue( PropertiesUtils.isNodeServiceProxy(resource)); + } + + @Test + public void testProxyServiceAllNull(){ + when(service.getProperties()).thenReturn(null); + when(service.getInputs()).thenReturn(null); + + final List<PropertyDefinition> properties = PropertiesUtils.getProperties(service); + assertEquals(0, properties.size()); + } + + private PropertyDefinition buildPropertyDefinition(String name){ + PropertyDefinition retVal = new PropertyDefinition(); + retVal.setName(name); + return retVal; + } + + private InputDefinition buildInputDefiniton(String name){ + InputDefinition retVal = new InputDefinition(); + retVal.setName(name); + return retVal; + } + + private ComponentInstanceProperty createProperties() { + ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty(); + instanceProperty.setUniqueId("inputId"); + 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()); + + List<GetInputValueDataDefinition> valueDataDefinitionList = new ArrayList<>(); + GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); + getInputValueDataDefinition.setInputId("inputId"); + getInputValueDataDefinition.setPropName("prop_name"); + valueDataDefinitionList.add(getInputValueDataDefinition); + instanceProperty.setGetInputValues(valueDataDefinitionList); + return instanceProperty; + } + + private 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; + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/CapabilityTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/CapabilityTestUtils.java new file mode 100644 index 0000000000..fc0edd9fd1 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/CapabilityTestUtils.java @@ -0,0 +1,51 @@ +/* + * 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.components.property; + +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; + +import java.util.ArrayList; +import java.util.List; + +public class CapabilityTestUtils { + + public 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; + } + + public 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; + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java index f59adada9a..deb634e232 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java @@ -13,6 +13,7 @@ import org.openecomp.sdc.be.components.utils.ResourceBuilder; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; @@ -24,9 +25,12 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition; +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; @RunWith(MockitoJUnitRunner.class) @@ -65,6 +69,64 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT } @Test + public void declareCapabilitiesPropertiesAsInputs() { + prop1.setParentUniqueId("capUniqueId"); + List<PropertyDataDefinition> properties = Collections.singletonList(prop1); + List<ComponentInstancePropInput> propsToDeclare = createInstancePropInputList(properties); + when(toscaOperationFacade.addComponentInstancePropertiesToComponent(eq(resource), instancePropertiesCaptor + .capture())).thenReturn(Either.left(Collections.emptyMap())); + + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + + List<ComponentInstanceProperty> capPropList = new ArrayList<>(); + ComponentInstanceProperty instanceProperty = createProperties(); + capPropList.add(instanceProperty); + capabilityDefinition.setProperties(capPropList); + + capabilityDefinition.setPath(Collections.singletonList("path")); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + resource.setCapabilities(capabilityMap); + + Either<List<InputDefinition>, StorageOperationStatus> createdInputs = testInstance + .declarePropertiesAsInputs(resource, "inst1", propsToDeclare); + Assert.assertTrue(createdInputs.isLeft()); + } + + @Test + public void testUnDeclarePropertiesAsInputs() throws Exception { + Component component = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId("resourceId") + .setName("resourceName").build(); + InputDefinition input = new InputDefinition(); + input.setUniqueId("ComponentInput1_uniqueId"); + input.setPropertyId("ComponentInput1_uniqueId"); + + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + + List<ComponentInstanceProperty> properties = new ArrayList<>(); + ComponentInstanceProperty instanceProperty = createProperties(); + + List<GetInputValueDataDefinition> valueDataDefinitionList = new ArrayList<>(); + GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); + getInputValueDataDefinition.setInputId("ComponentInput1_uniqueId"); + getInputValueDataDefinition.setPropName("prop_name"); + valueDataDefinitionList.add(getInputValueDataDefinition); + + instanceProperty.setGetInputValues(valueDataDefinitionList); + properties.add(instanceProperty); + capabilityDefinition.setProperties(properties); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + component.setCapabilities(capabilityMap); + component.setInputs(Collections.singletonList(input)); + when(toscaOperationFacade.updateInstanceCapabilityProperty(any(Resource.class), any(), + any(ComponentInstanceProperty.class), any(CapabilityDefinition.class))).thenReturn(StorageOperationStatus.OK); + + StorageOperationStatus result = testInstance.unDeclarePropertiesAsInputs(component, input); + Assert.assertEquals(StorageOperationStatus.OK, result); + } + + @Test public void declarePropertiesAsInputs_multipleNonComplexProperty() { List<PropertyDataDefinition> properties = Arrays.asList(prop1, prop2); List<ComponentInstancePropInput> propsToDeclare = createInstancePropInputList(properties); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java new file mode 100644 index 0000000000..619c2949d2 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java @@ -0,0 +1,76 @@ +/* + * 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.components.utils; + + +import fj.data.Either; +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.types.ServiceConsumptionData; +import org.openecomp.sdc.exception.ResponseFormat; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition; +import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; + +public class ConsumptionUtilsTest { + + @Test + public void testHandleConsumptionInputMappedToCapabilityProperty() { + + Operation operation = new Operation(); + operation.setUniqueId("uniqueId"); + OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); + operationInputDefinition.setUniqueId("uniqueId"); + operationInputDefinition.setInputId("uniqueId"); + operationInputDefinition.setType("Integer"); + + List<OperationInputDefinition> operationInputDefinitions = new ArrayList<>(); + operationInputDefinitions.add(operationInputDefinition); + ListDataDefinition<OperationInputDefinition> listDataDefinition = new ListDataDefinition<>(operationInputDefinitions); + operation.setInputs(listDataDefinition); + CapabilityDefinition capabilityDefinition = createCapabilityDefinition(); + ServiceConsumptionData serviceConsumptionData = new ServiceConsumptionData(); + serviceConsumptionData.setInputId("uniqueId"); + serviceConsumptionData.setValue(capabilityDefinition.getName() + "_prop_name" ); + + List<ComponentInstanceProperty> capPropList = new ArrayList<>(); + ComponentInstanceProperty instanceProperty = createProperties(); + capPropList.add(instanceProperty); + capabilityDefinition.setProperties(capPropList); + + capabilityDefinition.setPath(Collections.singletonList("path")); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition)); + + Either<Operation, ResponseFormat> operationResponseFormatEither = ConsumptionUtils + .handleConsumptionInputMappedToCapabilityProperty(operation, operationInputDefinition, + serviceConsumptionData, capabilityMap, "componentName"); + + Assert.assertTrue(operationResponseFormatEither.isLeft()); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java index 1258bc04a9..74c7b8d841 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java @@ -129,4 +129,10 @@ public class InterfaceOperationUtilsTest { Assert.assertFalse(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId1")); } + @Test + public void testCreateMappedCapabilityPropertyDefaultValue() { + Assert.assertTrue(!InterfaceOperationUtils + .createMappedCapabilityPropertyDefaultValue("capName", "propName").isEmpty()); + } + }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidationTest.java index b4856b96b4..4c3ad329d2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidationTest.java @@ -102,6 +102,36 @@ public class CapabilitiesValidationTest { } @Test + public void shouldPassWhenCapabilityMaxOccurrencesIsUnbounded() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + capabilityDefinitions.add(createCapability("capName1", "capDesc", "capType", "source1", + "111", "UNBOUNDED")); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, component, false); + Assert.assertTrue(validateCapabilitiesResponseEither.isLeft()); + } + + @Test + public void shouldFailWhenCapabilityMinOccurrencesIsNegative() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + capabilityDefinitions.add(createCapability("capName1", "capDesc", "capType", "source1", + "-1", "3")); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, component, false); + Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); + } + + @Test + public void shouldThrowExceptionWhenMin_MaxOccurrencesIsNotInteger() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + capabilityDefinitions.add(createCapability("capName1", "capDesc", "capType", "source1", + "occur", "3")); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, component, false); + Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); + } + + @Test public void shouldFailWhenCapabilityNotFoundForUpdate() { List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); CapabilityDefinition capabilityToUpdate = createCapability("capName1", "capDesc", "capType", "source1", @@ -114,6 +144,47 @@ public class CapabilitiesValidationTest { Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); } + @Test + public void shouldFailWhenCapabilityMapIsEmptyInComponentForUpdate() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + CapabilityDefinition capabilityToUpdate = createCapability("capName1", "capDesc", "capType", "source1", + "1", "3"); + capabilityToUpdate.setUniqueId("uniqueId2"); + capabilityDefinitions.add(capabilityToUpdate); + Component resource = new Resource(); + List<CapabilityDefinition> componentCap = new ArrayList<>(); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put("capTypeC", componentCap); + + resource.setCapabilities(capabilityMap); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, resource, true); + Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); + } + + @Test + public void shouldFailWhenCapabilityMapIsNullInComponentForUpdate() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + CapabilityDefinition capabilityToUpdate = createCapability("capName1", "capDesc", "capType", "source1", + "1", "3"); + capabilityToUpdate.setUniqueId("uniqueId2"); + + capabilityDefinitions.add(capabilityToUpdate); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, new Resource(), true); + Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); + } + + @Test + public void shouldFailWhenCapabilityNameContainsSpecialSymbolExceptDot() { + List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); + capabilityDefinitions.add(createCapability("cap@name", "capDesc", "capType", "source1", + "0", "10")); + Either<Boolean, ResponseFormat> validateCapabilitiesResponseEither = capabilitiesValidationUtilTest + .validateCapabilities(capabilityDefinitions, component, false); + Assert.assertTrue(validateCapabilitiesResponseEither.isRight()); + } + private CapabilityDefinition createCapability(String name, String description, String type, String validSourceTypes, String minOccurrences, String maxOccurrences) { @@ -126,7 +197,6 @@ public class CapabilitiesValidationTest { capabilityDefinition.setMinOccurrences(minOccurrences); capabilityDefinition.setUniqueId("uniqueId"); - return capabilityDefinition; } @@ -143,9 +213,9 @@ public class CapabilitiesValidationTest { List<CapabilityDefinition> capabilityDefinitions = new ArrayList<>(); capabilityDefinitions.add(createCapability("capNameC", "capDesc", "capType", "source1", "0", "10")); - Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); - capabilityMap.put("capTypeC", capabilityDefinitions); - resource.setCapabilities(capabilityMap); + Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>(); + capabilityMap.put("capTypeC", capabilityDefinitions); + resource.setCapabilities(capabilityMap); return resource; } |