Add Service Template instance attributes to TOSCA Export
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / tosca / InterfacesOperationsConverterTest.java
index 3c425c1..771d52f 100644 (file)
@@ -57,8 +57,6 @@ import org.apache.commons.collections4.MapUtils;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
 import org.onap.sdc.tosca.services.YamlUtil;
 import org.openecomp.sdc.be.DummyConfigurationManager;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
@@ -105,7 +103,7 @@ class InterfacesOperationsConverterTest {
     @BeforeEach
     public void setUpBeforeTest() {
         interfacesOperationsConverter =
-                new InterfacesOperationsConverter(new PropertyConvertor());
+            new InterfacesOperationsConverter(new PropertyConvertor());
     }
 
     @Test
@@ -122,10 +120,10 @@ class InterfacesOperationsConverterTest {
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
         final Map<String, Object> interfaceTypeElement =
-                addInterfaceTypeElement(component, new ArrayList<>());
+            addInterfaceTypeElement(component, new ArrayList<>());
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("test");
         template.setInterface_types(interfaceTypeElement);
         final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
@@ -150,10 +148,10 @@ class InterfacesOperationsConverterTest {
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
         final Map<String, Object> interfaceTypeElement =
-                addInterfaceTypeElement(component, new ArrayList<>());
+            addInterfaceTypeElement(component, new ArrayList<>());
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("testService");
         template.setInterface_types(interfaceTypeElement);
         final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
@@ -178,8 +176,8 @@ class InterfacesOperationsConverterTest {
         ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
         Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
         nodeTypes.put(NODE_TYPE_NAME, nodeType);
@@ -208,8 +206,8 @@ class InterfacesOperationsConverterTest {
         ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("testService");
         Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
         nodeTypes.put(NODE_TYPE_NAME, nodeType);
@@ -236,7 +234,7 @@ class InterfacesOperationsConverterTest {
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
         Map<String, Object> interfacesMap = interfacesOperationsConverter
-                .getInterfacesMap(component, null, component.getInterfaces(), null, false, true);
+            .getInterfacesMap(component, null, component.getInterfaces(), null, false, true);
         ToscaNodeType nodeType = new ToscaNodeType();
         nodeType.setInterfaces(interfacesMap);
         ToscaExportHandler handler = new ToscaExportHandler();
@@ -267,8 +265,8 @@ class InterfacesOperationsConverterTest {
         ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, null, false);
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("test");
         Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
         nodeTypes.put("test", nodeType);
@@ -290,19 +288,19 @@ class InterfacesOperationsConverterTest {
         addedInterface.setType(addedInterfaceType);
         addOperationsToInterface(component, addedInterface, 2, 2, true, true);
         addedInterface.getOperationsMap().values().stream()
-                .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
-                        "name_for_op_0"))
-                .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
-                        .filter(operationInputDefinition -> operationInputDefinition.getName().contains("integer"))
-                        .forEach(operationInputDefinition -> operationInputDefinition.setInputId(addedInterfaceType +
-                                ".name_for_op_1.output_integer_1")));
+            .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
+                "name_for_op_0"))
+            .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
+                .filter(operationInputDefinition -> operationInputDefinition.getName().contains("integer"))
+                .forEach(operationInputDefinition -> operationInputDefinition.setInputId(addedInterfaceType +
+                    ".name_for_op_1.output_integer_1")));
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(addedInterfaceType, addedInterface);
         ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("test");
         Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
         nodeTypes.put("test", nodeType);
@@ -325,24 +323,24 @@ class InterfacesOperationsConverterTest {
         addedInterface.setType(addedInterfaceType);
         addOperationsToInterface(component, addedInterface, 2, 2, true, true);
         addedInterface.getOperationsMap().values().stream()
-                .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
-                        "name_for_op_0"))
-                .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
-                        .filter(opInputDef -> opInputDef.getName().contains("integer"))
-                        .forEach(opInputDef -> opInputDef.setInputId(
-                                addedInterfaceType +".name_for_op_1.output_integer_1")));
+            .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
+                "name_for_op_0"))
+            .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
+                .filter(opInputDef -> opInputDef.getName().contains("integer"))
+                .forEach(opInputDef -> opInputDef.setInputId(
+                    addedInterfaceType + ".name_for_op_1.output_integer_1")));
         //Mapping to operation from another interface
         String secondInterfaceType = "org.test.lifecycle.standard.interfaceType.second";
         InterfaceDefinition secondInterface = new InterfaceDefinition();
         secondInterface.setType(secondInterfaceType);
         addOperationsToInterface(component, secondInterface, 2, 2, true, true);
         secondInterface.getOperationsMap().values().stream()
