From f9561f8b5a361fa027a162aef697e5c0115c1415 Mon Sep 17 00:00:00 2001 From: "katy.rotman" Date: Wed, 9 May 2018 14:35:53 +0300 Subject: Tosca for Workflow operations Issue-ID: SDC-1060 Change-Id: I0c334f7aaf99443577478773e7be91de26f8508e Signed-off-by: katy.rotman --- .../utils/InterfacesOperationsToscaUtilTest.java | 163 +++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java (limited to 'catalog-be/src/test/java/org') 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 new file mode 100644 index 0000000000..ee33d00806 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -0,0 +1,163 @@ +/* + * 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.tosca.utils; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openecomp.sdc.be.DummyConfigurationManager; +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.model.Component; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.tosca.ToscaExportHandler; +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 + public static void setUp() throws Exception { + new DummyConfigurationManager(); + } + + + @Test + public void addInterfaceTypeElement() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("interface.types.test_resource_name"); + addOperationsToInterface(addedInterface, 5, 3, true); + final String interfaceType = "normalizedComponentName-interface"; + ((Resource) component).setInterfaces(new HashMap<>()); + ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + final Map interfaceTypeElement = + InterfacesOperationsToscaUtil.addInterfaceTypeElement(component); + + ToscaExportHandler handler = new ToscaExportHandler(); + ToscaTemplate template = new ToscaTemplate("test"); + template.setInterface_types(interfaceTypeElement); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_resource_name")); + } + + @Test + public void addInterfaceDefinitionElement() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName"); + + addOperationsToInterface(addedInterface, 3, 2, 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("inputs:")); + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); + } + + @Test + public void addInterfaceDefinitionElement_noInputs() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("com.some.resource.or.other.resourceNameNoInputs"); + + addOperationsToInterface(addedInterface, 3, 3, false); + 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.assertFalse(toscaRepresentation.getMainYaml().contains("input_")); + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceNameNoInputs:")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); + } + + + private void addOperationsToInterface(InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp, + boolean hasInputs) { + + addedInterface.setOperations(new HashMap<>()); + for (int i = 0; i < numOfOps; i++) { + final OperationDataDefinition operation = new OperationDataDefinition(); + operation.setName("name_for_op_" + i); + final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); + implementation.setArtifactName(i + "_createBPMN.bpmn"); + operation.setImplementation(implementation); + if (hasInputs) { + operation.setInputs(createInputs(numOfInputsPerOp)); + } + addedInterface.getOperations().put(operation.getName(), operation); + } + } + + + private ListDataDefinition createInputs(int numOfInputs) { + ListDataDefinition operationInputDefinitionList = new ListDataDefinition<>(); + for (int i = 0; i < numOfInputs; i++) { + operationInputDefinitionList.add(createMockOperationInputDefinition("input_" + i, + java.util.UUID.randomUUID().toString() + "." + "naming_function_" + i)); + } + return operationInputDefinitionList; + } + + + private OperationInputDefinition createMockOperationInputDefinition(String name, String id) { + OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); + operationInputDefinition.setName(name); + operationInputDefinition.setInputId(id); + return operationInputDefinition; + } +} -- cgit 1.2.3-korg