From 874bd9ed420ce8c281450e730d6d1ed3e3dc688e Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Wed, 27 Jun 2018 14:59:48 +0530 Subject: Worklow Operation output tosca Added implementation to export workflow operation outputs to TOSCA template Change-Id: Id4c7104f725f7e9f5c97ae738387d2592bb80f7b Issue-ID: SDC-1450 Signed-off-by: ojasdubey --- .../utils/InterfaceUIDataConverterTest.java | 8 +-- .../utils/InterfacesOperationsToscaUtilTest.java | 67 +++++++++++++++++++--- 2 files changed, 59 insertions(+), 16 deletions(-) (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java index b158ddf5da..7e8dde9842 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java @@ -1,15 +1,10 @@ package org.openecomp.sdc.be.datamodel.utils; -import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IO_INPUT_PARAMETERS; - -import java.util.LinkedList; - import org.junit.Test; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; -import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.Operation; public class InterfaceUIDataConverterTest { @@ -28,9 +23,8 @@ public class InterfaceUIDataConverterTest { Operation operationData = new Operation(); InterfaceOperationDataDefinition result; ListDataDefinition inputs = new ListDataDefinition<>(); - ListDataDefinition outputs = new ListDataDefinition<>(); operationData.setInputs(inputs); - operationData.setOutputs(outputs); + operationData.setOutputs(new ListDataDefinition<>()); operationData.setImplementation(new ArtifactDataDefinition()); // default test result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index 67b27f678f..0c5db04bbd 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -27,6 +27,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; @@ -35,11 +36,6 @@ import org.openecomp.sdc.be.tosca.ToscaRepresentation; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaTemplate; -/** - * @author KATYR - * @since April 12, 2018 - */ - public class InterfacesOperationsToscaUtilTest { @BeforeClass @@ -54,7 +50,7 @@ public class InterfacesOperationsToscaUtilTest { component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); addedInterface.setToscaResourceName("interface.types.test_resource_name"); - addOperationsToInterface(addedInterface, 5, 3, true); + addOperationsToInterface(addedInterface, 5, 3, 0, true, false); final String interfaceType = "normalizedComponentName-interface"; ((Resource) component).setInterfaces(new HashMap<>()); ((Resource) component).getInterfaces().put(interfaceType, addedInterface); @@ -77,7 +73,7 @@ public class InterfacesOperationsToscaUtilTest { InterfaceDefinition addedInterface = new InterfaceDefinition(); addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName"); - addOperationsToInterface(addedInterface, 3, 2, true); + addOperationsToInterface(addedInterface, 3, 2, 0, true, false); final String interfaceType = "normalizedComponentName-interface"; ((Resource) component).setInterfaces(new HashMap<>()); ((Resource) component).getInterfaces().put(interfaceType, addedInterface); @@ -107,7 +103,7 @@ public class InterfacesOperationsToscaUtilTest { InterfaceDefinition addedInterface = new InterfaceDefinition(); addedInterface.setToscaResourceName("com.some.resource.or.other.resourceNameNoInputs"); - addOperationsToInterface(addedInterface, 3, 3, false); + addOperationsToInterface(addedInterface, 3, 3, 0, false, false); final String interfaceType = "normalizedComponentName-interface"; ((Resource) component).setInterfaces(new HashMap<>()); ((Resource) component).getInterfaces().put(interfaceType, addedInterface); @@ -129,9 +125,38 @@ public class InterfacesOperationsToscaUtilTest { Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); } + @Test + public void addInterfaceDefinitionElementWithOutputs() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName"); + + addOperationsToInterface(addedInterface, 2, 0, 2, false, true); + final String interfaceType = "normalizedComponentName-interface"; + ((Resource) component).setInterfaces(new HashMap<>()); + ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + ToscaNodeType nodeType = new ToscaNodeType(); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + + ToscaExportHandler handler = new ToscaExportHandler(); + ToscaTemplate template = new ToscaTemplate("test"); + Map nodeTypes = new HashMap<>(); + nodeTypes.put("test", nodeType); + template.setNode_types(nodeTypes); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceName:")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("outputs:")); + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("naming_function_")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); + } private void addOperationsToInterface(InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp, - boolean hasInputs) { + int numOfOutputsPerOp, boolean hasInputs, boolean hasOutputs) { addedInterface.setOperations(new HashMap<>()); for (int i = 0; i < numOfOps; i++) { @@ -144,6 +169,9 @@ public class InterfacesOperationsToscaUtilTest { if (hasInputs) { operation.setInputs(createInputs(numOfInputsPerOp)); } + if (hasOutputs) { + operation.setOutputs(createOutputs(numOfOutputsPerOp)); + } addedInterface.getOperations().put(operation.getName(), operation); } } @@ -158,6 +186,18 @@ public class InterfacesOperationsToscaUtilTest { return operationInputDefinitionList; } + private ListDataDefinition createOutputs(int numOfOutputs) { + ListDataDefinition operationOutputDefinitionList = new ListDataDefinition<>(); + for (int i = 0; i < numOfOutputs; i++) { + operationOutputDefinitionList.add(createMockOperationOutputDefinition("output_" + i, + java.util.UUID.randomUUID().toString() + "." + "naming_function_" + i, getTestOutputType(i))); + } + return operationOutputDefinitionList; + } + + private String getTestOutputType(int i) { + return i%2 == 0 ? "integer" : "boolean"; + } private OperationInputDefinition createMockOperationInputDefinition(String name, String id) { OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); @@ -165,4 +205,13 @@ public class InterfacesOperationsToscaUtilTest { operationInputDefinition.setInputId(id); return operationInputDefinition; } + + private OperationOutputDefinition createMockOperationOutputDefinition(String name, String id, String type) { + OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition(); + operationOutputDefinition.setName(name); + operationOutputDefinition.setInputId(id); + operationOutputDefinition.setType(type); + return operationOutputDefinition; + } + } -- cgit 1.2.3-korg