-                .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
-                        "name_for_op_0"))
-                .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
-                        .filter(opInputDef -> opInputDef.getName().contains("integer"))
-                        .forEach(opInputDef -> opInputDef.setInputId(
-                                addedInterfaceType +".name_for_op_1.output_integer_1")));
+            .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
+                "name_for_op_0"))
+            .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
+                .filter(opInputDef -> opInputDef.getName().contains("integer"))
+                .forEach(opInputDef -> opInputDef.setInputId(
+                    addedInterfaceType + ".name_for_op_1.output_integer_1")));
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(addedInterfaceType, addedInterface);
         component.getInterfaces().put(secondInterfaceType, secondInterface);
@@ -350,8 +348,8 @@ class InterfacesOperationsConverterTest {
         ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
 
-        ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null, null,null,
-                interfacesOperationsConverter);
+        ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
+            interfacesOperationsConverter);
         ToscaTemplate template = new ToscaTemplate("test");
         Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
         nodeTypes.put("test", nodeType);
@@ -385,7 +383,7 @@ class InterfacesOperationsConverterTest {
         component.getInterfaces().put(interfaceName, aInterfaceWithInput);
         final ToscaNodeType nodeType = new ToscaNodeType();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
-        final ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null,null,
+        final ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
             interfacesOperationsConverter);
         final ToscaTemplate template = new ToscaTemplate("testService");
         final Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
@@ -393,7 +391,8 @@ class InterfacesOperationsConverterTest {
         template.setNode_types(nodeTypes);
         final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
         final String toscaTemplateYaml = new String(toscaRepresentation.getMainYaml());
-        assertThat(toscaTemplateYaml, allOf(containsString(INPUTS.getElementName() + ":"), containsString(input1Name), containsString(interfaceName)));
+        assertThat(toscaTemplateYaml,
+            allOf(containsString(INPUTS.getElementName() + ":"), containsString(input1Name), containsString(interfaceName)));
         validateInterfaceInputs(toscaTemplateYaml, interfaceName, inputMap);
     }
 
@@ -439,15 +438,15 @@ class InterfacesOperationsConverterTest {
     @FunctionalInterface
     interface MainYamlAssertion extends Function<String, Boolean> {}
 
-    private static Function<String, Boolean> all(MainYamlAssertion...fs) {
+    private static Function<String, Boolean> all(MainYamlAssertion... fs) {
         return s -> io.vavr.collection.List.of(fs).map(f -> f.apply(s)).fold(true, (l, r) -> l && r);
     }
 
-    private static MainYamlAssertion containsNone(String...expected) {
+    private static MainYamlAssertion containsNone(String... expected) {
         return s -> io.vavr.collection.List.of(expected).map(e -> !s.contains(e)).fold(true, (l, r) -> l && r);
     }
 
-    private static MainYamlAssertion containsAll(String...expected) {
+    private static MainYamlAssertion containsAll(String... expected) {
         return s -> io.vavr.collection.List.of(expected).map(s::contains).fold(true, (l, r) -> l && r);
     }
 
@@ -467,7 +466,7 @@ class InterfacesOperationsConverterTest {
             }
             if (hasOutputs) {
                 operation.setOutputs(createOutputs(addedInterface.getToscaResourceName(),
-                        operation.getName(), numOfInputsPerOp));
+                    operation.getName(), numOfInputsPerOp));
             }
             addedInterface.getOperations().put(operation.getName(), operation);
         }
@@ -496,7 +495,7 @@ class InterfacesOperationsConverterTest {
         for (int i = 0; i < numOfInputs; i++) {
             String mappedPropertyName = java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME + i;
             operationInputDefinitionList.add(createMockOperationInputDefinition(
-                    INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, mappedPropertyName, i));
+                INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, mappedPropertyName, i));
             addMappedPropertyAsComponentInput(component, mappedPropertyName);
 
         }
@@ -519,7 +518,7 @@ class InterfacesOperationsConverterTest {
         ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
         for (int i = 0; i < numOfOutputs; i++) {
             operationOutputDefinitionList.add(createMockOperationOutputDefinition(interfaceName, operationName,
-                    OUTPUT_NAME_PREFIX + inputTypes[i] + "_" + i, i));
+                OUTPUT_NAME_PREFIX + inputTypes[i] + "_" + i, i));
         }
         return operationOutputDefinitionList;
     }
