summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-07-07 13:57:03 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-13 11:23:36 +0000
commit2b1ecc236c86ba71ea749f1c127e29a9abe8cabe (patch)
tree1dec6cf08aa9f45d54e8860fad8d8a6cd982f615 /catalog-be/src/test/java
parent578e7acb26fe807e593cbbdb9bbad51a0ffff277 (diff)
Service Import - Input appearing as a property
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I33fa543e3a1c40b7590334a6396634abbd5b536f Issue-ID: SDC-4079
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java223
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java197
2 files changed, 138 insertions, 282 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index e3e4590d0f..caae11bdee 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -20,19 +20,15 @@
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.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;
@@ -78,7 +74,6 @@ 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;
@@ -105,8 +100,7 @@ class InterfacesOperationsConverterTest {
@BeforeEach
public void setUpBeforeTest() {
- interfacesOperationsConverter =
- new InterfacesOperationsConverter(new PropertyConvertor());
+ interfacesOperationsConverter = new InterfacesOperationsConverter(new PropertyConvertor());
}
@Test
@@ -122,19 +116,14 @@ class InterfacesOperationsConverterTest {
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
- final Map<String, Object> interfaceTypeElement =
- addInterfaceTypeElement(component, new ArrayList<>());
+ 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());
- 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())));
}
@Test
@@ -150,19 +139,14 @@ class InterfacesOperationsConverterTest {
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);
+ 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());
- assertTrue(all(
- containsAll("NodeTypeName"),
- containsNone("operations")
- ).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
@@ -178,22 +162,15 @@ class InterfacesOperationsConverterTest {
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
@@ -208,19 +185,15 @@ class InterfacesOperationsConverterTest {
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, null, 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);
}
@@ -235,23 +208,15 @@ class InterfacesOperationsConverterTest {
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(null, null, null, null, null, null, null, null, null, null, null, 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));
- validateServiceProxyOperationInputs(mainYaml);
+ final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), null, false, true);
+ 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
@@ -266,19 +231,15 @@ class InterfacesOperationsConverterTest {
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
@@ -300,20 +261,15 @@ class InterfacesOperationsConverterTest {
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
@@ -323,6 +279,7 @@ class InterfacesOperationsConverterTest {
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType(addedInterfaceType);
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addOperationsToInterface(component, addedInterface, 2, 2, true, true);
addedInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
@@ -335,6 +292,7 @@ class InterfacesOperationsConverterTest {
String secondInterfaceType = "org.test.lifecycle.standard.interfaceType.second";
InterfaceDefinition secondInterface = new InterfaceDefinition();
secondInterface.setType(secondInterfaceType);
+ secondInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addOperationsToInterface(component, secondInterface, 2, 2, true, true);
secondInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
@@ -349,21 +307,21 @@ class InterfacesOperationsConverterTest {
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());
- 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(interfaces.containsKey("second"));
+ resourceName = interfaces.get("second");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
- String mainYaml = new String(toscaRepresentation.getMainYaml());
- assertTrue(all(
- containsAll("resourceNameInputMappedToOutput:", "inputs:"),
- containsNone("operations")
- ).apply(mainYaml));
- validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
@Test
@@ -385,17 +343,15 @@ class InterfacesOperationsConverterTest {
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);
+ 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());
+
}
@Test
@@ -442,12 +398,12 @@ class InterfacesOperationsConverterTest {
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(actualArtifactPropertiesMap.keySet().size(), 1);
+ 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(expectedListOfStringPropValue.size(), 3);
+ assertEquals(3, expectedListOfStringPropValue.size());
assertTrue(expectedListOfStringPropValue.contains("value1"));
assertTrue(expectedListOfStringPropValue.contains("value2"));
assertTrue(expectedListOfStringPropValue.contains("value3"));
@@ -494,7 +450,9 @@ class InterfacesOperationsConverterTest {
}
@FunctionalInterface
- interface MainYamlAssertion extends Function<String, Boolean> {}
+ 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);
@@ -706,7 +664,7 @@ class InterfacesOperationsConverterTest {
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)
@@ -732,14 +690,15 @@ class InterfacesOperationsConverterTest {
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
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index 6a3810f102..040907b3f0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -49,7 +49,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.stream.Collectors;
import mockit.Deencapsulation;
import org.apache.commons.collections.MapUtils;
@@ -63,8 +62,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
@@ -87,6 +84,7 @@ import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupInstance;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipInfo;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
@@ -117,10 +115,12 @@ class ToscaExportHandlerTest extends BaseConfDependent {
private static final String COMPONENT_PROPERTY_NAME = "prop1";
private static final String COMPONENT_PROPERTY_TYPE = "string";
private static final String COMPONENT_INPUT_NAME = "input1";
+ private static final String COMPONENT_OUTPUT_NAME = "output1";
private static final String COMPONENT_INPUT_TYPE = "integer";
+ private static final String COMPONENT_OUTPUT_TYPE = "integer";
private static final String RESOURCE_NAME = "resource";
private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
- private static final Map<String, DataTypeDefinition> DATA_TYPES = new HashMap<>();
+ private static final String LOCAL_INTERFACE_TYPE = "Local";
@InjectMocks
private ToscaExportHandler testSubject;
@@ -178,6 +178,7 @@ class ToscaExportHandlerTest extends BaseConfDependent {
private Resource getNewResource() {
Resource resource = new Resource();
+ resource.setUniqueId("resourceUniqueId");
List<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition category = new CategoryDefinition();
List<SubCategoryDefinition> subcategories = new ArrayList<>();
@@ -203,6 +204,13 @@ class ToscaExportHandlerTest extends BaseConfDependent {
category.setSubcategories(subcategories);
categories.add(category);
+ final List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(new PropertyDefinition());
+ resource.setProperties(properties);
+ Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
+ proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
+ resource.setInterfaces(proxyInterfaces);
+
resource.setCategories(categories);
resource.setVersion("version");
resource.setVendorName("vendorName");
@@ -307,32 +315,24 @@ class ToscaExportHandlerTest extends BaseConfDependent {
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class),
any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
- Either<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation
- .invoke(testSubject, "convertInterfaceNodeType", new HashMap<String, Component>(), component,
- new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
+ final var result = testSubject.convertInterfaceNodeType(new HashMap<String, Component>(), component,
+ new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
assertNotNull(result);
assertTrue(result.isLeft());
Map<String, ToscaNodeType> nodeTypeMap = result.left().value().getNode_types();
- assertEquals(1,nodeTypeMap.size());
+ assertNotNull(nodeTypeMap);
+ assertEquals(1, nodeTypeMap.size());
ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next();
+ assertNotNull(toscaNodeType);
Map<String, ToscaProperty> propertyMap = toscaNodeType.getProperties();
// Check if inputs and properties in component are merged properly
- assertEquals(2, propertyMap.size());
- assertTrue(propertyMap.containsKey(COMPONENT_INPUT_NAME));
+ assertNotNull(propertyMap);
+ assertEquals(1, propertyMap.size());
+ assertFalse(propertyMap.containsKey(COMPONENT_INPUT_NAME));
assertTrue(propertyMap.containsKey(COMPONENT_PROPERTY_NAME));
}
@Test
- void testCreateToscaRepresentation() {
- ToscaTemplate toscaTemplate = new ToscaTemplate("");
- ToscaRepresentation result;
-
- // default test
- result = testSubject.createToscaRepresentation(toscaTemplate);
- assertNotNull(result);
- }
-
- @Test
void testGetDependencies() {
Component component = new Resource();
@@ -411,7 +411,6 @@ class ToscaExportHandlerTest extends BaseConfDependent {
void testConvertToscaTemplateWhenComponentContainsGroup() throws ToscaConversionException {
Component component = getNewResource();
ToscaTemplate toscaNode = new ToscaTemplate("");
- Either<ToscaTemplate, ToscaError> result;
component.setComponentInstances(new ArrayList<>());
List<GroupDefinition> groups = new ArrayList<>();
@@ -423,6 +422,16 @@ class ToscaExportHandlerTest extends BaseConfDependent {
groups.add(group);
component.setGroups(groups);
+ final var input = new InputDefinition();
+ input.setName(COMPONENT_INPUT_NAME);
+ input.setType(COMPONENT_INPUT_TYPE);
+ component.setInputs(Collections.singletonList(input));
+
+ final var output = new OutputDefinition();
+ output.setName(COMPONENT_OUTPUT_NAME);
+ output.setType(COMPONENT_OUTPUT_TYPE);
+ component.setOutputs(Collections.singletonList(output));
+
Map<String, String[]> substitutionMappingMap = new HashMap<>();
String[] array = {"value1", "value2"};
substitutionMappingMap.put("key", array);
@@ -444,7 +453,7 @@ class ToscaExportHandlerTest extends BaseConfDependent {
doReturn(map).when(outputConverter).convert(any(), any());
// test component contains group
- result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
+ final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
assertNotNull(result);
}
@@ -738,7 +747,7 @@ class ToscaExportHandlerTest extends BaseConfDependent {
when(toscaOperationFacade.getToscaFullElement("uid")).thenReturn(Either.left(component));
when(toscaOperationFacade.getToscaFullElement("sourceModelUid")).thenReturn(Either.left(component));
when(toscaOperationFacade.getLatestByName("serviceProxy", null)).thenReturn(Either.left(new Resource()));
- when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(getNewResource()));
final Map<String, String[]> substitutionMappingMap = new HashMap<>();
final String[] array = {"value1", "value2"};
@@ -862,7 +871,14 @@ class ToscaExportHandlerTest extends BaseConfDependent {
when(toscaOperationFacade.getToscaFullElement("uid")).thenReturn(Either.left(component));
when(toscaOperationFacade.getToscaFullElement("sourceModelUid")).thenReturn(Either.left(component));
when(toscaOperationFacade.getLatestByName("serviceProxy", null)).thenReturn(Either.left(new Resource()));
- when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
+
+ Resource newResource = getNewResource();
+ InputDefinition input = new InputDefinition();
+ input.setName(COMPONENT_INPUT_NAME);
+ input.setType(COMPONENT_INPUT_TYPE);
+ newResource.setInputs(Collections.singletonList(input));
+
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(newResource));
final Map<String, String[]> substitutionMappingMap = new HashMap<>();
final String[] array = {"value1", "value2"};
@@ -875,7 +891,7 @@ class ToscaExportHandlerTest extends BaseConfDependent {
.thenReturn(Either.left(Collections.emptyMap()));
// default test
- final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(newResource);
assertNotNull(toscaRepresentationToscaErrorEither);
}
@@ -1107,16 +1123,15 @@ class ToscaExportHandlerTest extends BaseConfDependent {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
Component proxyResource = new Resource();
Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
proxyResource.setInterfaces(proxyInterfaces);
- when(toscaOperationFacade.getToscaElement(any(String.class),
- any(ComponentParametersView.class)))
- .thenReturn(Either.left(proxyResource));
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(proxyResource));
+ when(interfacesOperationsConverter.addInterfaceTypeElement(any(Component.class), anyList()))
+ .thenReturn(Collections.singletonMap(LOCAL_INTERFACE_TYPE, new HashMap<>()));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
assertNotNull(result);
@@ -1562,7 +1577,7 @@ class ToscaExportHandlerTest extends BaseConfDependent {
when(capabilityRequirementConverter.buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("cap"), any(), any()))
.thenReturn(Either.left(builtCapabilityOrRequirementName));
when(capabilityRequirementConverter.buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("req"), any(), any()))
- .thenReturn(Either.left(builtCapabilityOrRequirementName));
+ .thenReturn(Either.left(builtCapabilityOrRequirementName));
final Map<String, ToscaTemplateRequirement> requirementMap = Deencapsulation
.invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement,
@@ -1683,127 +1698,9 @@ class ToscaExportHandlerTest extends BaseConfDependent {
assertEquals("test_type", result.get("test_art").getType());
}
- @Test
- void testGetProxyNodeTypeInterfacesNoInterfaces() {
- Component service = new Service();
- Optional<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- assertFalse(proxyNodeTypeInterfaces.isPresent());
- }
-
- @Test
- void testGetProxyNodeTypeInterfaces() {
- Component service = getTestComponent();
- Optional<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- assertTrue(proxyNodeTypeInterfaces.isPresent());
- Map<String, Object> componentInterfaces = proxyNodeTypeInterfaces.get();
- assertNotNull(componentInterfaces);
- }
-
-
- @Test
- void testGetProxyNodeTypePropertiesComponentNull() {
- Optional<Map<String, ToscaProperty>> proxyNodeTypeProperties =
- testSubject.getProxyNodeTypeProperties(null, DATA_TYPES);
- assertFalse(proxyNodeTypeProperties.isPresent());
- }
-
- @Test
- void testGetProxyNodeTypePropertiesNoProperties() {
- Component service = new Service();
- Optional<Map<String, ToscaProperty>> proxyNodeTypeProperties =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
- assertFalse(proxyNodeTypeProperties.isPresent());
- }
-
- @Test
- void testGetProxyNodeTypeProperties() {
- Component service = getTestComponent();
- service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"),
- createMockProperty("componentPropInt", null)));
- Optional<Map<String, ToscaProperty>> proxyNodeTypeProperties =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
- assertTrue(proxyNodeTypeProperties.isPresent());
- Map<String, ToscaProperty> componentProperties = proxyNodeTypeProperties.get();
- assertNotNull(componentProperties);
- assertEquals(2, componentProperties.size());
- }
-
- @Test
- void testAddInputsToPropertiesNoInputs() {
- Component service = getTestComponent();
- service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"),
- createMockProperty("componentPropInt", null)));
- Optional<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get();
- testSubject.addInputsToProperties(DATA_TYPES, null, proxyNodeTypeProperties);
- assertNotNull(proxyNodeTypeProperties);
- assertEquals(2, proxyNodeTypeProperties.size());
- testSubject.addInputsToProperties(DATA_TYPES, new ArrayList<>(), proxyNodeTypeProperties);
- assertEquals(2, proxyNodeTypeProperties.size());
- }
-
- @Test
- void testAddInputsToPropertiesWithInputs() {
- Component service = getTestComponent();
- service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"),
- createMockProperty("componentPropInt", null)));
- service.setInputs(Arrays.asList(createMockInput("componentInputStr1",
- "Default String Input1"), createMockInput("componentInputStr2", "Default String Input2")));
- Optional<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get();
- testSubject.addInputsToProperties(DATA_TYPES, service.getInputs(), proxyNodeTypeProperties);
- assertNotNull(proxyNodeTypeProperties);
- assertEquals(4, proxyNodeTypeProperties.size());
- }
-
- @Test
- void testAddInputsToPropertiesOnlyInputs() {
- Component service = getTestComponent();
- service.setInputs(Arrays.asList(createMockInput("componentInputStr1",
- "Default String Input1"), createMockInput("componentInputStr2", "Default String Input2")));
- Optional<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get();
- testSubject.addInputsToProperties(DATA_TYPES, service.getInputs(), proxyNodeTypeProperties);
- assertNotNull(proxyNodeTypeProperties);
- assertEquals(2, proxyNodeTypeProperties.size());
- }
-
- @Test
- void testOperationImplementationInProxyNodeTypeNotPresent() {
- Component service = getTestComponent();
- InterfaceDefinition interfaceDefinition =
- service.getInterfaces().get("normalizedServiceComponentName-interface");
- interfaceDefinition.setOperations(new HashMap<>());
- final OperationDataDefinition operation = new OperationDataDefinition();
- operation.setName("start");
- operation.setDescription("op description");
- final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- implementation.setArtifactName("createBPMN.bpmn");
- operation.setImplementation(implementation);
- interfaceDefinition.getOperations().put(operation.getName(), operation);
- service.getInterfaces().put("normalizedServiceComponentName-interface", interfaceDefinition);
- service.setInputs(Arrays.asList(createMockInput("componentInputStr1",
- "Default String Input1"), createMockInput("componentInputStr2", "Default String Input2")));
- Optional<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- assertTrue(proxyNodeTypeInterfaces.isPresent());
- Map<String, Object> componentInterfaces = proxyNodeTypeInterfaces.get();
- assertNotNull(componentInterfaces);
- }
-
private Component getTestComponent() {
Component component = new Service();
+ component.setUniqueId("serviceUniqueId");
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.service.or.other.serviceName");