X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Ftosca%2FToscaExportHandlerTest.java;h=0b3796261a12144a2dd7039d66a449b474ccbd47;hb=28e1a54e6074f50dcc06f7ea4eb3943ad873b448;hp=325a0031337f2257758cc63f9564bdd3b4ffb0c7;hpb=df1e300dad94d65a88d2012df9096961619d8272;p=sdc.git 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 325a003133..0b3796261a 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 @@ -22,13 +22,12 @@ package org.openecomp.sdc.be.tosca; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyList; @@ -51,27 +50,28 @@ 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; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Triple; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openecomp.sdc.be.components.BeConfDependentTest; 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.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.exception.ToscaExportException; @@ -90,7 +90,9 @@ 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.RelationshipImpl; import org.openecomp.sdc.be.model.RelationshipInfo; import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; @@ -103,7 +105,6 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.tosca.exception.ToscaConversionException; -import org.openecomp.sdc.be.tosca.model.SubstitutionMapping; import org.openecomp.sdc.be.tosca.model.ToscaCapability; import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; @@ -114,16 +115,20 @@ import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement; import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate; import org.openecomp.sdc.be.tosca.utils.InputConverter; import org.openecomp.sdc.be.tosca.utils.OutputConverter; +import org.openecomp.sdc.common.test.BaseConfDependent; -public class ToscaExportHandlerTest extends BeConfDependentTest { +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 DATA_TYPES = new HashMap<>(); + private static final String LOCAL_INTERFACE_TYPE = "Local"; + private static final String UNIQUE_ID = "1L"; @InjectMocks private ToscaExportHandler testSubject; @@ -164,16 +169,24 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { @Mock private AttributeConverter attributeConverter; - @Before - public void setUpMock() { - MockitoAnnotations.initMocks(this); + @BeforeAll + public static void setupBeforeClass() { + componentName = "catalog-be"; + confPath = "src/test/resources/config"; + setUp(); + } + + @BeforeEach + void setUpMock() { + MockitoAnnotations.openMocks(this); doReturn(new ToscaProperty()).when(propertyConvertor).convertProperty(any(), any(), eq(PROPERTY)); doReturn(new HashMap()).when(interfacesOperationsConverter) - .getInterfacesMap(any(), isNull(), anyMap(), anyMap(), anyBoolean(), anyBoolean()); + .getInterfacesMap(any(), isNull(), anyMap(), anyMap(), anyBoolean()); } private Resource getNewResource() { Resource resource = new Resource(); + resource.setUniqueId("resourceUniqueId"); List categories = new ArrayList<>(); CategoryDefinition category = new CategoryDefinition(); List subcategories = new ArrayList<>(); @@ -183,13 +196,13 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { dataType.setName("dataTypeName"); dataType.setDerivedFromName("tosca.datatypes.Root"); PropertyDataDefinition propData = new PropertyDataDefinitionBuilder() - .setName("property") - .setType("type") - .build(); + .setName("property") + .setType("type") + .build(); List propDataList = Arrays.asList(propData); dataType.setPropertiesData(propDataList); List propList = propDataList.stream().map(PropertyDefinition::new) - .collect(Collectors.toList()); + .collect(Collectors.toList()); dataType.setProperties(propList); dataTypes.add(dataType); @@ -199,6 +212,13 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { category.setSubcategories(subcategories); categories.add(category); + final List properties = new ArrayList<>(); + properties.add(new PropertyDefinition()); + resource.setProperties(properties); + Map proxyInterfaces = new HashMap<>(); + proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>())); + resource.setInterfaces(proxyInterfaces); + resource.setCategories(categories); resource.setVersion("version"); resource.setVendorName("vendorName"); @@ -232,55 +252,65 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testExportComponent() throws Exception { + void testExportComponent() { Component component = getNewResource(); Either result; when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); // default test when component is Resource result = testSubject.exportComponent(component); - Assert.assertNotNull(result); + assertNotNull(result); component = getNewService(); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); // default test when component is Service result = testSubject.exportComponent(component); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testExportComponentInterface() throws Exception { - Component component = getNewResource(); + void testExportComponentInterface() { + Resource component = getNewResource(); Either result; - ((Resource) component).setInterfaces(new HashMap<>()); + component.setInterfaces(new HashMap<>()); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); // default test when convertInterfaceNodeType is right result = testSubject.exportComponentInterface(component, false); - Assert.assertNotNull(result); + assertNotNull(result); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test when convertInterfaceNodeType is left result = testSubject.exportComponentInterface(component, false); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testConvertInterfaceNodeTypeProperties() throws Exception { + void testExportDataType() { + DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(); + dataTypeDefinition.setUniqueId("uniqueId"); + Either result; + when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); + result = testSubject.exportDataType(dataTypeDefinition); + assertNotNull(result); + } + + @Test + void testConvertInterfaceNodeTypeProperties() { Resource component = getNewResource(); @@ -297,61 +327,52 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setToscaResourceName(RESOURCE_NAME); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); // when convertRequirements is called, make it return the same value as 3rd (index=2) argument. - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2))); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2))); - Either result = (Either) Deencapsulation - .invoke(testSubject, "convertInterfaceNodeType", new HashMap(), component, + final var result = testSubject.convertInterfaceNodeType(new HashMap(), component, new ToscaTemplate(TOSCA_VERSION), new HashMap(), false); - Assert.assertNotNull(result); - assertThat(result.isLeft(), is(true)); + assertNotNull(result); + assertTrue(result.isLeft()); Map nodeTypeMap = result.left().value().getNode_types(); - assertThat(nodeTypeMap.size(), is(1)); + assertNotNull(nodeTypeMap); + assertEquals(1, nodeTypeMap.size()); ToscaNodeType toscaNodeType = nodeTypeMap.values().iterator().next(); + assertNotNull(toscaNodeType); Map propertyMap = toscaNodeType.getProperties(); // Check if inputs and properties in component are merged properly - assertThat(propertyMap.size(), is(2)); - assertThat(propertyMap.containsKey(COMPONENT_INPUT_NAME), is(true)); - assertThat(propertyMap.containsKey(COMPONENT_PROPERTY_NAME), is(true)); - } - - @Test - public void testCreateToscaRepresentation() throws Exception { - ToscaTemplate toscaTemplate = new ToscaTemplate(""); - ToscaRepresentation result; - - // default test - result = testSubject.createToscaRepresentation(toscaTemplate); - Assert.assertNotNull(result); + assertNotNull(propertyMap); + assertEquals(1, propertyMap.size()); + assertFalse(propertyMap.containsKey(COMPONENT_INPUT_NAME)); + assertTrue(propertyMap.containsKey(COMPONENT_PROPERTY_NAME)); } @Test - public void testGetDependencies() throws Exception { + void testGetDependencies() { Component component = new Resource(); Either result; // default test result = testSubject.getDependencies(component); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testSetImports() throws Exception { + void testSetImports() { Resource resource = new Resource(); resource.setResourceType(ResourceTypeEnum.PNF); - Component component = resource; - component.setName("TestResourceName"); + resource.setName("TestResourceName"); Map artifactList = new HashMap<>(); ArtifactDefinition artifact = new ArtifactDefinition(); artifact.setArtifactName("name.name2"); artifactList.put("assettoscatemplate", artifact); - component.setArtifacts(artifactList); - component.setToscaArtifacts(artifactList); + resource.setArtifacts(artifactList); + resource.setToscaArtifacts(artifactList); ToscaTemplate toscaTemplate = new ToscaTemplate(""); ComponentInstance ci = new ComponentInstance(); @@ -360,25 +381,25 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { ci.setSourceModelUid("modelName"); List componentInstanceList = new LinkedList<>(); componentInstanceList.add(ci); - component.setComponentInstances(componentInstanceList); + resource.setComponentInstances(componentInstanceList); - when(toscaOperationFacade.getToscaFullElement("name")).thenReturn(Either.left(component)); + when(toscaOperationFacade.getToscaFullElement("name")).thenReturn(Either.left(resource)); Either>, ToscaError> result; - result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate); + result = Deencapsulation.invoke(testSubject, "fillImports", resource, toscaTemplate, false); verify(toscaOperationFacade, times(1)).getToscaFullElement("name"); - Assert.assertTrue(result.isLeft()); + assertTrue(result.isLeft()); ToscaTemplate toscaTemplateRes = result.left().value().left; - Assert.assertEquals(8, toscaTemplateRes.getImports().size()); - Assert.assertNotNull(toscaTemplateRes.getImports().get(6).get("resource-TestResourceName-interface")); - Assert.assertNotNull(toscaTemplateRes.getImports().get(7).get("resource-TestResourceName")); - Assert.assertEquals(1, toscaTemplateRes.getDependencies().size()); - Assert.assertEquals("name.name2", toscaTemplateRes.getDependencies().get(0).getLeft()); + assertEquals(8, toscaTemplateRes.getImports().size()); + assertNotNull(toscaTemplateRes.getImports().get(6).get("resource-TestResourceName-interface")); + assertNotNull(toscaTemplateRes.getImports().get(7).get("resource-TestResourceName")); + assertEquals(1, toscaTemplateRes.getDependencies().size()); + assertEquals("name.name2", toscaTemplateRes.getDependencies().get(0).getLeft()); } @Test - public void testConvertToscaTemplate() throws Exception { + void testConvertToscaTemplate() throws Exception { final Component component = getNewResource(); final ToscaTemplate toscaNode = new ToscaTemplate(""); @@ -393,22 +414,21 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setComponentInstances(resourceInstances); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.right(false)); final Map map = new HashMap<>(); map.put("mock", new ToscaProperty()); doReturn(map).when(outputConverter).convert(any(), any()); // default test - result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); - Assert.assertNotNull(result); + result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); + assertNotNull(result); } @Test - public void testConvertToscaTemplateWhenComponentContainsGroup() throws ToscaConversionException { + void testConvertToscaTemplateWhenComponentContainsGroup() throws ToscaConversionException { Component component = getNewResource(); ToscaTemplate toscaNode = new ToscaTemplate(""); - Either result; component.setComponentInstances(new ArrayList<>()); List groups = new ArrayList<>(); @@ -420,20 +440,29 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { 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 substitutionMappingMap = new HashMap<>(); String[] array = {"value1", "value2"}; substitutionMappingMap.put("key", array); - when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(any(Map.class), - any(Component.class))).thenReturn(Either.left(substitutionMappingMap)); + when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), + any(Component.class))).thenReturn(Either.left(substitutionMappingMap)); - when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Map.class), - any(Component.class), any(SubstitutionMapping.class))) - .thenReturn(Either.left(new SubstitutionMapping())); + when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Component.class), anyMap())) + .thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(inputConverter.convertInputs(any(List.class), any(Map.class))).thenReturn(new HashMap<>()); + when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>()); when(groupExportParser.getGroups(component)).thenReturn(null); @@ -442,12 +471,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { doReturn(map).when(outputConverter).convert(any(), any()); // test component contains group - result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); - Assert.assertNotNull(result); + final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); + assertNotNull(result); } @Test - public void testConvertToscaTemplateWhenComponentIsService() throws Exception { + void testConvertToscaTemplateWhenComponentIsService() throws Exception { Component component = getNewService(); ToscaTemplate toscaNode = new ToscaTemplate(""); Either result; @@ -467,11 +496,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { substitutionMappingMap.put("key", array); when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class))) - .thenReturn(Either.left(substitutionMappingMap)); + .thenReturn(Either.left(substitutionMappingMap)); when(capabilityRequirementConverter - .convertSubstitutionMappingRequirements(anyMap(), any(Component.class), any(SubstitutionMapping.class))) - .thenReturn(Either.left(new SubstitutionMapping())); + .convertSubstitutionMappingRequirements(any(Component.class), anyMap())) + .thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); @@ -481,12 +510,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { doReturn(map).when(outputConverter).convert(any(), any()); // test component contains group - result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); - Assert.assertNotNull(result); + result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); + assertNotNull(result); } @Test - public void testConvertMetadata_1() throws Exception { + void testConvertMetadata_1() { Component component = getNewResource(); boolean isInstance = true; @@ -496,11 +525,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // default test Map result = Deencapsulation.invoke(testSubject, "convertMetadata", component, isInstance, componentInstance); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testFillImports() throws Exception { + void testFillImports() { Component component = getNewService(); ToscaTemplate toscaTemplate = new ToscaTemplate(""); @@ -518,7 +547,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { component.setToscaArtifacts(toscaArtifacts); when(toscaOperationFacade.getToscaFullElement(any(String.class))) - .thenReturn(Either.left(component)); + .thenReturn(Either.left(component)); Resource baseType = getNewResource(); Map baseTypeToscaArtifacts = new HashMap<>(); @@ -532,12 +561,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0", null)).thenReturn(Either.left(baseType)); // default test - result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate); - Assert.assertNotNull(result); + result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate, false); + assertNotNull(result); } @Test - public void testCreateDependency() throws Exception { + void testCreateDependency() { Map componentCache = new HashMap<>(); List>> imports = new ArrayList<>(); @@ -559,22 +588,22 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(toscaOperationFacade.getToscaFullElement("modelName")).thenReturn(Either.left(new Service())); // default test - Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci); - Assert.assertFalse(componentCache.isEmpty()); + Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci, false); + assertFalse(componentCache.isEmpty()); } @Test - public void testGetInterfaceFilename() throws Exception { + void testGetInterfaceFilename() { String artifactName = "artifact.name"; String result; // default test result = ToscaExportHandler.getInterfaceFilename(artifactName); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testConvertNodeType() throws Exception { + void testConvertNodeType() { Component component = new Resource(); ToscaTemplate toscaNode = new ToscaTemplate(""); Map nodeTypes = new HashMap<>(); @@ -582,15 +611,15 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); // default test result = Deencapsulation - .invoke(testSubject, "convertNodeType", new HashMap<>(), component, toscaNode, nodeTypes); - Assert.assertNotNull(result); + .invoke(testSubject, "convertNodeType", new HashMap<>(), component, toscaNode, nodeTypes); + assertNotNull(result); } @Test - public void testConvertInterfaceNodeType() throws Exception { + void testConvertInterfaceNodeType() { Component component = getNewResource(); ToscaTemplate toscaNode = new ToscaTemplate(""); Map nodeTypes = new HashMap<>(); @@ -601,54 +630,54 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType", new HashMap<>(), component, toscaNode - , nodeTypes, false); - Assert.assertNotNull(result); + , nodeTypes, false); + assertNotNull(result); } @Test - public void testConvertReqCapAndTypeName() throws Exception { + void testConvertReqCapAndTypeName() { Component component = new Resource(); ToscaTemplate toscaNode = new ToscaTemplate(""); - Map nodeTypes = new HashMap(); + Map nodeTypes = new HashMap<>(); ToscaNodeType toscaNodeType = new ToscaNodeType(); Map dataTypes = new HashMap<>(); Either result; when( - capabilityRequirementConverter - .convertCapabilities(any(Map.class), any(Resource.class), any(Map.class))) - .thenReturn(new HashMap<>()); + capabilityRequirementConverter + .convertCapabilities(anyMap(), any(Resource.class), anyMap())) + .thenReturn(new HashMap<>()); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test result = Deencapsulation - .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes, - toscaNodeType, dataTypes); - Assert.assertNotNull(result); + .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes, + toscaNodeType, dataTypes); + assertNotNull(result); component = new Service(); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // test when component is service result = Deencapsulation - .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes, - toscaNodeType, dataTypes); - Assert.assertNotNull(result); + .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes, + toscaNodeType, dataTypes); + assertNotNull(result); } @Test - public void testConvertNodeTemplatesWhenComponentIsService() throws Exception { + void testConvertNodeTemplatesWhenComponentIsService() { final Component component = getNewService(); final List componentInstances = new ArrayList<>(); final Map> componentInstancesProperties = new HashMap<>(); @@ -725,18 +754,139 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentInstancesProperties.put("id", list); component.setComponentInstancesProperties(componentInstancesProperties); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component)); + when(capabilityRequirementConverter + .convertComponentInstanceCapabilities(any(ComponentInstance.class), anyMap(), any(ToscaNodeTemplate.class))) + .thenReturn(Either.left(new ToscaNodeTemplate())); + when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); + when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), any(ToscaNodeType.class))) + .thenReturn(Either.left(new ToscaNodeType())); + 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(getNewResource())); + + final Map substitutionMappingMap = new HashMap<>(); + final String[] array = {"value1", "value2"}; + substitutionMappingMap.put("key", array); + when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class))) + .thenReturn(Either.left(substitutionMappingMap)); + + when(capabilityRequirementConverter + .convertSubstitutionMappingRequirements(any(Component.class), anyMap())) + .thenReturn(Either.left(Collections.emptyMap())); + + // default test + final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(component); + assertNotNull(toscaRepresentationToscaErrorEither); + + } + + @Test + void testConvertWithBooleanNodeFilterWhenComponentIsService() { + final Component component = getNewService(); + final List componentInstances = new ArrayList<>(); + final Map> componentInstancesProperties = new HashMap<>(); + final Map componentCache = new HashMap<>(); + final Map> componentInstancesInputs = new HashMap<>(); + final Map componentInstanceNodeFilters = new HashMap<>(); + CINodeFilterDataDefinition nodeFilter = new CINodeFilterDataDefinition(); + PropertyFilterDataDefinition prop = new PropertyFilterDataDefinition(); + prop.setName("nodeFilterPropBoolean"); + prop.setType("boolean"); + PropertyFilterConstraintDataDefinition constr = new PropertyFilterConstraintDataDefinition(); + constr.setPropertyName(prop.getName()); + constr.setOperator(ConstraintType.EQUAL); + constr.setValue("true"); + constr.setOriginalType("boolean"); + prop.setConstraints(List.of(constr)); + ListDataDefinition lstDataDef = new ListDataDefinition<>(); + lstDataDef.add(prop); + nodeFilter.setProperties(lstDataDef); + final List inputs = new ArrayList<>(); + final ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput(); + componentInstanceInput.setUniqueId("uuid"); + inputs.add(componentInstanceInput); + componentInstancesInputs.put("uuid", inputs); + componentInstanceNodeFilters.put("uuid", nodeFilter); + final List resourceInstancesRelations = new ArrayList<>(); + final RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef(); + reldef.setFromNode("node"); + resourceInstancesRelations.add(reldef); + component.setComponentInstancesRelations(resourceInstancesRelations); + + final ComponentInstance instance = new ComponentInstance(); + instance.setNodeFilter(nodeFilter); + instance.setUniqueId("id"); + instance.setComponentUid("uid"); + instance.setOriginType(OriginTypeEnum.ServiceProxy); + final List groupInstances = new ArrayList<>(); + final GroupInstance groupInst = new GroupInstance(); + final List artifacts = new ArrayList<>(); + artifacts.add("artifact"); + groupInst.setArtifacts(artifacts); + groupInst.setType("type"); + groupInstances.add(groupInst); + instance.setGroupInstances(groupInstances); + + final List properties = new ArrayList<>(); + properties.add(new PropertyDefinition()); + instance.setProperties(properties); + + instance.setUniqueId("uuid"); + instance.setDescription("desc"); + instance.setSourceModelUid("sourceModelUid"); + + componentInstances.add(instance); + + component.setComponentInstances(componentInstances); + component.setNodeFilterComponents(componentInstanceNodeFilters); + component.setComponentInstancesInputs(componentInstancesInputs); + + component.setInvariantUUID("uuid"); + component.setUUID("uuid"); + component.setDescription("desc"); + component.setUniqueId("uid"); + + componentCache.put("uid", component); + + final List componentInstanceProperties = new ArrayList<>(); + componentInstanceProperties.add(new ComponentInstanceProperty()); + + componentInstancesProperties.put("uuid", componentInstanceProperties); + component.setComponentInstancesProperties(componentInstancesProperties); + + final Map> componentInstancesAttributes = new HashMap<>(); + final List componentInstanceAttributes = new ArrayList<>(); + final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute(); + componentInstanceAttribute.setDefaultValue("def value"); + componentInstanceAttributes.add(componentInstanceAttribute); + + componentInstancesAttributes.put("uuid", componentInstanceAttributes); + component.setComponentInstancesAttributes(componentInstancesAttributes); + + ComponentInstanceProperty cip = new ComponentInstanceProperty(); + cip.setInstanceUniqueId("id"); + + List list = new ArrayList<>(); + list.add(cip); + + componentInstancesProperties.put("id", list); + component.setComponentInstancesProperties(componentInstancesProperties); + + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component)); when(capabilityRequirementConverter - .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) + .convertComponentInstanceCapabilities(any(ComponentInstance.class), anyMap(), any(ToscaNodeTemplate.class))) .thenReturn(Either.left(new ToscaNodeTemplate())); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))) + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), any(ToscaNodeType.class))) .thenReturn(Either.left(new ToscaNodeType())); 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 substitutionMappingMap = new HashMap<>(); final String[] array = {"value1", "value2"}; @@ -745,17 +895,16 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { .thenReturn(Either.left(substitutionMappingMap)); when(capabilityRequirementConverter - .convertSubstitutionMappingRequirements(any(Map.class), any(Component.class), any(SubstitutionMapping.class))) - .thenReturn(Either.left(new SubstitutionMapping())); + .convertSubstitutionMappingRequirements(any(Component.class), anyMap())) + .thenReturn(Either.left(Collections.emptyMap())); // default test final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(component); assertNotNull(toscaRepresentationToscaErrorEither); - } @Test - public void testConvertNodeTemplatesWhenComponentIsResource() throws Exception { + void testConvertNodeTemplatesWhenComponentIsResource() { final Resource component = getNewResource(); component.setResourceType(VF); final List componentInstances = new ArrayList<>(); @@ -849,37 +998,44 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentInstancesInputs.put("id", componentInstanceInputs); component.setComponentInstancesInputs(componentInstancesInputs); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component)); when(capabilityRequirementConverter - .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) - .thenReturn(Either.left(new ToscaNodeTemplate())); + .convertComponentInstanceCapabilities(any(ComponentInstance.class), anyMap(), any(ToscaNodeTemplate.class))) + .thenReturn(Either.left(new ToscaNodeTemplate())); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), any(ToscaNodeType.class))) - .thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), any(ToscaNodeType.class))) + .thenReturn(Either.left(new ToscaNodeType())); 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 substitutionMappingMap = new HashMap<>(); final String[] array = {"value1", "value2"}; substitutionMappingMap.put("key", array); when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class))) - .thenReturn(Either.left(substitutionMappingMap)); + .thenReturn(Either.left(substitutionMappingMap)); when(capabilityRequirementConverter - .convertSubstitutionMappingRequirements(any(Map.class), any(Component.class), any(SubstitutionMapping.class))) - .thenReturn(Either.left(new SubstitutionMapping())); + .convertSubstitutionMappingRequirements(any(Component.class), anyMap())) + .thenReturn(Either.left(Collections.emptyMap())); // default test - final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(component); + final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(newResource); assertNotNull(toscaRepresentationToscaErrorEither); } @Test - public void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() throws Exception { + void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() { Component component = getNewResource(); List componentInstances = new ArrayList<>(); Map> componentInstancesProperties = new HashMap<>(); @@ -912,14 +1068,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentCache.put("uid", component); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component)); when(capabilityRequirementConverter - .convertComponentInstanceCapabilities(any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class))) - .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); + .convertComponentInstanceCapabilities(any(ComponentInstance.class), anyMap(), any(ToscaNodeTemplate.class))) + .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(component); @@ -927,7 +1083,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testConvetNodeTemplateWhenGetOriginComponentIsRight() throws Exception { + void testConvetNodeTemplateWhenGetOriginComponentIsRight() { Component component = getNewResource(); List componentInstances = new ArrayList<>(); Map> componentInstancesProperties = new HashMap<>(); @@ -966,11 +1122,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentCache.put("uid", component); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.right(false)); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test final Either toscaRepresentationToscaErrorEither = testSubject.exportComponent(component); @@ -978,7 +1134,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() { + void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() { Resource component = getNewResource(); component.setResourceType(VF); List componentInstances = new ArrayList<>(); @@ -997,7 +1153,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { reldef.setToNode("node"); List relationships = new ArrayList<>(); CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship(); - relationship.setRelation(new RelationshipInfo()); + relationship.setRelation(new RelationshipInfo("requirement", new RelationshipImpl())); relationships.add(relationship); reldef.setRelationships(relationships); resourceInstancesRelations.add(reldef); @@ -1009,25 +1165,28 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { artifactList.put("assettoscatemplate", artifact); component.setArtifacts(artifactList); component.setToscaArtifacts(artifactList); + component.setRequirements(Collections.singletonMap("mock", Collections.singletonList(new RequirementDefinition()))); ComponentInstance instance = new ComponentInstance(); instance.setUniqueId("id"); instance.setComponentUid("id"); instance.setOriginType(OriginTypeEnum.VF); + Map> requirements = new HashMap<>(); + requirements.put("mock1", Collections.singletonList(new RequirementDefinition())); + instance.setRequirements(requirements); componentInstances.add(instance); - component.setComponentInstances(componentInstances); component.setComponentInstancesInputs(componentInstancesInputs); component.setComponentInstances(componentInstances); doReturn(Either.left(component)).when(toscaOperationFacade).getToscaFullElement("id"); - when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.left(component)); + when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component)); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); // default test final Either result = testSubject.exportComponent(component); @@ -1035,7 +1194,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testCreateNodeType() throws Exception { + void testCreateNodeType() { Component component = new Resource(); List array = new ArrayList<>(); @@ -1045,16 +1204,16 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // test when component is resource result = Deencapsulation.invoke(testSubject, "createNodeType", component); - Assert.assertNotNull(result); + assertNotNull(result); component = new Service(); // test when component is service result = Deencapsulation.invoke(testSubject, "createNodeType", component); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testCreateProxyInterfaceTypesComponentNotFound() throws Exception { + void testCreateProxyInterfaceTypesComponentNotFound() { Component container = new Service(); Either, ToscaError> result; List componentInstances = new ArrayList<>(); @@ -1066,14 +1225,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { componentInstances.add(instance); container.setComponentInstances(componentInstances); when(toscaOperationFacade.getToscaElement(any(String.class), - any(ComponentParametersView.class))) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + any(ComponentParametersView.class))) + .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container); - Assert.assertTrue(result.isRight()); + assertTrue(result.isRight()); } @Test - public void testCreateProxyInterfaceTypesWhenInterfaceLifecycleFetchFailed() { + void testCreateProxyInterfaceTypesWhenInterfaceLifecycleFetchFailed() { Component container = new Service(); Either, ToscaError> result; List componentInstances = new ArrayList<>(); @@ -1085,16 +1244,16 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { container.setComponentInstances(componentInstances); when(toscaOperationFacade.getToscaElement(any(String.class), - any(ComponentParametersView.class))) - .thenReturn(Either.left(new Resource())); + any(ComponentParametersView.class))) + .thenReturn(Either.left(new Resource())); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container); - Assert.assertTrue(result.isRight()); + assertTrue(result.isRight()); } @Test - public void testCreateProxyInterfaceTypesPositive() { + void testCreateProxyInterfaceTypesPositive() { Component container = new Service(); Either, ToscaError> result; List componentInstances = new ArrayList<>(); @@ -1105,25 +1264,24 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { 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 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); - Assert.assertNotNull(result); - Assert.assertTrue(result.isLeft()); - Assert.assertEquals(1, result.left().value().size()); + assertNotNull(result); + assertTrue(result.isLeft()); + assertEquals(1, result.left().value().size()); } @Test - public void testCreateProxyNodeTypes() throws Exception { + void testCreateProxyNodeTypes() { Map componentCache = new HashMap<>(); Component container = new Resource(); Either, ToscaError> result; @@ -1136,15 +1294,15 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { container.setComponentInstances(componentInstances); when(toscaOperationFacade.getLatestByName("serviceProxy", null)) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); // test when getLatestByName return is right result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testCreateServiceSubstitutionNodeTypes() throws Exception { + void testCreateServiceSubstitutionNodeTypes() { Map componentCache = new HashMap<>(); Component referencedService = getNewService(); @@ -1164,19 +1322,19 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { containerService.setComponentInstances(componentInstances); when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())) - .thenReturn(Either.left(Collections.emptyMap())); + .thenReturn(Either.left(Collections.emptyMap())); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); - when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class), - any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); + when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class), + any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); ToscaTemplate toscaNode = new ToscaTemplate("1_1"); Deencapsulation.invoke(testSubject, "createServiceSubstitutionNodeTypes", componentCache, containerService, toscaNode); - Assert.assertNotNull(toscaNode.getNode_types()); + assertNotNull(toscaNode.getNode_types()); } @Test - public void testCreateProxyNodeTypesWhenGetLatestByNameReturnValue() { + void testCreateProxyNodeTypesWhenGetLatestByNameReturnValue() { Map componentCache = new HashMap<>(); Component container = new Resource(); Either, ToscaError> result; @@ -1195,18 +1353,18 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { parameterView.setIgnoreCategories(false); when(toscaOperationFacade.getToscaElement(any(String.class), - any(ComponentParametersView.class))) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + any(ComponentParametersView.class))) + .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>())); // test when getLatestByName is left result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void testCreateProxyNodeType() throws Exception { + void testCreateProxyNodeType() { Map componentCache = new HashMap<>(); Component origComponent = new Resource(); Component proxyComponent = new Resource(); @@ -1217,12 +1375,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // default test result = Deencapsulation.invoke(testSubject, "createProxyNodeType", componentCache, origComponent, - proxyComponent, instance); - Assert.assertNotNull(result); + proxyComponent, instance); + assertNotNull(result); } @Test - public void testConvertComponentInstanceRequirements() throws Exception { + void testConvertComponentInstanceRequirements() { Component component = new Resource(); ComponentInstance componentInstance = new ComponentInstance(); List relations = new ArrayList<>(); @@ -1233,8 +1391,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // default test result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component, - componentInstance, relations, nodeTypeTemplate, originComponent, componentCache); - Assert.assertNotNull(result); + componentInstance, relations, nodeTypeTemplate, originComponent, componentCache); + assertNotNull(result); RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef(); reldef.setFromNode("name"); @@ -1253,12 +1411,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // test when filteredRElations ins't empty result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component, - componentInstance, relations, nodeTypeTemplate, originComponent, componentCache); - Assert.assertNotNull(result); + componentInstance, relations, nodeTypeTemplate, originComponent, componentCache); + assertNotNull(result); } @Test - public void buildRequirementFailure() { + void buildRequirementFailure() { final Component fromOriginComponent = new Resource(); final ComponentInstance fromInstance = new ComponentInstance(); final String fromInstanceUid = "fromInstanceUid"; @@ -1274,15 +1432,15 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { final List instancesList = new ArrayList<>(); instancesList.add(fromInstance); String expectedError = String - .format("Failed to find a relation from the node %s to the node %s", fromInstance.getName(), - relationshipDefinition.getToNode()); - assertThrows(ToscaExportException.class, () -> - Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, - instancesList, relationshipDefinition, new HashMap<>()), expectedError); + .format("Failed to find a relation from the node %s to the node %s", fromInstance.getName(), + relationshipDefinition.getToNode()); + assertDoesNotThrow(() -> + Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, + instancesList, relationshipDefinition, new HashMap<>()), expectedError); try { Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, - instancesList, relationshipDefinition, new HashMap<>()); + instancesList, relationshipDefinition, new HashMap<>()); } catch (Exception e) { assertTrue(e instanceof ToscaExportException); assertEquals(expectedError, e.getMessage()); @@ -1306,25 +1464,25 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { relationshipDefinition.setToNode(fromInstanceUid); expectedError = String - .format("Failed to find a requirement with uniqueId %s on a component with uniqueId %s", - relation.getRequirementUid(), fromOriginComponent.getUniqueId()); + .format("Failed to find a requirement with uniqueId %s on a component with uniqueId %s", + relation.getRequirementUid(), fromOriginComponent.getUniqueId()); assertThrows(ToscaExportException.class, () -> - Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, - instancesList, relationshipDefinition, new HashMap<>()), expectedError); + Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, + instancesList, relationshipDefinition, new HashMap<>()), expectedError); requirementDefinition.setName(requirementName); when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); expectedError = String.format( - "Failed to build substituted name for the requirement %s. " - + "Failed to get an origin component with uniqueId %s", - requirementName, fromInstance.getActualComponentUid()); + "Failed to build substituted name for the requirement %s. " + + "Failed to get an origin component with uniqueId %s", + requirementName, fromInstance.getActualComponentUid()); assertThrows(ToscaExportException.class, () -> Deencapsulation - .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, - relationshipDefinition, new HashMap<>()), expectedError); + .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, + relationshipDefinition, new HashMap<>()), expectedError); final Component toOriginComponent = new Resource(); final Map> capabilityMap = new HashMap<>(); @@ -1338,7 +1496,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { capabilityMap.put(capabilityName, Collections.singletonList(capabilityDefinition)); toOriginComponent.setCapabilities(capabilityMap); when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) - .thenReturn(Either.left(toOriginComponent)); + .thenReturn(Either.left(toOriginComponent)); requirementDefinition.setCapability(capabilityName); relation.setCapability("wrong"); @@ -1347,17 +1505,17 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { requirementDefinition.setPath(new ArrayList<>()); expectedError = String - .format("Failed to find a capability with name %s on a component with uniqueId %s", - relation.getCapability(), fromOriginComponent.getUniqueId()); + .format("Failed to find a capability with name %s on a component with uniqueId %s", + relation.getCapability(), fromOriginComponent.getUniqueId()); assertThrows(ToscaExportException.class, () -> Deencapsulation - .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, - relationshipDefinition, new HashMap<>()), - expectedError); + .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, + relationshipDefinition, new HashMap<>()), + expectedError); } @Test - public void testBuildRequirement() { + void testBuildRequirement() { final ComponentInstance fromInstance = new ComponentInstance(); fromInstance.setUniqueId("name"); fromInstance.setComponentUid("string"); @@ -1404,24 +1562,24 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { toOriginComponent.setCapabilities(capabilityMap); when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) - .thenReturn(Either.left(toOriginComponent)); + .thenReturn(Either.left(toOriginComponent)); final String builtCapabilityName = "builtCapabilityName"; when( - capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq(capabilityName), eq( - capabilityPreviousName))) - .thenReturn(Either.left(builtCapabilityName)); + capabilityRequirementConverter + .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq(capabilityName), eq( + capabilityPreviousName), any())) + .thenReturn(Either.left(builtCapabilityName)); final String builtRequirementName = "builtRequirementName"; when( - capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq(requirementName), eq( - requirementPreviousName))) - .thenReturn(Either.left(builtRequirementName)); + capabilityRequirementConverter + .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq(requirementName), eq( + requirementPreviousName), any())) + .thenReturn(Either.left(builtRequirementName)); final Map actualRequirementMap = - Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, - instancesList, relationshipDefinition, componentCache); + Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, + instancesList, relationshipDefinition, componentCache); assertNotNull(actualRequirementMap); assertFalse(actualRequirementMap.isEmpty()); assertTrue(actualRequirementMap.containsKey(builtRequirementName)); @@ -1431,14 +1589,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { //to toOriginComponent not found when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); assertThrows(ToscaExportException.class, () -> Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, - instancesList, relationshipDefinition, componentCache)); + instancesList, relationshipDefinition, componentCache)); } @Test - public void testAddRequirmentsWithBuildAndAddRequirements() { + void testAddRequirmentsWithBuildAndAddRequirements() { ComponentInstance fromInstance = new ComponentInstance(); Component fromOriginComponent = new Resource(); List instancesList = new ArrayList<>(); @@ -1483,25 +1641,25 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { fromOriginComponent.setCapabilities(capabilities); when(toscaOperationFacade.getToscaElement(any(String.class), - any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent)); + any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent)); when( - capabilityRequirementConverter - .buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString())) - .thenReturn(Either.right(false)); + capabilityRequirementConverter + .buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString(), any())) + .thenReturn(Either.right(false)); final String expectedErrorMsg = - String.format("Failed to build a substituted capability name for the capability " - + "with name %s on a component with uniqueId %s", - cap.getRequirement(), fromOriginComponent.getUniqueId()); + String.format("Failed to build a substituted capability name for the capability " + + "with name %s on a component with uniqueId %s", + cap.getRequirement(), fromOriginComponent.getUniqueId()); assertThrows(ToscaExportException.class, () -> - Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, - rel, componentCache), expectedErrorMsg); + Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList, + rel, componentCache), expectedErrorMsg); } @Test - public void testBuildAndAddRequirement() { + void testBuildAndAddRequirement() { Component fromOriginComponent = new Resource(); Component toOriginComponent = new Resource(); CapabilityDefinition capability = new CapabilityDefinition(); @@ -1519,19 +1677,19 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { reqAndRelationshipPair.setRequirement("req"); when( - capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString())) - .thenReturn(Either.left("buildCapNameRes")); + capabilityRequirementConverter + .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString(), any())) + .thenReturn(Either.left("buildCapNameRes")); when( - capabilityRequirementConverter - .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString())) - .thenReturn(Either.left("buildReqNameRes")); + capabilityRequirementConverter + .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString(), any())) + .thenReturn(Either.left("buildReqNameRes")); // default test final Map requirementMap = - Deencapsulation.invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, - capability, requirement, capabilityRequirementRelationship, toInstance, componentCache); + Deencapsulation.invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, + capability, requirement, capabilityRequirementRelationship, toInstance, componentCache); assertNotNull(requirementMap); assertFalse(requirementMap.isEmpty()); assertTrue(requirementMap.containsKey("buildReqNameRes")); @@ -1541,7 +1699,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testBuildRequirementBuildSubstitutedNameReturnsValueTwice() { + void testBuildRequirementBuildSubstitutedNameReturnsValueTwice() { final Component fromOriginComponent = new Resource(); final Component toOriginComponent = new Resource(); final CapabilityDefinition capability = new CapabilityDefinition(); @@ -1557,12 +1715,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { relationship.setRequirement("req"); final String builtCapabilityOrRequirementName = "builtCapabilityOrRequirementName"; - when(capabilityRequirementConverter.buildSubstitutedName(any(), any(), any(), any(), any())) - .thenReturn(Either.left(builtCapabilityOrRequirementName)); + 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)); final Map requirementMap = Deencapsulation - .invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement, - capabilityRequirementRelationship, toInstance, componentCache); + .invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement, + capabilityRequirementRelationship, toInstance, componentCache); assertNotNull(requirementMap); assertFalse(requirementMap.isEmpty()); assertTrue(requirementMap.containsKey(builtCapabilityOrRequirementName)); @@ -1572,7 +1732,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { } @Test - public void testIsRequirementBelongToRelation() throws Exception { + void testIsRequirementBelongToRelation() { Component originComponent = new Resource(); RelationshipInfo reqAndRelationshipPair = new RelationshipInfo(); @@ -1585,27 +1745,29 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // test return false result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent, - reqAndRelationshipPair, requirement, fromInstanceId); - Assert.assertFalse(result); + reqAndRelationshipPair, requirement, fromInstanceId); + assertFalse(result); } @Test - public void testIsRequirementBelongToRelationWithNonAtomicComponent() { + void testIsRequirementBelongToRelationWithNonAtomicComponent() { Component originComponent = new Service(); RelationshipInfo reqAndRelationshipPair = new RelationshipInfo(); RequirementDefinition requirement = new RequirementDefinition(); + requirement.setUniqueId(UNIQUE_ID); + reqAndRelationshipPair.setRequirementUid(UNIQUE_ID); String fromInstanceId = ""; boolean result; // default test return true result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent, - reqAndRelationshipPair, requirement, fromInstanceId); - Assert.assertTrue(result); + reqAndRelationshipPair, requirement, fromInstanceId); + assertTrue(result); } @Test - public void testIsRequirementBelongToOwner() throws Exception { + void testIsRequirementBelongToOwner() { RelationshipInfo reqAndRelationshipPair = new RelationshipInfo(); RequirementDefinition requirement = new RequirementDefinition(); @@ -1618,38 +1780,38 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // default test result = Deencapsulation.invoke(testSubject, "isRequirementBelongToOwner", reqAndRelationshipPair, requirement, - fromInstanceId, originComponent); - Assert.assertFalse(result); + fromInstanceId, originComponent); + assertFalse(result); } @Test - public void testIsCvfc() throws Exception { + void testIsCvfc() { Component component = new Service(); boolean result; result = Deencapsulation.invoke(testSubject, "isCvfc", component); - Assert.assertFalse(result); + assertFalse(result); } @Test - public void testConvertCapabilities() throws Exception { - Component component = new Resource(); - SubstitutionMapping substitutionMappings = new SubstitutionMapping(); - Map componentCache = new HashMap<>(); - Either result; + void testConvertCapabilities() { + final Component component = new Resource(); + final Map componentCache = new HashMap<>(); + final Either, ToscaError> expectedResult = Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR); when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(componentCache, component)) - .thenReturn(Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR)); + .thenReturn(expectedResult); // default test return isRight - result = Deencapsulation.invoke(testSubject, "convertCapabilities", component, substitutionMappings, - componentCache); - Assert.assertNotNull(result); + final Either, ToscaError> actualResult = + Deencapsulation.invoke(testSubject, "convertSubstitutionMappingCapabilities", component, componentCache); + assertNotNull(actualResult); + assertEquals(expectedResult, actualResult); } @Test - public void testConvertCapabilities_1() throws Exception { + void testConvertCapabilities_1() { Component component = new Resource(); ToscaNodeType nodeType = new ToscaNodeType(); Map dataTypes = new HashMap<>(); @@ -1660,12 +1822,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { // default test result = Deencapsulation - .invoke(testSubject, "convertCapabilities", new HashMap<>(), component, nodeType, dataTypes); - Assert.assertNotNull(result); + .invoke(testSubject, "convertCapabilities", new HashMap<>(), component, nodeType, dataTypes); + assertNotNull(result); } @Test - public void testConvertToNodeTemplateArtifacts() throws Exception { + void testConvertToNodeTemplateArtifacts() { Map container = new HashMap<>(); ToscaArtifactDataDefinition art = new ToscaArtifactDataDefinition(); art.setFile("test_file"); @@ -1673,133 +1835,15 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { Map result; container.put("test_art", art); result = Deencapsulation.invoke(testSubject, "convertToNodeTemplateArtifacts", container); - Assert.assertNotNull(result); - Assert.assertTrue(MapUtils.isNotEmpty(result)); - Assert.assertEquals("test_file", result.get("test_art").getFile()); - Assert.assertEquals("test_type", result.get("test_art").getType()); - } - - @Test - public void testGetProxyNodeTypeInterfacesNoInterfaces() { - Component service = new Service(); - Optional> proxyNodeTypeInterfaces = - testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES); - Assert.assertFalse(proxyNodeTypeInterfaces.isPresent()); - } - - @Test - public void testGetProxyNodeTypeInterfaces() { - Component service = getTestComponent(); - Optional> proxyNodeTypeInterfaces = - testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES); - Assert.assertTrue(proxyNodeTypeInterfaces.isPresent()); - Map componentInterfaces = proxyNodeTypeInterfaces.get(); - Assert.assertNotNull(componentInterfaces); - } - - - @Test - public void testGetProxyNodeTypePropertiesComponentNull() { - Optional> proxyNodeTypeProperties = - testSubject.getProxyNodeTypeProperties(null, DATA_TYPES); - Assert.assertFalse(proxyNodeTypeProperties.isPresent()); - } - - @Test - public void testGetProxyNodeTypePropertiesNoProperties() { - Component service = new Service(); - Optional> proxyNodeTypeProperties = - testSubject.getProxyNodeTypeProperties(service, DATA_TYPES); - Assert.assertFalse(proxyNodeTypeProperties.isPresent()); - } - - @Test - public void testGetProxyNodeTypeProperties() { - Component service = getTestComponent(); - service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"), - createMockProperty("componentPropInt", null))); - Optional> proxyNodeTypeProperties = - testSubject.getProxyNodeTypeProperties(service, DATA_TYPES); - Assert.assertTrue(proxyNodeTypeProperties.isPresent()); - Map componentProperties = proxyNodeTypeProperties.get(); - Assert.assertNotNull(componentProperties); - Assert.assertEquals(2, componentProperties.size()); - } - - @Test - public void testAddInputsToPropertiesNoInputs() { - Component service = getTestComponent(); - service.setProperties(Arrays.asList(createMockProperty("componentPropStr", "Default String Prop"), - createMockProperty("componentPropInt", null))); - Optional> proxyNodeTypePropertiesResult = - testSubject.getProxyNodeTypeProperties(service, DATA_TYPES); - - Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent()); - Map proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get(); - testSubject.addInputsToProperties(DATA_TYPES, null, proxyNodeTypeProperties); - Assert.assertNotNull(proxyNodeTypeProperties); - Assert.assertEquals(2, proxyNodeTypeProperties.size()); - testSubject.addInputsToProperties(DATA_TYPES, new ArrayList<>(), proxyNodeTypeProperties); - Assert.assertEquals(2, proxyNodeTypeProperties.size()); - } - - @Test - public 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> proxyNodeTypePropertiesResult = - testSubject.getProxyNodeTypeProperties(service, DATA_TYPES); - - Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent()); - Map proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get(); - testSubject.addInputsToProperties(DATA_TYPES, service.getInputs(), proxyNodeTypeProperties); - Assert.assertNotNull(proxyNodeTypeProperties); - Assert.assertEquals(4, proxyNodeTypeProperties.size()); - } - - @Test - public void testAddInputsToPropertiesOnlyInputs() { - Component service = getTestComponent(); - service.setInputs(Arrays.asList(createMockInput("componentInputStr1", - "Default String Input1"), createMockInput("componentInputStr2", "Default String Input2"))); - Optional> proxyNodeTypePropertiesResult = - testSubject.getProxyNodeTypeProperties(service, DATA_TYPES); - - Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent()); - Map proxyNodeTypeProperties = proxyNodeTypePropertiesResult.get(); - testSubject.addInputsToProperties(DATA_TYPES, service.getInputs(), proxyNodeTypeProperties); - Assert.assertNotNull(proxyNodeTypeProperties); - Assert.assertEquals(2, proxyNodeTypeProperties.size()); - } - - @Test - public 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> proxyNodeTypeInterfaces = - testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES); - Assert.assertTrue(proxyNodeTypeInterfaces.isPresent()); - Map componentInterfaces = proxyNodeTypeInterfaces.get(); - Assert.assertNotNull(componentInterfaces); + assertNotNull(result); + assertTrue(MapUtils.isNotEmpty(result)); + assertEquals("test_file", result.get("test_art").getFile()); + assertEquals("test_type", result.get("test_art").getType()); } 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");