package org.openecomp.sdc.be.tosca;
+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 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.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;
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;
private static final String RESOURCE_NAME = "resource";
private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
private static final String LOCAL_INTERFACE_TYPE = "Local";
+ private static final String UNIQUE_ID = "1L";
@InjectMocks
private ToscaExportHandler testSubject;
void setUpMock() {
MockitoAnnotations.openMocks(this);
doReturn(new ToscaProperty()).when(propertyConvertor).convertProperty(any(), any(), eq(PROPERTY));
- doReturn(new HashMap<String, Object>()).when(interfacesOperationsConverter).getInterfacesMap(any(), isNull(), anyMap(), anyMap(), anyBoolean());
+ doReturn(new HashMap<String, Object>()).when(interfacesOperationsConverter)
+ .getInterfacesMap(any(), isNull(), anyMap(), anyMap(), anyBoolean());
}
private Resource getNewResource() {
dataType.setName("dataTypeName");
dataType.setDerivedFromName("tosca.datatypes.Root");
PropertyDataDefinition propData = new PropertyDataDefinitionBuilder()
- .setName("property")
- .setType("type")
- .build();
+ .setName("property")
+ .setType("type")
+ .build();
List<PropertyDataDefinition> propDataList = Arrays.asList(propData);
dataType.setPropertiesData(propDataList);
List<PropertyDefinition> propList = propDataList.stream().map(PropertyDefinition::new)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
dataType.setProperties(propList);
dataTypes.add(dataType);
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ 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);
component = getNewService();
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
// default test when component is Service
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);
assertNotNull(result);
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test when convertInterfaceNodeType is left
result = testSubject.exportComponentInterface(component, false);
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(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
+ any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
final var result = testSubject.convertInterfaceNodeType(new HashMap<String, Component>(), component,
- new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
+ new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
assertNotNull(result);
assertTrue(result.isLeft());
Map<String, ToscaNodeType> nodeTypeMap = result.left().value().getNode_types();
substitutionMappingMap.put("key", array);
when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(),
- any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
+ any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
- .thenReturn(Either.left(Collections.emptyMap()));
+ .thenReturn(Either.left(Collections.emptyMap()));
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
substitutionMappingMap.put("key", array);
when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class)))
- .thenReturn(Either.left(substitutionMappingMap));
+ .thenReturn(Either.left(substitutionMappingMap));
when(capabilityRequirementConverter
- .convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
- .thenReturn(Either.left(Collections.emptyMap()));
+ .convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
+ .thenReturn(Either.left(Collections.emptyMap()));
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
component.setToscaArtifacts(toscaArtifacts);
when(toscaOperationFacade.getToscaFullElement(any(String.class)))
- .thenReturn(Either.left(component));
+ .thenReturn(Either.left(component));
Resource baseType = getNewResource();
Map<String, ArtifactDefinition> baseTypeToscaArtifacts = new HashMap<>();
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);
+ .invoke(testSubject, "convertNodeType", new HashMap<>(), component, toscaNode, nodeTypes);
assertNotNull(result);
}
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(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType", new HashMap<>(), component, toscaNode
- , nodeTypes, false);
+ , nodeTypes, false);
assertNotNull(result);
}
Either<ToscaTemplate, ToscaError> result;
when(
- capabilityRequirementConverter
- .convertCapabilities(anyMap(), any(Resource.class), anyMap()))
- .thenReturn(new HashMap<>());
+ capabilityRequirementConverter
+ .convertCapabilities(anyMap(), any(Resource.class), anyMap()))
+ .thenReturn(new HashMap<>());
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
result = Deencapsulation
- .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes,
- toscaNodeType, dataTypes);
+ .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes,
+ toscaNodeType, dataTypes);
assertNotNull(result);
component = new Service();
when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ 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);
+ .invoke(testSubject, "convertReqCapAndTypeName", new HashMap<>(), component, toscaNode, nodeTypes,
+ toscaNodeType, dataTypes);
assertNotNull(result);
}
componentInstancesProperties.put("id", list);
component.setComponentInstancesProperties(componentInstancesProperties);
+ 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<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(component);
+ assertNotNull(toscaRepresentationToscaErrorEither);
+
+ }
+
+ @Test
+ void testConvertWithBooleanNodeFilterWhenComponentIsService() {
+ final Component component = getNewService();
+ final List<ComponentInstance> componentInstances = new ArrayList<>();
+ final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
+ final Map<String, Component> componentCache = new HashMap<>();
+ final Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
+ final Map<String, CINodeFilterDataDefinition> 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<PropertyFilterDataDefinition> lstDataDef = new ListDataDefinition<>();
+ lstDataDef.add(prop);
+ nodeFilter.setProperties(lstDataDef);
+ final List<ComponentInstanceInput> inputs = new ArrayList<>();
+ final ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput();
+ componentInstanceInput.setUniqueId("uuid");
+ inputs.add(componentInstanceInput);
+ componentInstancesInputs.put("uuid", inputs);
+ componentInstanceNodeFilters.put("uuid", nodeFilter);
+ 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.setNodeFilter(nodeFilter);
+ instance.setUniqueId("id");
+ instance.setComponentUid("uid");
+ instance.setOriginType(OriginTypeEnum.ServiceProxy);
+ 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);
+
+ 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<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);
+
+ ComponentInstanceProperty cip = new ComponentInstanceProperty();
+ cip.setInstanceUniqueId("id");
+
+ List<ComponentInstanceProperty> 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), anyMap(), any(ToscaNodeTemplate.class)))
// default test
final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
assertNotNull(toscaRepresentationToscaErrorEither);
-
}
@Test
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()));
+ .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()));
+ .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()));
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(Component.class), anyMap()))
- .thenReturn(Either.left(Collections.emptyMap()));
+ .convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
+ .thenReturn(Either.left(Collections.emptyMap()));
// default test
final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(newResource);
when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.left(component));
when(capabilityRequirementConverter
- .convertComponentInstanceCapabilities(any(ComponentInstance.class), anyMap(), 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(anyMap(), any(Resource.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
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()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
reldef.setToNode("node");
List<CapabilityRequirementRelationship> 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);
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<String, List<RequirementDefinition>> 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);
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()));
+ 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<ToscaRepresentation, ToscaError> result = testSubject.exportComponent(component);
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);
assertTrue(result.isRight());
}
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);
assertTrue(result.isRight());
}
proxyResource.setInterfaces(proxyInterfaces);
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<>()));
+ .thenReturn(Collections.singletonMap(LOCAL_INTERFACE_TYPE, new HashMap<>()));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
assertNotNull(result);
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);
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(anyMap(), any(Service.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
ToscaTemplate toscaNode = new ToscaTemplate("1_1");
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<>()));
// default test
result = Deencapsulation.invoke(testSubject, "createProxyNodeType", componentCache, origComponent,
- proxyComponent, instance);
+ proxyComponent, instance);
assertNotNull(result);
}
// default test
result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
- componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
+ componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
assertNotNull(result);
RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
// test when filteredRElations ins't empty
result = Deencapsulation.invoke(testSubject, "convertComponentInstanceRequirements", component,
- componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
+ componentInstance, relations, nodeTypeTemplate, originComponent, componentCache);
assertNotNull(result);
}
final List<ComponentInstance> 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());
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<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
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");
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
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), any()))
- .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), any()))
- .thenReturn(Either.left(builtRequirementName));
+ capabilityRequirementConverter
+ .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq(requirementName), eq(
+ requirementPreviousName), any()))
+ .thenReturn(Either.left(builtRequirementName));
final Map<String, ToscaTemplateRequirement> 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));
//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
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(), any()))
- .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
reqAndRelationshipPair.setRequirement("req");
when(
- capabilityRequirementConverter
- .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString(), any()))
- .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(), any()))
- .thenReturn(Either.left("buildReqNameRes"));
+ capabilityRequirementConverter
+ .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString(), any()))
+ .thenReturn(Either.left("buildReqNameRes"));
// default test
final Map<String, ToscaTemplateRequirement> 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"));
final String builtCapabilityOrRequirementName = "builtCapabilityOrRequirementName";
when(capabilityRequirementConverter.buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("cap"), any(), any()))
- .thenReturn(Either.left(builtCapabilityOrRequirementName));
+ .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,
- capabilityRequirementRelationship, toInstance, componentCache);
+ .invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement,
+ capabilityRequirementRelationship, toInstance, componentCache);
assertNotNull(requirementMap);
assertFalse(requirementMap.isEmpty());
assertTrue(requirementMap.containsKey(builtCapabilityOrRequirementName));
// test return false
result = Deencapsulation.invoke(testSubject, "isRequirementBelongToRelation", originComponent,
- reqAndRelationshipPair, requirement, fromInstanceId);
+ reqAndRelationshipPair, requirement, fromInstanceId);
assertFalse(result);
}
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);
+ reqAndRelationshipPair, requirement, fromInstanceId);
assertTrue(result);
}
// default test
result = Deencapsulation.invoke(testSubject, "isRequirementBelongToOwner", reqAndRelationshipPair, requirement,
- fromInstanceId, originComponent);
+ fromInstanceId, originComponent);
assertFalse(result);
}
final Either<Map<String, String[]>, ToscaError> expectedResult = Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR);
when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(componentCache, component))
- .thenReturn(expectedResult);
+ .thenReturn(expectedResult);
// default test return isRight
final Either<Map<String, String[]>, ToscaError> actualResult =
- Deencapsulation.invoke(testSubject, "convertSubstitutionMappingCapabilities", component, componentCache);
+ Deencapsulation.invoke(testSubject, "convertSubstitutionMappingCapabilities", component, componentCache);
assertNotNull(actualResult);
assertEquals(expectedResult, actualResult);
}
// default test
result = Deencapsulation
- .invoke(testSubject, "convertCapabilities", new HashMap<>(), component, nodeType, dataTypes);
+ .invoke(testSubject, "convertCapabilities", new HashMap<>(), component, nodeType, dataTypes);
assertNotNull(result);
}