@@ -559,8 +558,8 @@ class InterfacesOperationsConverterTest {
     private void validateOperationInputs(final String mainYaml, int numOfInputsPerOp, String mappedOperationName) {
         String nodeTypeKey = NODE_TYPE_NAME + ":";
         String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(),
-                mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length()
-                        + String.valueOf(numOfInputsPerOp).length());
+            mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length()
+                + String.valueOf(numOfInputsPerOp).length());
         YamlToObjectConverter objectConverter = new YamlToObjectConverter();
         ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class);
         Map<String, Object> interfaces = toscaNodeType.getInterfaces();
@@ -575,7 +574,7 @@ class InterfacesOperationsConverterTest {
                 if (operationVal instanceof Map) {
                     //Since the inputs are mapped to output operations from only first interface so using that name
                     validateOperationInputDefinition(interfaces.keySet().iterator().next(), mappedOperationName,
-                            operationVal);
+                        operationVal);
                 }
             }
         }
@@ -588,7 +587,7 @@ class InterfacesOperationsConverterTest {
             String[] inputNameSplit = inputEntry.getKey().split("_");
             Map<String, Object> inputValueObject = (Map<String, Object>) inputEntry.getValue();
             validateOperationInputDefinitionDefaultValue(interfaceType, operationName, inputNameSplit[1],
-                    Integer.parseInt(inputNameSplit[2]), inputValueObject);
+                Integer.parseInt(inputNameSplit[2]), inputValueObject);
         }
     }
 
@@ -613,15 +612,15 @@ class InterfacesOperationsConverterTest {
             assertTrue(mappedPropertyDefaultValue.contains(operationName));
             assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
         } else {
-            fail("Invalid Tosca function in default value. Allowed values: "+ ToscaFunctions.GET_PROPERTY.getFunctionName() +
-                    "/"+ ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
+            fail("Invalid Tosca function in default value. Allowed values: " + ToscaFunctions.GET_PROPERTY.getFunctionName() +
+                "/" + ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
         }
     }
 
     private void validateServiceProxyOperationInputs(String mainYaml) {
         String nodeTypeKey = NODE_TYPE_NAME + ":";
         String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(),
-                mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length());
+            mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length());
         YamlUtil yamlUtil = new YamlUtil();
         ToscaNodeType toscaNodeType = yamlUtil.yamlToObject(nodeTypesRepresentation, ToscaNodeType.class);
         for (Object interfaceVal : toscaNodeType.getInterfaces().values()) {
@@ -650,10 +649,10 @@ class InterfacesOperationsConverterTest {
         service.setInterfaces(Collections.singletonMap("Local", new InterfaceDefinition("Local", null, new HashMap<>())));
 
         Map<String, Object> resultMap = InterfacesOperationsConverter.addInterfaceTypeElement(service,
-                Collections.singletonList("org.openecomp.interfaces.node.lifecycle.Standard"));
+            Collections.singletonList("org.openecomp.interfaces.node.lifecycle.Standard"));
 
         assertTrue(MapUtils.isNotEmpty(resultMap)
-                && resultMap.containsKey("org.openecomp.interfaces.node.lifecycle.LocalInterface"));
+            && resultMap.containsKey("org.openecomp.interfaces.node.lifecycle.LocalInterface"));
     }
 
     @Test
@@ -662,13 +661,13 @@ class InterfacesOperationsConverterTest {
         service.setComponentMetadataDefinition(new ServiceMetadataDefinition());
         service.getComponentMetadataDefinition().getMetadataDataDefinition().setName("LocalInterface");
         service.setInterfaces(Collections.singletonMap("NotLocal", new InterfaceDefinition("NotLocal", null,
-                new HashMap<>())));
+            new HashMap<>())));
 
         Map<String, Object> resultMap = interfacesOperationsConverter.getInterfacesMap(service, null,
-                service.getInterfaces(), null, false, false);
+            service.getInterfaces(), null, false, false);
 
         assertTrue(MapUtils.isNotEmpty(resultMap)
-                && resultMap.containsKey("NotLocal"));
+            && resultMap.containsKey("NotLocal"));
     }
 
     @Test