package org.openecomp.sdc.be.tosca;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.anEmptyMap;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
-import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INTERFACES;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPES;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Objects;
-import java.util.function.Function;
-import java.util.stream.Collectors;
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.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.DummyConfigurationManager;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.FilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
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.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.ServiceMetadataDefinition;
+import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
-import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
-import org.openecomp.sdc.common.util.YamlToObjectConverter;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.yaml.snakeyaml.Yaml;
class InterfacesOperationsConverterTest {
private static final String INPUT_NAME_PREFIX = "input_";
private static final String OUTPUT_NAME_PREFIX = "output_";
private static final String NODE_TYPE_NAME = "test";
- private final String[] inputTypes = {"string", "integer", "float", "boolean"};
- private static ObjectMapper mapper;
private static final Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
-
+ private static ObjectMapper mapper;
+ private final String[] inputTypes = {"string", "integer", "float", "boolean"};
private InterfacesOperationsConverter interfacesOperationsConverter;
@BeforeAll
@BeforeEach
public void setUpBeforeTest() {
- interfacesOperationsConverter =
- new InterfacesOperationsConverter(new PropertyConvertor());
+ interfacesOperationsConverter = new InterfacesOperationsConverter(new PropertyConvertor());
}
@Test
component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("Local");
- addOperationsToInterface(component, addedInterface, 5, 3, true, false);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
- final Map<String, Object> interfaceTypeElement =
- addInterfaceTypeElement(component, new ArrayList<>());
-
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- ToscaTemplate template = new ToscaTemplate("test");
- template.setInterface_types(interfaceTypeElement);
- final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
-
- assertTrue(all(
- containsAll("NodeTypeName"),
- containsNone("operations")
- ).apply(new String(toscaRepresentation.getMainYaml())));
+ final Map<String, Object> interfaceTypeElement = interfacesOperationsConverter.addInterfaceTypeElement(component, new ArrayList<>());
+ assertNotNull(interfaceTypeElement);
+ assertTrue(interfaceTypeElement.containsKey("org.openecomp.interfaces.node.lifecycle.NodeTypeName"));
+ Object o = interfaceTypeElement.get("org.openecomp.interfaces.node.lifecycle.NodeTypeName");
+ assertNotNull(o);
+ assertTrue(o instanceof Map);
+ assertEquals(7, ((Map) o).size());
+
}
@Test
component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("Local");
- addOperationsToInterface(component, addedInterface, 5, 3, true, false);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
- final Map<String, Object> interfaceTypeElement =
- addInterfaceTypeElement(component, new ArrayList<>());
-
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- ToscaTemplate template = new ToscaTemplate("testService");
- template.setInterface_types(interfaceTypeElement);
- final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
-
- assertTrue(all(
- containsAll("NodeTypeName"),
- containsNone("operations")
- ).apply(new String(toscaRepresentation.getMainYaml())));
+ final Map<String, Object> interfaceTypeElement = interfacesOperationsConverter.addInterfaceTypeElement(component, new ArrayList<>());
+ assertNotNull(interfaceTypeElement);
+ assertTrue(interfaceTypeElement.containsKey("org.openecomp.interfaces.node.lifecycle.NodeTypeName"));
+ Object o = interfaceTypeElement.get("org.openecomp.interfaces.node.lifecycle.NodeTypeName");
+ assertNotNull(o);
+ assertTrue(o instanceof Map);
+ assertEquals(7, ((Map) o).size());
+
}
@Test
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("resourceName"));
+ Object resourceName = interfaces.get("resourceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(4, ((Map) resourceName).size());
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
- Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- nodeTypes.put(NODE_TYPE_NAME, nodeType);
- template.setNode_types(nodeTypes);
- final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
-
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
- containsNone("operations", "defaultp")
- ).apply(mainYaml));
-
- validateOperationInputs(mainYaml, 2, null);
}
@Test
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.service.or.other.serviceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("serviceName"));
+ Object resourceName = interfaces.get("serviceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(4, ((Map) resourceName).size());
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- ToscaTemplate template = new ToscaTemplate("testService");
- Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- nodeTypes.put(NODE_TYPE_NAME, nodeType);
- template.setNode_types(nodeTypes);
- final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("serviceName", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.service.or.other.serviceName"),
- containsNone("operations", "defaultp")
- ).apply(mainYaml));
- validateOperationInputs(mainYaml, 2, null);
}
-
@Test
void testGetInterfaceAsMapServiceProxy() {
Component component = new Resource();
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
- Map<String, Object> interfacesMap = interfacesOperationsConverter
- .getInterfacesMap(component, null, component.getInterfaces(), null, false, true);
- ToscaNodeType nodeType = new ToscaNodeType();
- nodeType.setInterfaces(interfacesMap);
- ToscaExportHandler handler = new ToscaExportHandler();
- ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
- Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- nodeTypes.put(NODE_TYPE_NAME, nodeType);
- template.setNode_types(nodeTypes);
- final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
-
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
- containsNone("operations", "defaultp")
- ).apply(mainYaml));
- validateServiceProxyOperationInputs(mainYaml);
+ final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), null, false);
+ assertNotNull(interfacesMap);
+ assertEquals(1, interfacesMap.size());
+ assertTrue(interfacesMap.containsKey("resourceName"));
+ Object resourceName = interfacesMap.get("resourceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(4, ((Map) resourceName).size());
+
}
@Test
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceNameNoInputs");
- addOperationsToInterface(component, addedInterface, 3, 3, false, false);
+ addOperationsToInterface(component, addedInterface, 3, 3, false, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, null, false);
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("resourceNameNoInputs"));
+ Object resourceName = interfaces.get("resourceNameNoInputs");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(4, ((Map) resourceName).size());
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- 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);
-
- assertTrue(all(
- containsAll("resourceNameNoInputs", "has description", "com.some.resource.or.other.resourceName"),
- containsNone("operations", INPUT_NAME_PREFIX, "defaultp")
- ).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType(addedInterfaceType);
- addOperationsToInterface(component, addedInterface, 2, 2, true, true);
+ addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
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")));
+ .forEach(operationInputDefinition -> {
+ operationInputDefinition.setInputId(addedInterfaceType + ".name_for_op_1.output_integer_1");
+ operationInputDefinition.setToscaDefaultValue(
+ new Gson().toJson(createMappedOutputDefaultValue(SELF, operationInputDefinition.getInputId())));
+ }));
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(addedInterfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("resourceNameInputMappedToOutput"));
+ Object resourceName = interfaces.get("resourceNameInputMappedToOutput");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- 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);
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("resourceNameInputMappedToOutput:", "inputs:"),
- containsNone("operations")
- ).apply(mainYaml));
- validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
@Test
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType(addedInterfaceType);
- addOperationsToInterface(component, addedInterface, 2, 2, true, true);
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+ addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
addedInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
"name_for_op_0"))
String secondInterfaceType = "org.test.lifecycle.standard.interfaceType.second";
InterfaceDefinition secondInterface = new InterfaceDefinition();
secondInterface.setType(secondInterfaceType);
- addOperationsToInterface(component, secondInterface, 2, 2, true, true);
+ secondInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+ addOperationsToInterface(component, secondInterface, 2, 2, true, true, false, false);
secondInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
"name_for_op_0"))
ToscaNodeType nodeType = new ToscaNodeType();
interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(2, interfaces.size());
+ assertTrue(interfaces.containsKey("resourceNameInputMappedToOutput"));
+ Object resourceName = interfaces.get("resourceNameInputMappedToOutput");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
+
+ assertTrue(interfaces.containsKey("second"));
+ resourceName = interfaces.get("second");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
- ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null, null, null,
- interfacesOperationsConverter, null);
- 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);
-
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("resourceNameInputMappedToOutput:", "inputs:"),
- containsNone("operations")
- ).apply(mainYaml));
- validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
@Test
void interfaceWithInputsToscaExportTest() {
final Component component = new Service();
- final InterfaceDefinition aInterfaceWithInput = new InterfaceDefinition();
+ final InterfaceDefinition anInterfaceWithInput = new InterfaceDefinition();
final String interfaceName = "myInterfaceName";
final String interfaceType = "my.type." + interfaceName;
- aInterfaceWithInput.setType(interfaceType);
+ anInterfaceWithInput.setType(interfaceType);
final String input1Name = "input1";
final InputDataDefinition input1 = createInput("string", "input1 description", false, "input1 value");
final String input2Name = "input2";
final Map<String, InputDataDefinition> inputMap = new HashMap<>();
inputMap.put(input1Name, input1);
inputMap.put(input2Name, input2);
- aInterfaceWithInput.setInputs(inputMap);
+ anInterfaceWithInput.setInputs(inputMap);
component.setInterfaces(new HashMap<>());
- component.getInterfaces().put(interfaceName, aInterfaceWithInput);
+ component.getInterfaces().put(interfaceName, anInterfaceWithInput);
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, null,
- interfacesOperationsConverter, null);
- final ToscaTemplate template = new ToscaTemplate("testService");
- final Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- nodeTypes.put(NODE_TYPE_NAME, nodeType);
- 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)));
- validateInterfaceInputs(toscaTemplateYaml, interfaceName, inputMap);
- }
-
- private void validateInterfaceInputs(final String yaml, final String interfaceName, final Map<String, InputDataDefinition> expectedInputMap) {
- String fixedMainYaml = yaml;
- final String nullString = "null";
- if (fixedMainYaml.startsWith(nullString)) {
- fixedMainYaml = yaml.substring(nullString.length());
- }
- if (fixedMainYaml.endsWith(nullString)) {
- fixedMainYaml = fixedMainYaml.substring(0, fixedMainYaml.length() - nullString.length());
- }
- final Map<String, Object> yamlMap = (Map<String, Object>) new Yaml().load(fixedMainYaml);
- final Map<String, Object> nodeTypesMap = (Map<String, Object>) yamlMap.get(NODE_TYPES.getElementName());
- final Map<String, Object> node = (Map<String, Object>) nodeTypesMap.get(NODE_TYPE_NAME);
- final Map<String, Object> interfacesMap = (Map<String, Object>) node.get(INTERFACES.getElementName());
- final Map<String, Object> interface1 = (Map<String, Object>) interfacesMap.get(interfaceName);
- final Map<String, Object> actualInputsMap = (Map<String, Object>) interface1.get(INPUTS.getElementName());
- assertThat(actualInputsMap.keySet(), containsInAnyOrder(expectedInputMap.keySet().toArray()));
- expectedInputMap.forEach((inputName, inputDataDefinition) -> {
- final Map<String, Object> actualInput = (Map<String, Object>) actualInputsMap.get(inputName);
- compareInputYaml(inputName, actualInput, inputDataDefinition);
- });
- }
-
- private void compareInputYaml(final String inputName, final Map<String, Object> actualInput,
- final InputDataDefinition expectedInput) {
- final String msgFormat = "%s should be equal in input %s";
- String field = TYPE.getElementName();
- assertThat(String.format(msgFormat, field, inputName),
- actualInput.get(field), equalTo(expectedInput.getType()));
- field = DESCRIPTION.getElementName();
- assertThat(String.format(msgFormat, field, inputName),
- actualInput.get(field), equalTo(expectedInput.getDescription()));
- field = REQUIRED.getElementName();
- assertThat(String.format(msgFormat, field, inputName),
- actualInput.get(field), equalTo(expectedInput.getRequired()));
- field = DEFAULT.getElementName();
- assertThat(String.format(msgFormat, field, inputName),
- actualInput.get(field), equalTo(expectedInput.getDefaultValue()));
- }
+ Map<String, Object> interfaces = nodeType.getInterfaces();
+ assertNotNull(interfaces);
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("myInterfaceName"));
+ Object resourceName = interfaces.get("myInterfaceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(2, ((Map) resourceName).size());
- @FunctionalInterface
- interface MainYamlAssertion extends Function<String, Boolean> {}
-
- 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) {
- 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) {
- return s -> io.vavr.collection.List.of(expected).map(s::contains).fold(true, (l, r) -> l && r);
}
- private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps,
- int numOfInputsPerOp, boolean hasInputs, boolean hasOutputs) {
+ @Test
+ void interfaceWithOperationImplementationArtifactPropertiesTest() {
+ //given
+ final Component component = new Service();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ final String interfaceName = "myInterfaceName";
+ interfaceDefinition.setType("my.type." + interfaceName);
+ final var operation1DataDefinition = new OperationDataDefinition();
+ operation1DataDefinition.setName("anOperation");
+
+ final PropertyDataDefinition listOfStringProperty = new PropertyDataDefinition();
+ listOfStringProperty.setName("listProperty");
+ listOfStringProperty.setType(ToscaType.LIST.getType());
+ final PropertyDataDefinition listOfStringSchemaProperty = new PropertyDataDefinition();
+ listOfStringSchemaProperty.setType(ToscaType.STRING.getType());
+ final SchemaDefinition listPropertySchema = new SchemaDefinition();
+ listPropertySchema.setProperty(listOfStringProperty);
+ listOfStringProperty.setSchema(listPropertySchema);
+ listOfStringProperty.setValue("[ \"value1\", \"value2\", \"value3\" ]");
+ final ArrayList<Object> propertyList = new ArrayList<>();
+ propertyList.add(listOfStringProperty);
+ final HashMap<String, Object> artifactDefinitionMapInitializer = new HashMap<>();
+ artifactDefinitionMapInitializer.put(JsonPresentationFields.PROPERTIES.getPresentation(), propertyList);
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(artifactDefinitionMapInitializer);
+ artifactDataDefinition.setArtifactName("artifact1");
+ artifactDataDefinition.setArtifactType("my.artifact.Type");
+ operation1DataDefinition.setImplementation(artifactDataDefinition);
+ interfaceDefinition.setOperations(Map.of(operation1DataDefinition.getName(), operation1DataDefinition));
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceName, interfaceDefinition);
+ //when
+ Map<String, Object> interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), null, false);
+ //then
+ assertTrue(interfacesMap.containsKey(interfaceName));
+ final Map<String, Object> actualInterfaceMap = (Map<String, Object>) interfacesMap.get(interfaceName);
+ assertTrue(actualInterfaceMap.containsKey(operation1DataDefinition.getName()));
+ final Map<String, Object> actualOperationMap = (Map<String, Object>) actualInterfaceMap.get(operation1DataDefinition.getName());
+ assertTrue(actualOperationMap.containsKey("implementation"));
+ final Map<String, Object> actualImplementationMap = (Map<String, Object>) actualOperationMap.get("implementation");
+ assertTrue(actualImplementationMap.containsKey("primary"));
+ final Map<String, Object> actualArtifactImplementationMap = (Map<String, Object>) actualImplementationMap.get("primary");
+ assertTrue(actualArtifactImplementationMap.containsKey("properties"));
+ final Map<String, Object> actualArtifactPropertiesMap = (Map<String, Object>) actualArtifactImplementationMap.get("properties");
+ assertEquals(1, actualArtifactPropertiesMap.keySet().size());
+ assertTrue(actualArtifactPropertiesMap.containsKey(listOfStringProperty.getName()));
+ final Object expectedListObject = actualArtifactPropertiesMap.get(listOfStringProperty.getName());
+ assertTrue(expectedListObject instanceof List);
+ final List<String> expectedListOfStringPropValue = (List<String>) expectedListObject;
+ assertEquals(3, expectedListOfStringPropValue.size());
+ assertTrue(expectedListOfStringPropValue.contains("value1"));
+ assertTrue(expectedListOfStringPropValue.contains("value2"));
+ assertTrue(expectedListOfStringPropValue.contains("value3"));
+ }
+
+ private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp,
+ boolean hasInputs, boolean hasOutputs, boolean addAComplexType, boolean hasMilestones) {
addedInterface.setOperations(new HashMap<>());
for (int i = 0; i < numOfOps; i++) {
final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
implementation.setArtifactName(i + "_createBPMN.bpmn");
operation.setImplementation(implementation);
+ if (hasMilestones) {
+ operation.setMilestones(createMilestones());
+ }
if (hasInputs) {
- operation.setInputs(createInputs(component, numOfInputsPerOp));
+ operation.setInputs(createInputs(component, numOfInputsPerOp, addAComplexType));
}
if (hasOutputs) {
operation.setOutputs(createOutputs(addedInterface.getToscaResourceName(),
}
}
+ private Map<String, MilestoneDataDefinition> createMilestones() {
+ Map<String, MilestoneDataDefinition> toscaMilestones = new HashMap<>();
+ OperationInputDefinition input1 = new OperationInputDefinition();
+ input1.setValue("testString");
+ input1.setType("string");
+ input1.setName("stringName");
+ OperationInputDefinition input2 = createMockComplexOperationInputDefinition("complex", "complex");
+ ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ inputs.add(input1);
+ inputs.add(input2);
+ ActivityDataDefinition activity = new ActivityDataDefinition();
+ activity.setType(ActivityTypeEnum.DELEGATE.getValue());
+ activity.setWorkflow("workflow1");
+ activity.setInputs(inputs);
+ ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>();
+ activities.add(activity);
+ MilestoneDataDefinition milestone = new MilestoneDataDefinition();
+ milestone.setActivities(activities);
+ FilterDataDefinition filter1 = new FilterDataDefinition();
+ filter1.setName("my_attribute");
+ filter1.setConstraint("equal");
+ filter1.setFilterValue("my_value");
+ FilterDataDefinition filter2 = new FilterDataDefinition();
+ ToscaGetFunctionDataDefinition toscaFunction = new ToscaGetFunctionDataDefinition();
+ toscaFunction.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
+ toscaFunction.setPropertyName("role");
+ toscaFunction.setPropertySource(PropertySource.SELF);
+ toscaFunction.setSourceName("myVfc");
+ toscaFunction.setPropertyPathFromSource(Arrays.asList("role"));
+ filter2.setToscaFunction(toscaFunction);
+ filter2.setName("my_other_attribute");
+ filter2.setConstraint("equal");
+ filter2.setFilterValue("{'get_attribute':['SELF','role']}");
+ ListDataDefinition<FilterDataDefinition> filters = new ListDataDefinition<>();
+ filters.add(filter1);
+ filters.add(filter2);
+ milestone.setFilters(filters);
+ toscaMilestones.put(MilestoneTypeEnum.ON_ENTRY.getValue(), milestone);
+ return toscaMilestones;
+ }
+
private InputDataDefinition createInput(final String type, final String description, final Boolean isRequired,
final String defaultValue) {
final PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition();
return new InputDataDefinition(propertyDataDefinition);
}
- private ListDataDefinition<OperationInputDefinition> createInputs(Component component, int numOfInputs) {
+ private ListDataDefinition<OperationInputDefinition> createInputs(Component component, int numOfInputs, boolean addAComplexType) {
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ if (addAComplexType) {
+ String mappedPropertyName = java.util.UUID.randomUUID() + "." + MAPPED_PROPERTY_NAME + numOfInputs;
+ operationInputDefinitionList.add(
+ createMockComplexOperationInputDefinition(INPUT_NAME_PREFIX + "Complex" + "_" + numOfInputs, mappedPropertyName));
+ numOfInputs -= 1;
+ }
for (int i = 0; i < numOfInputs; i++) {
- String mappedPropertyName = java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME + i;
+ String mappedPropertyName = java.util.UUID.randomUUID() + "." + MAPPED_PROPERTY_NAME + i;
operationInputDefinitionList.add(createMockOperationInputDefinition(
INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, mappedPropertyName, i));
addMappedPropertyAsComponentInput(component, mappedPropertyName);
return operationInputDefinition;
}
+ private OperationInputDefinition createMockComplexOperationInputDefinition(String name, String id) {
+ OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
+ operationInputDefinition.setName(name);
+ operationInputDefinition.setInputId(id);
+ operationInputDefinition.setType("complexDataType");
+ operationInputDefinition.setRequired(false);
+ operationInputDefinition.setValue(
+ "{\"intProp\":1,\"stringProp\":{\"type\":\"GET_ATTRIBUTE\",\"propertyUniqueId\":\"ac4bc339-56d1-4ea2-9802-2da219a1247a.designer\",\"propertyName\":\"designer\",\"propertySource\":\"SELF\",\"sourceUniqueId\":\"ac4bc339-56d1-4ea2-9802-2da219a1247a\",\"sourceName\":\"service\",\"functionType\":\"GET_ATTRIBUTE\",\"propertyPathFromSource\":[\"designer\"]}}");
+ return operationInputDefinition;
+ }
+
private OperationOutputDefinition createMockOperationOutputDefinition(String interfaceName, String operationName,
String outputName, int index) {
OperationOutputDefinition operationInputDefinition = new OperationOutputDefinition();
return operationInputDefinition;
}
- 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());
- YamlToObjectConverter objectConverter = new YamlToObjectConverter();
- ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class);
- Map<String, Object> interfaces = toscaNodeType.getInterfaces();
- for (Map.Entry<String, Object> interfaceEntry : interfaces.entrySet()) {
- Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceEntry.getValue(), Map.class);
- final Map<String, Object> operationsMap = interfaceDefinition.entrySet().stream()
- .filter(entry -> !INPUTS.getElementName().equals(entry.getKey()) &&
- !TYPE.getElementName().equals(entry.getKey()))
- .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
- for (Map.Entry<String, Object> operationEntry : operationsMap.entrySet()) {
- Object operationVal = operationEntry.getValue();
- 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);
- }
- }
- }
- }
-
- private void validateOperationInputDefinition(String interfaceType, String operationName, Object operationVal) {
- Map<String, Object> operation = mapper.convertValue(operationVal, Map.class);
- Map<String, Object> inputs = (Map<String, Object>) operation.get("inputs");
- for (Map.Entry<String, Object> inputEntry : inputs.entrySet()) {
- String[] inputNameSplit = inputEntry.getKey().split("_");
- Map<String, Object> inputValueObject = (Map<String, Object>) inputEntry.getValue();
- validateOperationInputDefinitionDefaultValue(interfaceType, operationName, inputNameSplit[1],
- Integer.parseInt(inputNameSplit[2]), inputValueObject);
- }
- }
-
-
- private void validateOperationInputDefinitionDefaultValue(String interfaceType, String operationName,
- String inputType, int index,
- Map<String, Object> inputValueObject) {
- if (inputValueObject.containsKey(ToscaFunctions.GET_PROPERTY.getFunctionName())) {
- String mappedPropertyValue = MAPPED_PROPERTY_NAME + index;
- List<String> mappedPropertyDefaultValue = (List<String>) inputValueObject
- .get(ToscaFunctions.GET_PROPERTY.getFunctionName());
- assertEquals(2, mappedPropertyDefaultValue.size());
- assertTrue(mappedPropertyDefaultValue.contains(SELF));
- assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
- } else if (inputValueObject.containsKey(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
- List<String> mappedPropertyDefaultValue = (List<String>) inputValueObject
- .get(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
- assertEquals(4, mappedPropertyDefaultValue.size());
- String mappedPropertyValue = OUTPUT_NAME_PREFIX + inputType + "_" + index;
- assertTrue(mappedPropertyDefaultValue.contains(SELF));
- assertTrue(mappedPropertyDefaultValue.contains(interfaceType));
- 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());
- }
- }
-
- 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());
- YamlUtil yamlUtil = new YamlUtil();
- ToscaNodeType toscaNodeType = yamlUtil.yamlToObject(nodeTypesRepresentation, ToscaNodeType.class);
- for (Object interfaceVal : toscaNodeType.getInterfaces().values()) {
- Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceVal, Map.class);
- for (Object operationVal : interfaceDefinition.values()) {
- if (operationVal instanceof Map) {
- Map<String, Object> operation = (Map<String, Object>) mapper.convertValue(operationVal, Map.class);
- Map<String, Object> operationInputs = (Map<String, Object>) operation.get("inputs");
- for (Object inputValue : operationInputs.values()) {
- Map<String, Object> inputValueAsMap = (Map<String, Object>) inputValue;
- assertFalse(inputValueAsMap.keySet().contains("type"));
- assertFalse(inputValueAsMap.keySet().contains("required"));
- assertFalse(inputValueAsMap.keySet().contains("default"));
- }
- }
- }
- }
- }
-
@Test
void testAddInterfaceTypeElementGetCorrectLocalInterfaceName() {
Service service = new Service();
service.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("LocalInterface");
service.setInterfaces(Collections.singletonMap("Local", new InterfaceDefinition("Local", null, new HashMap<>())));
- Map<String, Object> resultMap = InterfacesOperationsConverter.addInterfaceTypeElement(service,
+ Map<String, Object> resultMap = interfacesOperationsConverter.addInterfaceTypeElement(service,
Collections.singletonList("org.openecomp.interfaces.node.lifecycle.Standard"));
assertTrue(MapUtils.isNotEmpty(resultMap)
service.setInterfaces(Collections.singletonMap("NotLocal", new InterfaceDefinition("NotLocal", null,
new HashMap<>())));
- Map<String, Object> resultMap = interfacesOperationsConverter.getInterfacesMap(service, null,
- service.getInterfaces(), null, false, false);
+ Map<String, Object> resultMap = interfacesOperationsConverter.getInterfacesMap(service, null, service.getInterfaces(), null, false);
assertTrue(MapUtils.isNotEmpty(resultMap)
&& resultMap.containsKey("NotLocal"));
}
+ @Test
+ void testGetInterfaceAsMapWithComplexType() {
+ addComplexTypeToDataTypes();
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+ addedInterface.setType("com.some.resource.or.other.resourceName");
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, true, false);
+ final String interfaceType = "normalizedComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), dataTypes, false);
+ assertNotNull(interfacesMap);
+ assertEquals(1, interfacesMap.size());
+ assertTrue(interfacesMap.containsKey("resourceName"));
+ Object resourceName = interfacesMap.get("resourceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(4, ((Map) resourceName).size());
+ assertTrue(resourceName instanceof Map);
+ Map<String, Object> resource = (Map<String, Object>) resourceName;
+ assertTrue(resource.containsKey("name_for_op_0"));
+ Map<String, Object> operation0 = (Map<String, Object>) resource.get("name_for_op_0");
+ assertTrue(operation0.containsKey("inputs"));
+ Map<String, Object> operation0Inputs = (Map<String, Object>) operation0.get("inputs");
+ assertTrue(operation0Inputs.containsKey("input_Complex_2"));
+ Map<String, Object> complexInput = (Map<String, Object>) operation0Inputs.get("input_Complex_2");
+ assertTrue(complexInput.containsKey("stringProp"));
+ Map<String, Object> complexInputStringProp = (Map<String, Object>) complexInput.get("stringProp");
+ assertTrue(complexInputStringProp.containsKey("type"));
+ assertTrue(ToscaFunctionType.findType((String) complexInputStringProp.get("type")).isPresent());
+ assertTrue(complexInputStringProp.containsKey("propertyName"));
+ assertEquals("designer", complexInputStringProp.get("propertyName"));
+ assertTrue(complexInputStringProp.containsKey("propertySource"));
+ assertEquals("SELF", complexInputStringProp.get("propertySource"));
+ }
+
+ @Test
+ void testGetInterfaceAsMapWithMilestones() {
+ addComplexTypeToDataTypes();
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+ addedInterface.setType("com.some.resource.or.other.resourceName");
+ addOperationsToInterface(component, addedInterface, 2, 0, false, false, false, true);
+ final String interfaceType = "normalizedComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), dataTypes, false);
+ assertNotNull(interfacesMap);
+ assertEquals(1, interfacesMap.size());
+ assertTrue(interfacesMap.containsKey("resourceName"));
+ Object resourceName = interfacesMap.get("resourceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
+ Map<String, Object> resource = (Map<String, Object>) resourceName;
+ assertTrue(resource.containsKey("name_for_op_0"));
+ Map<String, Object> operation0 = (Map<String, Object>) resource.get("name_for_op_0");
+ assertTrue(operation0.containsKey("milestones"));
+ Map<String, Object> operation0Milestones = (Map<String, Object>) operation0.get("milestones");
+ assertTrue(operation0Milestones.containsKey(MilestoneTypeEnum.ON_ENTRY.getValue()));
+ Map<String, Object> milestone = (Map<String, Object>) operation0Milestones.get(MilestoneTypeEnum.ON_ENTRY.getValue());
+ assertTrue(milestone.containsKey("activities"));
+ List<Map<String, Object>> activities = (List<Map<String, Object>>) milestone.get("activities");
+ assertEquals(1, activities.size());
+ Map<String, Object> activity = activities.get(0);
+ assertEquals(1, activities.size());
+ assertTrue(activity.containsKey("delegate"));
+ Map<String, Object> activityVariables = (Map<String, Object>) activity.get("delegate");
+ assertTrue(activityVariables.containsKey("workflow"));
+ assertEquals("workflow1", activityVariables.get("workflow"));
+ assertTrue(activityVariables.containsKey("inputs"));
+ assertTrue(activityVariables.get("inputs") instanceof Map);
+ Map<String, Object> inputs = (Map<String, Object>) activityVariables.get("inputs");
+ assertNotNull(inputs);
+ assertTrue(inputs.containsKey("stringName"));
+ assertTrue(inputs.get("stringName") instanceof String);
+ String input = (String) inputs.get("stringName");
+ assertEquals("testString", input);
+ assertTrue(inputs.containsKey("complex"));
+ Map<String, Object> complexInput = (Map<String, Object>) inputs.get("complex");
+ assertTrue(complexInput.containsKey("intProp"));
+ assertTrue(complexInput.get("intProp") instanceof Integer);
+ assertEquals(1, complexInput.get("intProp"));
+ assertTrue(complexInput.containsKey("stringProp"));
+ Map<String, Object> complexInputStringProp = (Map<String, Object>) complexInput.get("stringProp");
+ assertTrue(complexInputStringProp.containsKey("type"));
+ assertTrue(ToscaFunctionType.findType((String) complexInputStringProp.get("type")).isPresent());
+ assertTrue(complexInputStringProp.containsKey("propertyName"));
+ assertEquals("designer", complexInputStringProp.get("propertyName"));
+ assertTrue(complexInputStringProp.containsKey("propertySource"));
+ assertEquals("SELF", complexInputStringProp.get("propertySource"));
+
+ assertTrue(milestone.containsKey("filters"));
+ List<Map<String, Object>> filters = (List<Map<String, Object>>) milestone.get("filters");
+ assertEquals(2, filters.size());
+ Map<String, Object> filter1 = filters.get(0);
+ assertTrue(filter1.containsKey("my_attribute"));
+ Map<String, Object> filter1Constraint = (Map<String, Object>) filter1.get("my_attribute");
+ assertTrue(filter1Constraint.containsKey(ConstraintType.EQUAL.getType()));
+ String filter1Value = (String) filter1Constraint.get(ConstraintType.EQUAL.getType());
+ assertEquals("my_value", filter1Value);
+ Map<String, Object> filter2 = filters.get(1);
+ assertTrue(filter2.containsKey("my_other_attribute"));
+ Map<String, Object> filter2Constraint = (Map<String, Object>) filter2.get("my_other_attribute");
+ assertTrue(filter2Constraint.containsKey(ConstraintType.EQUAL.getType()));
+ Map<String, Object> filter2Value = (Map<String, Object>) filter2Constraint.get(ConstraintType.EQUAL.getType());
+ assertTrue(filter2Value.containsKey(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName()));
+ List<String> filter2ValueToscaFunction = (List<String>) filter2Value.get(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName());
+ assertEquals(2, filter2ValueToscaFunction.size());
+ assertEquals("SELF", filter2ValueToscaFunction.get(0));
+ assertEquals("role", filter2ValueToscaFunction.get(1));
+ }
+
+ private void addComplexTypeToDataTypes() {
+ PropertyDefinition intProp = new PropertyDefinition();
+ intProp.setType("integer");
+ intProp.setName("intProp");
+ PropertyDefinition stringProp = new PropertyDefinition();
+ stringProp.setType("string");
+ stringProp.setName("stringProp");
+ DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName("complexDataType");
+ dataType.setProperties(new ArrayList<>(Arrays.asList(stringProp, intProp)));
+ dataTypes.put("complexDataType", dataType);
+ }
+
@Test
void testRemoveInterfacesWithoutOperationsEmptyMap() {
final Map<String, Object> interfaceMap = new HashMap<>();
interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap);
- assertThat(interfaceMap, is(anEmptyMap()));
+ assertNotNull(interfaceMap);
+ assertTrue(interfaceMap.isEmpty());
}
@Test
void testRemoveInterfacesWithoutOperationsNullParameter() {
final Map<String, Object> interfaceMap = null;
interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap);
- assertThat(interfaceMap, is(nullValue()));
+ assertNull(interfaceMap);
}
@Test