summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java163
1 files changed, 163 insertions, 0 deletions
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<String, Object> 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<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("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<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.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<OperationInputDefinition> createInputs(int numOfInputs) {
+ ListDataDefinition<OperationInputDefinition> 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;
+ }
+}