diff options
Diffstat (limited to 'catalog-be/src/test/java/org')
2 files changed, 59 insertions, 16 deletions
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<OperationInputDefinition> inputs = new ListDataDefinition<>(); - ListDataDefinition<OperationOutputDefinition> 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<String, ToscaNodeType> 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<OperationOutputDefinition> createOutputs(int numOfOutputs) { + ListDataDefinition<OperationOutputDefinition> 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; + } + } |