+ void testConvertNodeTemplatesWhenComponentIsResource() {
+ final Resource component = getNewResource();
+ component.setResourceType(VF);
+ final List<ComponentInstance> componentInstances = new ArrayList<>();
+ final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ final Map<String, Component> componentCache = new HashMap<>();
+ final Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ final ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
+ final Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
+ final Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ final List<ComponentInstanceInput> inputs = new ArrayList<>();
+ final ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput();
+ componentInstanceInput.setUniqueId("uuid");
+ inputs.add(componentInstanceInput);
+ componentInstancesInputs.put("uuid", inputs);
+ final List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
+ final RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ reldef.setFromNode("node");
+ resourceInstancesRelations.add(reldef);
+ component.setComponentInstancesRelations(resourceInstancesRelations);
+
+ final ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.VFC);
+ final List<GroupInstance> groupInstances = new ArrayList<>();
+ final GroupInstance groupInst = new GroupInstance();
+ final List<String> artifacts = new ArrayList<>();
+ artifacts.add("artifact");
+ groupInst.setArtifacts(artifacts);
+ groupInst.setType("type");
+ groupInstances.add(groupInst);
+ instance.setGroupInstances(groupInstances);
+
+ final List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(new PropertyDefinition());
+ instance.setProperties(properties);
+ component.setProperties(properties);
+
+ instance.setUniqueId("uuid");
+ instance.setDescription("desc");
+ instance.setSourceModelUid("sourceModelUid");
+ final Map<String, ArtifactDefinition> artifactList = new HashMap<>();
+ final ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("name.name2");
+ artifactList.put("assettoscatemplate", artifact);
+ instance.setArtifacts(artifactList);
+
+ Map<String, ToscaArtifactDataDefinition> toscaArtifactDataDefinitionMap = new HashMap<>();
+ toscaArtifactDataDefinitionMap.put("assettoscatemplate", new ToscaArtifactDataDefinition());
+ instance.setToscaArtifacts(toscaArtifactDataDefinitionMap);
+
+ componentInstances.add(instance);
+
+ component.setComponentInstances(componentInstances);
+
+ component.setComponentInstancesInputs(componentInstancesInputs);
+ component.setInvariantUUID("uuid");
+ component.setUUID("uuid");
+ component.setDescription("desc");
+ component.setUniqueId("uid");
+
+ componentCache.put("uid", component);
+
+ final List<ComponentInstanceProperty> componentInstanceProperties = new ArrayList<>();
+ componentInstanceProperties.add(new ComponentInstanceProperty());
+
+ componentInstancesProperties.put("uuid", componentInstanceProperties);
+ component.setComponentInstancesProperties(componentInstancesProperties);
+
+ final Map<String, List<ComponentInstanceAttribute>> componentInstancesAttributes = new HashMap<>();
+ final List<ComponentInstanceAttribute> componentInstanceAttributes = new ArrayList<>();
+ final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
+ componentInstanceAttribute.setDefaultValue("def value");
+ componentInstanceAttributes.add(componentInstanceAttribute);
+
+ componentInstancesAttributes.put("uuid", componentInstanceAttributes);
+ component.setComponentInstancesAttributes(componentInstancesAttributes);
+
+ component.setArtifacts(artifactList);
+ component.setToscaArtifacts(artifactList);
+
+ final List<AttributeDefinition> attributes = new ArrayList<>();
+ final var attribute = new AttributeDefinition();
+ attribute.setName("mock");
+ attributes.add(attribute);
+ component.setAttributes(attributes);
+
+ List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
+ componentInstanceInputs.add(new ComponentInstanceInput());
+
+ componentInstancesInputs.put("id", componentInstanceInputs);
+ component.setComponentInstancesInputs(componentInstancesInputs);
+
+ 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()));
+
+ 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"};
+ 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<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(newResource);
+ assertNotNull(toscaRepresentationToscaErrorEither);
+
+ }
+
+ @Test
+ void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() {