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;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum.VF;
import static org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType.PROPERTY;
import fj.data.Either;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
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.ForwardingPathDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
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.RequirementNodeFilterCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
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.ArtifactDefinition;
+import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput;
import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
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;
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.model.operations.impl.ModelOperation;
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.ToscaMetadata;
import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
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<String, DataTypeDefinition> DATA_TYPES = new HashMap<>();
+ private static final String LOCAL_INTERFACE_TYPE = "Local";
+ private static final String UNIQUE_ID = "1L";
@InjectMocks
private ToscaExportHandler testSubject;
@Mock
- private ApplicationDataTypeCache dataTypeCache;
+ private ApplicationDataTypeCache applicationDataTypeCache;
@Mock
private ToscaOperationFacade toscaOperationFacade;
@Mock
private InterfacesOperationsConverter interfacesOperationsConverter;
+ @Mock
+ ModelOperation modelOperation;
+
@Mock
private PolicyExportParser policyExportParser;
- @Before
- public void setUpMock() {
- MockitoAnnotations.initMocks(this);
- doReturn(new ToscaProperty()).when(propertyConvertor).convertProperty(any(), any(), eq(PROPERTY));
+ @Mock
+ private AttributeConverter attributeConverter;
+
+ @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<String, Object>()).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<CategoryDefinition> categories = new ArrayList<>();
CategoryDefinition category = new CategoryDefinition();
List<SubCategoryDefinition> subcategories = new ArrayList<>();
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);
category.setSubcategories(subcategories);
categories.add(category);
+ final List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(new PropertyDefinition());
+ resource.setProperties(properties);
+ Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
+ proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
+ resource.setInterfaces(proxyInterfaces);
+
resource.setCategories(categories);
resource.setVersion("version");
resource.setVendorName("vendorName");
}
@Test
- public void testExportComponent() throws Exception {
+ void testExportComponent() {
Component component = getNewResource();
Either<ToscaRepresentation, ToscaError> result;
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
+ 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(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .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),
+ when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Service.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ 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<ToscaRepresentation, ToscaError> result;
- ((Resource) component).setInterfaces(new HashMap<>());
+ component.setInterfaces(new HashMap<>());
- when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .thenReturn(Either.left(Collections.emptyMap()));
// default test when convertInterfaceNodeType is right
result = testSubject.exportComponentInterface(component, false);
- Assert.assertNotNull(result);
+ assertNotNull(result);
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+ 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");
+ PropertyDefinition propData = new PropertyDataDefinitionBuilder()
+ .setName("property")
+ .setType("type")
+ .build();
+ List<PropertyDefinition> propDataList = Arrays.asList(propData);
+ dataTypeDefinition.setProperties(propDataList);
+ Either<ToscaRepresentation, ToscaError> result;
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+ when(propertyConvertor.convertProperty(any(), any(), any() )).thenReturn(new ToscaProperty());
+ result = testSubject.exportDataType(dataTypeDefinition);
+ assertNotNull(result);
+ }
+
+ @Test
+ void testConvertInterfaceNodeTypeProperties() {
Resource component = getNewResource();
component.setName(RESOURCE_NAME);
component.setToscaResourceName(RESOURCE_NAME);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .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),
+ when(capabilityRequirementConverter.convertRequirements(anyMap(), any(Resource.class),
any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
- Either<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation
- .invoke(testSubject, "convertInterfaceNodeType", new HashMap<String, Component>(), component,
+ final var result = testSubject.convertInterfaceNodeType(new HashMap<String, Component>(), component,
new ToscaTemplate(TOSCA_VERSION), new HashMap<String, ToscaNodeType>(), false);
- Assert.assertNotNull(result);
- assertThat(result.isLeft(), is(true));
+ assertNotNull(result);
+ assertTrue(result.isLeft());
Map<String, ToscaNodeType> 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<String, ToscaProperty> 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<ToscaTemplate, ToscaError> 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<String, ArtifactDefinition> 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();
ci.setComponentUid("name");
ci.setOriginType(OriginTypeEnum.PNF);
ci.setSourceModelUid("modelName");
List<ComponentInstance> 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<ImmutablePair<ToscaTemplate, Map<String, Component>>, 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("");
component.setComponentInstances(resourceInstances);
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class), any(ComponentInstance.class))).thenReturn(Either.right(false));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+ when(capabilityRequirementConverter.getOriginComponent(anyMap(), any(ComponentInstance.class))).thenReturn(Either.right(false));
final Map<String, ToscaProperty> 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<ToscaTemplate, ToscaError> result;
component.setComponentInstances(new ArrayList<>());
List<GroupDefinition> groups = new ArrayList<>();
groups.add(group);
component.setGroups(groups);
+ final var input = new InputDefinition();
+ input.setName(COMPONENT_INPUT_NAME);
+ input.setType(COMPONENT_INPUT_TYPE);
+ component.setInputs(Collections.singletonList(input));
+
+ final var output = new OutputDefinition();
+ output.setName(COMPONENT_OUTPUT_NAME);
+ output.setType(COMPONENT_OUTPUT_TYPE);
+ component.setOutputs(Collections.singletonList(output));
+
+ Map<String, String[]> substitutionMappingMap = new HashMap<>();
+ String[] array = {"value1", "value2"};
+ substitutionMappingMap.put("key", array);
+
+ when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(),
+ any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
+
+ when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
+ .thenReturn(Either.left(Collections.emptyMap()));
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+
+ when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
+
+ when(groupExportParser.getGroups(component)).thenReturn(null);
+
+ final Map<String, ToscaProperty> map = new HashMap<>();
+ map.put("mock", new ToscaProperty());
+ doReturn(map).when(outputConverter).convert(any(), any());
+
+ // test component contains group
+ final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false);
+ assertNotNull(result);
+ }
+
+ @Test
+ void testConvertToscaTemplateWithSubstitutionFilter() throws ToscaConversionException {
+ Component component = getNewResource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ component.setComponentInstances(new ArrayList<>());
+
+ SubstitutionFilterPropertyDataDefinition filterProp = new SubstitutionFilterPropertyDataDefinition();
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> filterProperties = new ListDataDefinition<>();
+ filterProperties.add(filterProp);
+ SubstitutionFilterDataDefinition subFilter = new SubstitutionFilterDataDefinition();
+ subFilter.setProperties(filterProperties);
+ component.setSubstitutionFilter(subFilter);
+
Map<String, String[]> substitutionMappingMap = new HashMap<>();
String[] array = {"value1", "value2"};
substitutionMappingMap.put("key", array);
- when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(any(Map.class),
+ 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(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ 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);
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<ToscaTemplate, ToscaError> result;
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(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
final Map<String, ToscaProperty> map = new HashMap<>();
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;
// default test
Map<String, String> 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("");
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<>();
ArtifactDefinition baseTypeArtifact = new ArtifactDefinition();
baseTypeArtifact.setArtifactName("typeA");
baseTypeToscaArtifacts.put("assettoscatemplate", baseTypeArtifact);
baseType.setToscaArtifacts(baseTypeToscaArtifacts);
-
+
component.setDerivedFromGenericType("org.typeA");
component.setDerivedFromGenericVersion("1.0");
- when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0")).thenReturn(Either.left(baseType));
+ 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<String, Component> componentCache = new HashMap<>();
List<Map<String, Map<String, String>>> imports = new ArrayList<>();
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<String, ToscaNodeType> nodeTypes = new HashMap<>();
Either<ToscaTemplate, ToscaError> result;
- when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .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<String, ToscaNodeType> nodeTypes = new HashMap<>();
inputs.add(new InputDefinition());
component.setInputs(inputs);
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .thenReturn(Either.left(Collections.emptyMap()));
- when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
+ 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<String, ToscaNodeType> nodeTypes = new HashMap();
+ Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
ToscaNodeType toscaNodeType = new ToscaNodeType();
Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
Either<ToscaTemplate, ToscaError> 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),
+ 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),
+ 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 testConvertNodeTemplates() throws Exception {
- Component component = getNewResource();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ void testConvertNodeTemplatesWhenComponentIsService() {
+ 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, 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);
- ComponentInstance instance = new ComponentInstance();
+ final ComponentInstance instance = new ComponentInstance();
instance.setUniqueId("id");
instance.setComponentUid("uid");
instance.setOriginType(OriginTypeEnum.ServiceProxy);
- List<GroupInstance> groupInstances = new ArrayList<>();
- GroupInstance groupInst = new GroupInstance();
- List<String> artifacts = new ArrayList<>();
+ 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");
+ instance.setMinOccurrences("0");
+ instance.setMaxOccurrences("10");
+ instance.setInstanceCount("{get_input:int}");
+
+ RequirementNodeFilterCapabilityDataDefinition filterCap = new RequirementNodeFilterCapabilityDataDefinition();
+ ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> instanceFilterCapabilities = new ListDataDefinition<>();
+ instanceFilterCapabilities.add(filterCap);
+ CINodeFilterDataDefinition nodeFilter = new CINodeFilterDataDefinition();
+ nodeFilter.setCapabilities(instanceFilterCapabilities);
+ instance.setNodeFilter(nodeFilter);
+
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);
- componentInstancesProperties.put("id", new ArrayList<>());
- componentInstancesInputs.put("id", new ArrayList<>());
+ final List<ComponentInstanceProperty> componentInstanceProperties = new ArrayList<>();
+ componentInstanceProperties.add(new ComponentInstanceProperty());
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
- any(ComponentInstance.class))).thenReturn(Either.left(component));
+ componentInstancesProperties.put("uuid", componentInstanceProperties);
+ component.setComponentInstancesProperties(componentInstancesProperties);
- when(capabilityRequirementConverter.convertComponentInstanceCapabilities(
- any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
- .thenReturn(Either.left(new ToscaNodeTemplate()));
+ 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)))
+ .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
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, new HashMap<>(), componentCache, dataTypes, topologyTemplate);
- Assert.assertNotNull(result);
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
+ assertNotNull(toscaRepresentationToscaErrorEither);
+
}
@Test
- public void testConvertNodeTemplatesWhenComponentIsService() throws Exception {
+ void test () {
Component component = getNewService();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
- Map<String, Component> componentCache = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- List<ComponentInstanceInput> inputs = new ArrayList<>();
- inputs.add(new ComponentInstanceInput());
- componentInstancesInputs.put("key", inputs);
- List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
- RequirementCapabilityRelDef reldef = new RequirementCapabilityRelDef();
+ component.setModel("test");
+
+ when(modelOperation.findAllModelImports("test", true)).thenReturn(new ArrayList<>());
+
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component, false);
+ assertNotNull(toscaRepresentationToscaErrorEither);
+ assertTrue(toscaRepresentationToscaErrorEither.isRight());
+ }
+
+ @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);
- ComponentInstance instance = new ComponentInstance();
+ final ComponentInstance instance = new ComponentInstance();
+ instance.setNodeFilter(nodeFilter);
instance.setUniqueId("id");
instance.setComponentUid("uid");
instance.setOriginType(OriginTypeEnum.ServiceProxy);
- List<GroupInstance> groupInstances = new ArrayList<>();
- GroupInstance groupInst = new GroupInstance();
- List<String> artifacts = new ArrayList<>();
+ 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");
- Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
- ForwardingPathDataDefinition path = new ForwardingPathDataDefinition();
- ListDataDefinition<ForwardingPathElementDataDefinition> list = new ListDataDefinition<>();
- path.setPathElements(list);
- forwardingPaths.put("key", path);
+ componentCache.put("uid", component);
- ((Service) component).setForwardingPaths(forwardingPaths);
+ final List<ComponentInstanceProperty> componentInstanceProperties = new ArrayList<>();
+ componentInstanceProperties.add(new ComponentInstanceProperty());
- componentCache.put("uid", component);
+ 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);
- componentInstancesProperties.put("id", new ArrayList<>());
- componentInstancesInterfaces.put("id", new ArrayList<>());
- componentInstancesInputs.put("id", new ArrayList<>());
+ componentInstancesAttributes.put("uuid", componentInstanceAttributes);
+ component.setComponentInstancesAttributes(componentInstancesAttributes);
+
+ ComponentInstanceProperty cip = new ComponentInstanceProperty();
+ cip.setInstanceUniqueId("id");
+
+ List<ComponentInstanceProperty> list = new ArrayList<>();
+ list.add(cip);
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
- any(ComponentInstance.class))).thenReturn(Either.left(component));
+ componentInstancesProperties.put("id", list);
+ component.setComponentInstancesProperties(componentInstancesProperties);
- when(capabilityRequirementConverter.convertComponentInstanceCapabilities(
- any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
+ 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
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- Assert.assertNotNull(result);
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
+ assertNotNull(toscaRepresentationToscaErrorEither);
}
@Test
- public void testConvertNodeTemplatesWhenConvertComponentInstanceCapabilitiesIsRight() throws Exception {
+ 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() {
Component component = getNewResource();
List<ComponentInstance> componentInstances = new ArrayList<>();
Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
instance.setComponentUid("uid");
instance.setOriginType(OriginTypeEnum.ServiceProxy);
componentInstances.add(instance);
+ component.setComponentInstances(componentInstances);
component.setComponentInstancesInputs(componentInstancesInputs);
component.setInvariantUUID("uuid");
componentCache.put("uid", component);
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
- 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));
+ 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));
+ 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()));
// default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- Assert.assertNotNull(result);
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
+ assertNotNull(toscaRepresentationToscaErrorEither);
}
@Test
- public void testConvetNodeTemplateWhenGetOriginComponentIsRight() throws Exception {
+ void testConvetNodeTemplateWhenGetOriginComponentIsRight() {
Component component = getNewResource();
List<ComponentInstance> componentInstances = new ArrayList<>();
Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
instance.setComponentUid("uid");
instance.setOriginType(OriginTypeEnum.ServiceProxy);
componentInstances.add(instance);
+ component.setComponentInstances(componentInstances);
component.setComponentInstancesInputs(componentInstancesInputs);
component.setInvariantUUID("uuid");
component.setUUID("uuid");
component.setDescription("desc");
+ final List<AttributeDefinition> attributes = new ArrayList<>();
+ final var attribute = new AttributeDefinition();
+ attribute.setName("mock");
+ attributes.add(attribute);
+ component.setAttributes(attributes);
+
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(anyMap(), any(Resource.class),
+ any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- Assert.assertNotNull(result);
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component);
+ assertNotNull(toscaRepresentationToscaErrorEither);
}
@Test
- public void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() {
- Component component = new Resource();
+ void testConvertNodeTemplatesWhenConvertComponentInstanceRequirmentsIsRight() {
+ Resource component = getNewResource();
+ component.setResourceType(VF);
List<ComponentInstance> componentInstances = new ArrayList<>();
Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
Map<String, List<ComponentInstanceProperty>> componentInstancesInterfaces = new HashMap<>();
Map<String, Component> componentCache = new HashMap<>();
Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
ToscaTopolgyTemplate topologyTemplate = new ToscaTopolgyTemplate();
- Either<Map<String, ToscaNodeTemplate>, ToscaError> result;
Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
List<ComponentInstanceInput> inputs = new ArrayList<>();
inputs.add(new ComponentInstanceInput());
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);
component.setComponentInstancesRelations(resourceInstancesRelations);
+ Map<String, ArtifactDefinition> artifactList = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("name.name2");
+ 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.setComponentInstancesInputs(componentInstancesInputs);
component.setComponentInstances(componentInstances);
- when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
- any(ComponentInstance.class))).thenReturn(Either.left(component));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "convertNodeTemplates", component, componentInstances,
- componentInstancesProperties, componentInstancesInterfaces, componentCache, dataTypes, topologyTemplate);
- Assert.assertNotNull(result);
- }
-
- @Test
- public void testAddComponentInstanceInputs() throws Exception {
-
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- String instanceUniqueId = "id";
- Map<String, Object> props = new HashMap<>();
-
- List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
- componentInstanceInputs.add(new ComponentInstanceInput());
-
- componentInstancesInputs.put(instanceUniqueId, componentInstanceInputs);
-
- // default test
- Deencapsulation.invoke(testSubject, "addComponentInstanceInputs", dataTypes, componentInstancesInputs,
- instanceUniqueId, props);
- }
-
- @Test
- public void testAddPropertiesOfComponentInstance() throws Exception {
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = new HashMap<>();
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- String instanceUniqueId = "id";
- Map<String, Object> props = new HashMap<>();
-
- ComponentInstanceProperty cip = new ComponentInstanceProperty();
- cip.setInstanceUniqueId("id");
-
- List<ComponentInstanceProperty> list = new ArrayList<>();
- list.add(cip);
-
- componentInstancesProperties.put("id", list);
-
- // default test
- Deencapsulation.invoke(testSubject, "addPropertiesOfComponentInstance", componentInstancesProperties, dataTypes,
- instanceUniqueId, props);
- }
-
- @Test
- public void testAddPropertiesOfParentComponent() throws Exception {
- Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
- ComponentInstance componentInstance = new ComponentInstance();
- Component componentOfInstance = new Resource();
- Map<String, Object> props = new HashMap<>();
-
- List<PropertyDefinition> properties = new ArrayList<>();
- properties.add(new PropertyDefinition());
-
- ((Resource) componentOfInstance).setProperties(properties);
+ doReturn(Either.left(component)).when(toscaOperationFacade).getToscaFullElement("id");
+ 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(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));
// default test
- Deencapsulation.invoke(testSubject, "addPropertiesOfParentComponent", dataTypes,
- componentOfInstance, props);
+ final Either<ToscaRepresentation, ToscaError> result = testSubject.exportComponent(component);
+ assertNotNull(result);
}
@Test
- public void testCreateNodeType() throws Exception {
+ void testCreateNodeType() {
Component component = new Resource();
List<String> array = new ArrayList<>();
// 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<Map<String, ToscaNodeType>, ToscaError> result;
List<ComponentInstance> componentInstances = new ArrayList<>();
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<Map<String, ToscaNodeType>, ToscaError> result;
List<ComponentInstance> componentInstances = new ArrayList<>();
container.setComponentInstances(componentInstances);
when(toscaOperationFacade.getToscaElement(any(String.class),
- any(ComponentParametersView.class)))
- .thenReturn(Either.left(new Resource()));
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ any(ComponentParametersView.class)))
+ .thenReturn(Either.left(new Resource()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .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<Map<String, ToscaNodeType>, ToscaError> result;
List<ComponentInstance> componentInstances = new ArrayList<>();
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(Collections.emptyMap()));
Component proxyResource = new Resource();
Map<String, InterfaceDefinition> proxyInterfaces = new HashMap<>();
proxyInterfaces.put("Local", new InterfaceDefinition("Local", "desc", new HashMap<>()));
proxyResource.setInterfaces(proxyInterfaces);
- when(toscaOperationFacade.getToscaElement(any(String.class),
- any(ComponentParametersView.class)))
- .thenReturn(Either.left(proxyResource));
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class))).thenReturn(Either.left(proxyResource));
+ when(interfacesOperationsConverter.addInterfaceTypeElement(any(Component.class), anyList()))
+ .thenReturn(Collections.singletonMap(LOCAL_INTERFACE_TYPE, new HashMap<>()));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
- 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<String, Component> componentCache = new HashMap<>();
Component container = new Resource();
Either<Map<String, ToscaNodeType>, ToscaError> result;
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- when(toscaOperationFacade.getLatestByName("serviceProxy"))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(toscaOperationFacade.getLatestByName("serviceProxy", null))
+ .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<String, Component> componentCache = new HashMap<>();
Component referencedService = getNewService();
componentInstances.add(instance);
containerService.setComponentInstances(componentInstances);
- when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
- .thenReturn(Either.left(Collections.emptyMap()));
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class),
- any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .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()));
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<String, Component> componentCache = new HashMap<>();
Component container = new Resource();
Either<Map<String, ToscaNodeType>, ToscaError> result;
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- when(toscaOperationFacade.getLatestByName("serviceProxy")).thenReturn(Either.left(new Resource()));
+ when(toscaOperationFacade.getLatestByName("serviceProxy", null)).thenReturn(Either.left(new Resource()));
ComponentParametersView parameterView = new ComponentParametersView();
parameterView.disableAll();
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(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ 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<String, Component> componentCache = new HashMap<>();
Component origComponent = new Resource();
Component proxyComponent = new Resource();
ComponentInstance instance = new ComponentInstance();
ToscaNodeType result;
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
// 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<RequirementCapabilityRelDef> relations = new ArrayList<>();
// 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");
// 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";
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
- public void testBuildRequirement() {
+ void testBuildRequirement() {
final ComponentInstance fromInstance = new ComponentInstance();
fromInstance.setUniqueId("name");
fromInstance.setComponentUid("string");
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<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
- public void testAddRequirmentsWithBuildAndAddRequirements() {
+ void testAddRequirmentsWithBuildAndAddRequirements() {
ComponentInstance fromInstance = new ComponentInstance();
Component fromOriginComponent = new Resource();
List<ComponentInstance> instancesList = new ArrayList<>();
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();
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<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"));
}
@Test
- public void testBuildRequirementBuildSubstitutedNameReturnsValueTwice() {
+ void testBuildRequirementBuildSubstitutedNameReturnsValueTwice() {
final Component fromOriginComponent = new Resource();
final Component toOriginComponent = new Resource();
final CapabilityDefinition capability = new CapabilityDefinition();
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<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
- public void testIsRequirementBelongToRelation() throws Exception {
+ void testIsRequirementBelongToRelation() {
Component originComponent = new Resource();
RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
// 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();
// 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<String, Component> componentCache = new HashMap<>();
- Either<SubstitutionMapping, ToscaError> result;
+ void testConvertCapabilities() {
+ final Component component = new Resource();
+ final Map<String, Component> componentCache = new HashMap<>();
+ final Either<Map<String, String[]>, 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<Map<String, String[]>, 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<String, DataTypeDefinition> dataTypes = new HashMap<>();
// 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<String, ToscaArtifactDataDefinition> container = new HashMap<>();
ToscaArtifactDataDefinition art = new ToscaArtifactDataDefinition();
art.setFile("test_file");
Map<String, ToscaTemplateArtifact> 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<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- Assert.assertFalse(proxyNodeTypeInterfaces.isPresent());
- }
-
- @Test
- public void testGetProxyNodeTypeInterfaces() {
- Component service = getTestComponent();
- Optional<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- Assert.assertTrue(proxyNodeTypeInterfaces.isPresent());
- Map<String, Object> componentInterfaces = proxyNodeTypeInterfaces.get();
- Assert.assertNotNull(componentInterfaces);
- }
-
-
- @Test
- public void testGetProxyNodeTypePropertiesComponentNull() {
- Optional<Map<String, ToscaProperty>> proxyNodeTypeProperties =
- testSubject.getProxyNodeTypeProperties(null, DATA_TYPES);
- Assert.assertFalse(proxyNodeTypeProperties.isPresent());
- }
-
- @Test
- public void testGetProxyNodeTypePropertiesNoProperties() {
- Component service = new Service();
- Optional<Map<String, ToscaProperty>> 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<Map<String, ToscaProperty>> proxyNodeTypeProperties =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
- Assert.assertTrue(proxyNodeTypeProperties.isPresent());
- Map<String, ToscaProperty> 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<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> 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<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> 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<Map<String, ToscaProperty>> proxyNodeTypePropertiesResult =
- testSubject.getProxyNodeTypeProperties(service, DATA_TYPES);
-
- Assert.assertTrue(proxyNodeTypePropertiesResult.isPresent());
- Map<String, ToscaProperty> 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<Map<String, Object>> proxyNodeTypeInterfaces =
- testSubject.getProxyNodeTypeInterfaces(service, DATA_TYPES);
- Assert.assertTrue(proxyNodeTypeInterfaces.isPresent());
- Map<String, Object> 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");
return component;
}
- private PropertyDefinition createMockProperty(String propertyName, String defaultValue){
+ private PropertyDefinition createMockProperty(String propertyName, String defaultValue) {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setName(propertyName);
propertyDefinition.setType("string");
return propertyDefinition;
}
- private InputDefinition createMockInput(String inputName, String defaultValue){
+ private InputDefinition createMockInput(String inputName, String defaultValue) {
InputDefinition inputDefinition = new InputDefinition();
inputDefinition.setName(inputName);
inputDefinition.setType("string");