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;
@BeforeEach
public void setUpBeforeTest() {
interfacesOperationsConverter =
- new InterfacesOperationsConverter(new PropertyConvertor());
+ new InterfacesOperationsConverter(new PropertyConvertor());
}
@Test
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);
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);
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);
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);
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();
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);
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);
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);
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);
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<>();
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);
}
@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);
}
}
if (hasOutputs) {
operation.setOutputs(createOutputs(addedInterface.getToscaResourceName(),
- operation.getName(), numOfInputsPerOp));
+ operation.getName(), numOfInputsPerOp));
}
addedInterface.getOperations().put(operation.getName(), operation);
}
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);
}
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;
}
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();
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);
}
}
}
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);
}
}
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()) {
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
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