summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-11-18 18:13:58 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-01-15 13:59:55 +0000
commitbd5a1006210092f9ac5c48352cc94f6264e961ef (patch)
treea91d4fc711dacb4e9833a1f7ff5134ff8407c931 /catalog-be/src/test/java/org
parent3849231a17930b1bb2ba09af15673bfd07538b9d (diff)
Initial support for relationship_templates
Change-Id: Ia246b9f11a77815c0585abfa0b3de5433728001a Issue-ID: SDC-3435 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java48
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java530
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportRelationshipTemplatesHandlerTest.java111
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/builder/ToscaRelationshipBuilderTest.java122
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaRequirementTest.java67
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirementTest.java147
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfaceTypesNameUtilTest.java53
7 files changed, 687 insertions, 391 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index 0281317b89..4f569f91cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -21,9 +21,12 @@ package org.openecomp.sdc.be.tosca;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -70,6 +73,7 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.ServiceMetadataDefinition;
+import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.common.util.YamlToObjectConverter;
@@ -666,4 +670,48 @@ class InterfacesOperationsConverterTest {
assertTrue(MapUtils.isNotEmpty(resultMap)
&& resultMap.containsKey("NotLocal"));
}
+
+ @Test
+ void testRemoveInterfacesWithoutOperationsEmptyMap() {
+ final Map<String, Object> interfaceMap = new HashMap<>();
+ interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap);
+ assertThat(interfaceMap, is(anEmptyMap()));
+ }
+
+ @Test
+ void testRemoveInterfacesWithoutOperationsNullParameter() {
+ final Map<String, Object> interfaceMap = null;
+ interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap);
+ assertThat(interfaceMap, is(nullValue()));
+ }
+
+ @Test
+ void testRemoveInterfacesWithoutOperationsSuccess() {
+ final Map<String, Object> interfaceMap = new HashMap<>();
+ final ToscaInterfaceDefinition toscaInterfaceDefinition1 = new ToscaInterfaceDefinition();
+ interfaceMap.put("toscaInterfaceDefinition1", toscaInterfaceDefinition1);
+
+ final ToscaInterfaceDefinition toscaInterfaceDefinition2 = new ToscaInterfaceDefinition();
+ final Map<String, Object> toscaInterfaceDefinition2OperationMap = new HashMap<>();
+ toscaInterfaceDefinition2OperationMap.put("operation1", new Object());
+ toscaInterfaceDefinition2.setOperations(toscaInterfaceDefinition2OperationMap);
+ interfaceMap.put("toscaInterfaceDefinition2", toscaInterfaceDefinition2);
+
+ final Map<String, Object> toscaInterfaceDefinition3 = new HashMap<>();
+ interfaceMap.put("toscaInterfaceDefinition3", toscaInterfaceDefinition3);
+
+ final Map<String, Object> toscaInterfaceDefinition4 = new HashMap<>();
+ toscaInterfaceDefinition4.put("operation1", new Object());
+ interfaceMap.put("toscaInterfaceDefinition4", toscaInterfaceDefinition4);
+
+ final Object notAToscaInterfaceDefinition = new Object();
+ interfaceMap.put("notAToscaInterfaceDefinition", notAToscaInterfaceDefinition);
+
+ interfacesOperationsConverter.removeInterfacesWithoutOperations(interfaceMap);
+ assertFalse(interfaceMap.containsKey("toscaInterfaceDefinition1"));
+ assertTrue(interfaceMap.containsKey("toscaInterfaceDefinition2"));
+ assertFalse(interfaceMap.containsKey("toscaInterfaceDefinition3"));
+ assertTrue(interfaceMap.containsKey("toscaInterfaceDefinition4"));
+ assertTrue(interfaceMap.containsKey("notAToscaInterfaceDefinition"));
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index b03e12fb6e..a87460fa93 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -16,12 +16,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2020, Nordix Foundation
+ * ================================================================================
*/
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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
@@ -30,6 +37,7 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType.PROPERTY;
import fj.data.Either;
@@ -50,7 +58,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
@@ -65,6 +72,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.exception.ToscaExportException;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
@@ -122,7 +130,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
private ToscaOperationFacade toscaOperationFacade;
@Mock
- private CapabilityRequirementConverter capabiltyRequirementConvertor;
+ private CapabilityRequirementConverter capabilityRequirementConverter;
@Mock
private InputConverter inputConverter;
@@ -146,7 +154,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
private PolicyExportParser policyExportParser;
@Before
- public void setUpMock() throws Exception {
+ public void setUpMock() {
MockitoAnnotations.initMocks(this);
doReturn(new ToscaProperty()).when(propertyConvertor).convertProperty(any(), any(), eq(PROPERTY));
doReturn(new HashMap<String, Object>()).when(interfacesOperationsConverter)
@@ -217,11 +225,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Component component = getNewResource();
Either<ToscaRepresentation, ToscaError> result;
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
// default test when component is Resource
@@ -229,10 +236,9 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Assert.assertNotNull(result);
component = getNewService();
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Service.class),
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
// default test when component is Service
result = testSubject.exportComponent(component);
@@ -246,16 +252,15 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
((Resource) component).setInterfaces(new HashMap<>());
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
// default test when convertInterfaceNodeType is right
result = testSubject.exportComponentInterface(component, false);
Assert.assertNotNull(result);
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test when convertInterfaceNodeType is left
@@ -280,12 +285,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component.setName(RESOURCE_NAME);
component.setToscaResourceName(RESOURCE_NAME);
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
// when convertRequirements is called, make it return the same value as 3rd (index=2) argument.
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenAnswer(i -> Either.left(i.getArgument(2)));
Either<ToscaTemplate, ToscaError> result = (Either<ToscaTemplate, ToscaError>) Deencapsulation
@@ -339,8 +343,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component.setComponentInstances(resourceInstances);
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.right(false));
// default test
@@ -368,19 +372,18 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
String[] array = {"value1", "value2"};
substitutionMappingMap.put("key", array);
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(any(Map.class),
+ when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(any(Map.class),
any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingRequirements(any(Map.class),
+ when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Map.class),
any(Component.class), any(SubstitutionMapping.class)))
.thenReturn(Either.left(new SubstitutionMapping()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(inputConverter.convertInputs(any(List.class), any(Map.class)))
- .thenReturn(new HashMap<>());
+ when(inputConverter.convertInputs(any(List.class), any(Map.class))).thenReturn(new HashMap<>());
- Mockito.when(groupExportParser.getGroups(component))
+ when(groupExportParser.getGroups(component))
.thenReturn(null);
// test component contains group
@@ -408,17 +411,16 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
String[] array = {"value1", "value2"};
substitutionMappingMap.put("key", array);
- Mockito
- .when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class)))
+ when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(), any(Component.class)))
.thenReturn(Either.left(substitutionMappingMap));
- Mockito.when(capabiltyRequirementConvertor
+ when(capabilityRequirementConverter
.convertSubstitutionMappingRequirements(anyMap(), any(Component.class), any(SubstitutionMapping.class)))
.thenReturn(Either.left(new SubstitutionMapping()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
+ when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
// test component contains group
result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode);
Assert.assertNotNull(result);
@@ -456,7 +458,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
toscaArtifacts.put("assettoscatemplate", artifact);
component.setToscaArtifacts(toscaArtifacts);
- Mockito.when(toscaOperationFacade.getToscaFullElement(any(String.class)))
+ when(toscaOperationFacade.getToscaFullElement(any(String.class)))
.thenReturn(Either.left(component));
// default test
@@ -482,9 +484,9 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
ci.setOriginType(OriginTypeEnum.ServiceProxy);
ci.setSourceModelUid("modelName");
- Mockito.when(toscaOperationFacade.getToscaFullElement(eq("name"))).thenReturn(Either.left(component));
+ when(toscaOperationFacade.getToscaFullElement(eq("name"))).thenReturn(Either.left(component));
- Mockito.when(toscaOperationFacade.getToscaFullElement(eq("modelName")))
+ when(toscaOperationFacade.getToscaFullElement(eq("modelName")))
.thenReturn(Either.left(new Service()));
// default test
@@ -508,8 +510,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
Either<ToscaTemplate, ToscaError> result;
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(dataTypeCache.getAll()).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
// default test
result = Deencapsulation
@@ -527,12 +529,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
inputs.add(new InputDefinition());
component.setInputs(inputs);
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
@@ -550,13 +551,12 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
Either<ToscaTemplate, ToscaError> result;
- Mockito.when(
- capabiltyRequirementConvertor
+ when(
+ capabilityRequirementConverter
.convertCapabilities(any(Map.class), any(Resource.class), any(Map.class)))
.thenReturn(new HashMap<>());
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Resource.class),
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Resource.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
@@ -567,8 +567,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component = new Service();
- Mockito
- .when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Service.class),
+ when(capabilityRequirementConverter.convertRequirements(any(Map.class), any(Service.class),
any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// test when component is service
@@ -621,10 +620,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstancesProperties.put("id", new ArrayList<>());
componentInstancesInputs.put("id", new ArrayList<>());
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.left(component));
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ when(capabilityRequirementConverter.convertComponentInstanceCapabilities(
any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.left(new ToscaNodeTemplate()));
@@ -687,10 +686,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstancesInterfaces.put("id", new ArrayList<>());
componentInstancesInputs.put("id", new ArrayList<>());
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.left(component));
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ when(capabilityRequirementConverter.convertComponentInstanceCapabilities(
any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.left(new ToscaNodeTemplate()));
@@ -733,10 +732,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentCache.put("uid", component);
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.left(component));
- Mockito.when(capabiltyRequirementConvertor.convertComponentInstanceCapabilities(
+ when(capabilityRequirementConverter.convertComponentInstanceCapabilities(
any(ComponentInstance.class), any(Map.class), any(ToscaNodeTemplate.class)))
.thenReturn(Either.right(ToscaError.GENERAL_ERROR));
@@ -779,7 +778,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentCache.put("uid", component);
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.right(false));
// default test
@@ -821,7 +820,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
component.setComponentInstancesInputs(componentInstancesInputs);
component.setComponentInstances(componentInstances);
- Mockito.when(capabiltyRequirementConvertor.getOriginComponent(any(Map.class),
+ when(capabilityRequirementConverter.getOriginComponent(any(Map.class),
any(ComponentInstance.class))).thenReturn(Either.left(component));
// default test
@@ -918,7 +917,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class)))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
@@ -937,10 +936,10 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class)))
.thenReturn(Either.left(new Resource()));
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
result = Deencapsulation.invoke(testSubject, "createProxyInterfaceTypes", container);
Assert.assertTrue(result.isRight());
@@ -958,14 +957,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.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);
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class)))
.thenReturn(Either.left(proxyResource));
@@ -988,18 +987,18 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy"))
+ when(toscaOperationFacade.getLatestByName("serviceProxy"))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// test when getLatestByName return is right
result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
Assert.assertNotNull(result);
}
-
+
@Test
public void testCreateServiceSubstitutionNodeTypes() throws Exception {
Map<String, Component> componentCache = new HashMap<>();
-
+
Component referencedService = getNewService();
referencedService.setInvariantUUID("uuid");
referencedService.setUUID("uuid");
@@ -1015,11 +1014,11 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
containerService.setComponentInstances(componentInstances);
-
- Mockito.when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
+
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
- Mockito.when(capabiltyRequirementConvertor.convertRequirements(any(Map.class), any(Service.class),
+ 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()));
ToscaTemplate toscaNode = new ToscaTemplate("1_1");
@@ -1041,17 +1040,17 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
componentInstances.add(instance);
container.setComponentInstances(componentInstances);
- Mockito.when(toscaOperationFacade.getLatestByName("serviceProxy")).thenReturn(Either.left(new Resource()));
+ when(toscaOperationFacade.getLatestByName("serviceProxy")).thenReturn(Either.left(new Resource()));
ComponentParametersView parameterView = new ComponentParametersView();
parameterView.disableAll();
parameterView.setIgnoreCategories(false);
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class)))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
// test when getLatestByName is left
result = Deencapsulation.invoke(testSubject, "createProxyNodeTypes", componentCache, container);
@@ -1066,7 +1065,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
ComponentInstance instance = new ComponentInstance();
ToscaNodeType result;
- Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
// default test
result = Deencapsulation.invoke(testSubject, "createProxyNodeType", componentCache, origComponent,
@@ -1111,138 +1110,185 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
}
@Test
- public void testAddRequirement() throws Exception {
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
+ public void buildRequirementFailure() {
+ final Component fromOriginComponent = new Resource();
+ final ComponentInstance fromInstance = new ComponentInstance();
+ final String fromInstanceUid = "fromInstanceUid";
+ fromInstance.setUniqueId(fromInstanceUid);
+ fromInstance.setComponentUid("componentUid");
+ final RequirementCapabilityRelDef relationshipDefinition = new RequirementCapabilityRelDef();
+ relationshipDefinition.setToNode("wrongNodeUid");
+ final List<CapabilityRequirementRelationship> relationshipList = new ArrayList<>();
+ final CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ relationship.setRequirement(new RequirementDataDefinition());
+ relationshipList.add(relationship);
+ relationshipDefinition.setRelationships(relationshipList);
+ final List<ComponentInstance> instancesList = new ArrayList<>();
instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
- fromOriginComponent.setRequirements(requirements);
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- Assert.assertNotNull(result);
+ 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);
+
+ try {
+ Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent,
+ instancesList, relationshipDefinition, new HashMap<>());
+ } catch (Exception e) {
+ assertTrue(e instanceof ToscaExportException);
+ assertEquals(expectedError, e.getMessage());
+ }
+
+ final RelationshipInfo relation = new RelationshipInfo();
+ final String requirementUid = "Uid";
+ relation.setRequirementUid(requirementUid);
+ final String requirementName = "requirementName";
+ relation.setRequirement(requirementName);
+ final String capabilityName = "capabilityName";
+ relation.setCapability(capabilityName);
+ final String capabilityOwnerId = "capabilityOwnerId";
+ relation.setCapabilityOwnerId(capabilityOwnerId);
+ relationship.setRelation(relation);
+
+ final Map<String, List<RequirementDefinition>> requirementMap = new HashMap<>();
+ final RequirementDefinition requirementDefinition = new RequirementDefinition();
+ requirementMap.put(requirementUid, Collections.singletonList(requirementDefinition));
+ fromOriginComponent.setRequirements(requirementMap);
+ relationshipDefinition.setToNode(fromInstanceUid);
+
+ expectedError = String
+ .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);
+
+ requirementDefinition.setName(requirementName);
+
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
+ .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());
+ assertThrows(ToscaExportException.class, () -> Deencapsulation
+ .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList,
+ relationshipDefinition, new HashMap<>()), expectedError);
+
+ final Component toOriginComponent = new Resource();
+ final Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
+ final CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+
+ capabilityDefinition.setName(capabilityName);
+ capabilityDefinition.setOwnerId(capabilityOwnerId);
+ capabilityDefinition.setType("aType");
+ final String capabilityPreviousName = "capabilityPreviousName";
+ capabilityDefinition.setPreviousName(capabilityPreviousName);
+ capabilityMap.put(capabilityName, Collections.singletonList(capabilityDefinition));
+ toOriginComponent.setCapabilities(capabilityMap);
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(toOriginComponent));
+
+
+ requirementDefinition.setCapability(capabilityName);
+ relation.setCapability("wrong");
+ final String requirementPreviousName = "requirementPreviousName";
+ requirementDefinition.setPreviousName(requirementPreviousName);
+ 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());
+
+ assertThrows(ToscaExportException.class, () -> Deencapsulation
+ .invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList,
+ relationshipDefinition, new HashMap<>()),
+ expectedError);
}
@Test
- public void testAddRequirmentsWhenFindRequirmentsReturnsValue() {
-
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
+ public void testBuildRequirement() {
+ final ComponentInstance fromInstance = new ComponentInstance();
fromInstance.setUniqueId("name");
fromInstance.setComponentUid("string");
+ final List<ComponentInstance> instancesList = new ArrayList<>();
+
+ final Map<String, Component> componentCache = new HashMap<>();
+ final List<CapabilityRequirementRelationship> relationshipList = new ArrayList<>();
+ final CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ relationship.setRequirement(new RequirementDataDefinition());
+ final RelationshipInfo relation = new RelationshipInfo();
+ final String requirementUid = "Uid";
+ relation.setRequirementUid(requirementUid);
+ final String requirementName = "requirementName";
+ relation.setRequirement(requirementName);
+ final String capabilityName = "capabilityName";
+ relation.setCapability(capabilityName);
+ final String capabilityOwnerId = "capabilityOwnerId";
+ relation.setCapabilityOwnerId(capabilityOwnerId);
+ relationship.setRelation(relation);
+ relationshipList.add(relationship);
+ final RequirementCapabilityRelDef relationshipDefinition = new RequirementCapabilityRelDef();
+ relationshipDefinition.setRelationships(relationshipList);
+ relationshipDefinition.setToNode("name");
instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
-
- List<RequirementDefinition> defs = new ArrayList<>();
- RequirementDefinition def = new RequirementDefinition();
- def.setName("requirment");
- def.setCapability("cap");
- defs.add(def);
- requirements.put("key", defs);
- fromOriginComponent.setRequirements(requirements);
-
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
- any(ComponentParametersView.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- Assert.assertNotNull(result);
- }
-
- @Test
- public void testAddRequirmentsWhenCapabilityBelongsToRelation() {
- ComponentInstance fromInstance = new ComponentInstance();
- Component fromOriginComponent = new Resource();
- List<ComponentInstance> instancesList = new ArrayList<>();
- RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, Component> componentCache = new HashMap<>();
- boolean result;
-
- List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
- CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
- cap.setRequirement(new RequirementDataDefinition());
- RelationshipInfo relation = new RelationshipInfo();
- relation.setRequirementUid("Uid");
- relation.setRequirement("requirment");
- relation.setCapability("cap");
- relation.setCapabilityOwnerId("id1");
- cap.setRelation(relation);
- relationships.add(cap);
- rel.setRelationships(relationships);
- rel.setToNode("name");
- fromInstance.setUniqueId("name");
- fromInstance.setComponentUid("string");
- instancesList.add(fromInstance);
- Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
-
- List<RequirementDefinition> defs = new ArrayList<>();
- RequirementDefinition def = new RequirementDefinition();
- def.setName("requirment");
- def.setCapability("cap");
- defs.add(def);
- requirements.put("key", defs);
- fromOriginComponent.setRequirements(requirements);
-
- Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
- List<CapabilityDefinition> caps = new ArrayList<>();
- CapabilityDefinition capdef = new CapabilityDefinition();
- capdef.setOwnerId("id");
- capdef.setName("name");
- capdef.setType("type");
- caps.add(capdef);
- capabilities.put("cap", caps);
-
- fromOriginComponent.setCapabilities(capabilities);
-
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
- any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- Assert.assertNotNull(result);
+ final RequirementDefinition requirementDefinition = new RequirementDefinition();
+ requirementDefinition.setName(requirementName);
+ requirementDefinition.setCapability(capabilityName);
+ final String requirementPreviousName = "requirementPreviousName";
+ requirementDefinition.setPreviousName(requirementPreviousName);
+ requirementDefinition.setPath(new ArrayList<>());
+ final Map<String, List<RequirementDefinition>> requirementMap = new HashMap<>();
+ requirementMap.put(requirementUid, Collections.singletonList(requirementDefinition));
+ final Component fromOriginComponent = new Resource();
+ fromOriginComponent.setRequirements(requirementMap);
+
+ final Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
+ final CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setName(capabilityName);
+ capabilityDefinition.setOwnerId(capabilityOwnerId);
+ final String capabilityPreviousName = "capabilityPreviousName";
+ capabilityDefinition.setPreviousName(capabilityPreviousName);
+ capabilityMap.put(capabilityName, Collections.singletonList(capabilityDefinition));
+ final Component toOriginComponent = new Resource();
+ toOriginComponent.setCapabilities(capabilityMap);
+
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(toOriginComponent));
+ final String builtCapabilityName = "builtCapabilityName";
+ when(
+ capabilityRequirementConverter
+ .buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq(capabilityName), eq(
+ capabilityPreviousName)))
+ .thenReturn(Either.left(builtCapabilityName));
+
+ final String builtRequirementName = "builtRequirementName";
+ when(
+ capabilityRequirementConverter
+ .buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq(requirementName), eq(
+ requirementPreviousName)))
+ .thenReturn(Either.left(builtRequirementName));
+
+ final Map<String, ToscaTemplateRequirement> actualRequirementMap =
+ Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent,
+ instancesList, relationshipDefinition, componentCache);
+ assertNotNull(actualRequirementMap);
+ assertFalse(actualRequirementMap.isEmpty());
+ assertTrue(actualRequirementMap.containsKey(builtRequirementName));
+ final ToscaTemplateRequirement actualToscaTemplateRequirement = actualRequirementMap.get(builtRequirementName);
+ assertNotNull(actualToscaTemplateRequirement);
+ assertEquals(builtCapabilityName, actualToscaTemplateRequirement.getCapability());
+
+ //to toOriginComponent not found
+ when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ assertThrows(ToscaExportException.class, () -> Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent,
+ instancesList, relationshipDefinition, componentCache));
}
@Test
@@ -1253,7 +1299,6 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
RequirementCapabilityRelDef rel = new RequirementCapabilityRelDef();
List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
Map<String, Component> componentCache = new HashMap<>();
- boolean result;
List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
CapabilityRequirementRelationship cap = new CapabilityRequirementRelationship();
@@ -1291,23 +1336,26 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
capabilities.put("cap", caps);
fromOriginComponent.setCapabilities(capabilities);
- Mockito.when(toscaOperationFacade.getToscaElement(any(String.class),
+ when(toscaOperationFacade.getToscaElement(any(String.class),
any(ComponentParametersView.class))).thenReturn(Either.left(fromOriginComponent));
- Mockito.when(
- capabiltyRequirementConvertor
+ when(
+ capabilityRequirementConverter
.buildSubstitutedName(anyMap(), any(Component.class), anyList(), anyString(), anyString()))
.thenReturn(Either.right(false));
- // default test
- result = Deencapsulation.invoke(testSubject, "addRequirement", fromInstance, fromOriginComponent, instancesList,
- rel, toscaRequirements, componentCache);
- Assert.assertNotNull(result);
+ 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());
+
+ assertThrows(ToscaExportException.class, () ->
+ Deencapsulation.invoke(testSubject, "buildRequirement", fromInstance, fromOriginComponent, instancesList,
+ rel, componentCache), expectedErrorMsg);
}
@Test
- public void testBuildAndAddRequirement() throws Exception {
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ public void testBuildAndAddRequirement() {
Component fromOriginComponent = new Resource();
Component toOriginComponent = new Resource();
CapabilityDefinition capability = new CapabilityDefinition();
@@ -1315,7 +1363,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
ComponentInstance toInstance = new ComponentInstance();
Map<String, Component> componentCache = new HashMap<>();
- boolean result;
+ final CapabilityRequirementRelationship capabilityRequirementRelationship = new CapabilityRequirementRelationship();
+ capabilityRequirementRelationship.setRelation(reqAndRelationshipPair);
capability.setPath(new ArrayList<>());
capability.setPreviousName("before cap");
reqAndRelationshipPair.setCapability("cap");
@@ -1323,46 +1372,57 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
requirement.setPreviousName("before req");
reqAndRelationshipPair.setRequirement("req");
- Mockito.when(
- capabiltyRequirementConvertor
+ when(
+ capabilityRequirementConverter
.buildSubstitutedName(anyMap(), eq(toOriginComponent), anyList(), eq("cap"), anyString()))
.thenReturn(Either.left("buildCapNameRes"));
- Mockito.when(
- capabiltyRequirementConvertor
+ when(
+ capabilityRequirementConverter
.buildSubstitutedName(anyMap(), eq(fromOriginComponent), anyList(), eq("req"), anyString()))
- .thenReturn(Either.right(false));
+ .thenReturn(Either.left("buildReqNameRes"));
// default test
- result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
- toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
- Assert.assertNotNull(result);
+ final Map<String, ToscaTemplateRequirement> requirementMap =
+ Deencapsulation.invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent,
+ capability, requirement, capabilityRequirementRelationship, toInstance, componentCache);
+ assertNotNull(requirementMap);
+ assertFalse(requirementMap.isEmpty());
+ assertTrue(requirementMap.containsKey("buildReqNameRes"));
+ final ToscaTemplateRequirement actualToscaTemplateRequirement = requirementMap.get("buildReqNameRes");
+ assertNotNull(actualToscaTemplateRequirement);
+ assertEquals("buildCapNameRes", actualToscaTemplateRequirement.getCapability());
}
@Test
- public void testBuildAndAddRequirementBuildSubtitutedNameReturnsValueTwice() {
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Component fromOriginComponent = new Resource();
- Component toOriginComponent = new Resource();
- CapabilityDefinition capability = new CapabilityDefinition();
- RequirementDefinition requirement = new RequirementDefinition();
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ public void testBuildRequirementBuildSubstitutedNameReturnsValueTwice() {
+ final Component fromOriginComponent = new Resource();
+ final Component toOriginComponent = new Resource();
+ final CapabilityDefinition capability = new CapabilityDefinition();
+ final RequirementDefinition requirement = new RequirementDefinition();
+ final RelationshipInfo relationship = new RelationshipInfo();
+ final CapabilityRequirementRelationship capabilityRequirementRelationship = new CapabilityRequirementRelationship();
+ capabilityRequirementRelationship.setRelation(relationship);
ComponentInstance toInstance = new ComponentInstance();
Map<String, Component> componentCache = new HashMap<>();
- boolean result;
capability.setPath(new ArrayList<>());
- reqAndRelationshipPair.setCapability("cap");
+ relationship.setCapability("cap");
requirement.setPath(new ArrayList<>());
- reqAndRelationshipPair.setRequirement("req");
-
- Mockito.when(capabiltyRequirementConvertor.buildSubstitutedName(any(), any(), any(), any(), any()))
- .thenReturn(Either.left("buildCapNameRes"));
-
- // default test
- result = Deencapsulation.invoke(testSubject, "buildAndAddRequirement", toscaRequirements, fromOriginComponent,
- toOriginComponent, capability, requirement, reqAndRelationshipPair, toInstance, componentCache);
- Assert.assertNotNull(result);
- Assert.assertTrue(result);
+ relationship.setRequirement("req");
+
+ final String builtCapabilityOrRequirementName = "builtCapabilityOrRequirementName";
+ when(capabilityRequirementConverter.buildSubstitutedName(any(), any(), any(), any(), any()))
+ .thenReturn(Either.left(builtCapabilityOrRequirementName));
+
+ final Map<String, ToscaTemplateRequirement> requirementMap = Deencapsulation
+ .invoke(testSubject, "buildRequirement", fromOriginComponent, toOriginComponent, capability, requirement,
+ capabilityRequirementRelationship, toInstance, componentCache);
+ assertNotNull(requirementMap);
+ assertFalse(requirementMap.isEmpty());
+ assertTrue(requirementMap.containsKey(builtCapabilityOrRequirementName));
+ final ToscaTemplateRequirement actualToscaTemplateRequirement = requirementMap.get(builtCapabilityOrRequirementName);
+ assertNotNull(actualToscaTemplateRequirement);
+ assertEquals(builtCapabilityOrRequirementName, actualToscaTemplateRequirement.getCapability());
}
@Test
@@ -1435,7 +1495,7 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Map<String, Component> componentCache = new HashMap<>();
Either<SubstitutionMapping, ToscaError> result;
- Mockito.when(capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(componentCache, component))
+ when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(componentCache, component))
.thenReturn(Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR));
// default test return isRight
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportRelationshipTemplatesHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportRelationshipTemplatesHandlerTest.java
new file mode 100644
index 0000000000..3225999974
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportRelationshipTemplatesHandlerTest.java
@@ -0,0 +1,111 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaRelationship;
+import org.openecomp.sdc.be.tosca.model.ToscaRelationshipTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
+
+class ToscaExportRelationshipTemplatesHandlerTest {
+
+ @Test
+ void testCreateFromEmptyNodeTemplateMapReturnsEmptyMap() {
+ final Map<String, ToscaRelationshipTemplate> actualRelationshipTemplateMap =
+ new ToscaExportRelationshipTemplatesHandler().createFrom(Collections.emptyMap());
+ assertNotNull(actualRelationshipTemplateMap);
+ assertTrue(actualRelationshipTemplateMap.isEmpty());
+ }
+
+ @Test
+ void testCreateFromSuccess() {
+ final Map<String, ToscaNodeTemplate> nodeTemplateMap = new HashMap<>();
+
+ final ToscaNodeTemplate nodeTemplateWithNoRequirements = new ToscaNodeTemplate();
+ nodeTemplateMap.put("nodeTemplateWithNoRequirements", nodeTemplateWithNoRequirements);
+
+ final ToscaNodeTemplate nodeTemplateWithRequirements = new ToscaNodeTemplate();
+ final List<Map<String, ToscaTemplateRequirement>> requirements = new ArrayList<>();
+
+ final Map<String, ToscaTemplateRequirement> requirementMap = new HashMap<>();
+ final ToscaTemplateRequirement complexRequirement = new ToscaTemplateRequirement();
+ complexRequirement.setNode("aNode");
+
+ final ToscaRelationship toscaRelationship = new ToscaRelationship();
+ final String relationshipType = "tosca.relationships.ConnectsTo";
+ toscaRelationship.setType(relationshipType);
+
+ final Map<String, ToscaInterfaceDefinition> interfaces = new HashMap<>();
+ final ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition();
+ final String interfaceConfigureType = "tosca.interfaces.relationship.Configure";
+ toscaInterfaceDefinition.setType(interfaceConfigureType);
+ final HashMap<String, Object> operationMap = new HashMap<>();
+ final String preConfigSourceOperationType = "pre_configure_source";
+ operationMap.put(preConfigSourceOperationType, new Object());
+ toscaInterfaceDefinition.setOperations(operationMap);
+
+ interfaces.put(interfaceConfigureType, toscaInterfaceDefinition);
+ toscaRelationship.setInterfaces(interfaces);
+ complexRequirement.setRelationship(toscaRelationship);
+ requirementMap.put("requirement1", complexRequirement);
+
+ final ToscaTemplateRequirement simpleRequirement = new ToscaTemplateRequirement();
+ simpleRequirement.setNode("anotherNode");
+ simpleRequirement.setRelationship("aRelationship");
+ requirementMap.put("requirement2", simpleRequirement);
+
+ requirements.add(requirementMap);
+ nodeTemplateWithRequirements.setRequirements(requirements);
+ nodeTemplateMap.put("nodeTemplateWithRequirements", nodeTemplateWithRequirements);
+
+ final Map<String, ToscaRelationshipTemplate> actualRelationshipTemplateMap =
+ new ToscaExportRelationshipTemplatesHandler().createFrom(nodeTemplateMap);
+
+ assertNotNull(actualRelationshipTemplateMap);
+ assertEquals(1, actualRelationshipTemplateMap.size());
+ final ToscaRelationshipTemplate actualRelationshipTemplate = actualRelationshipTemplateMap.values().iterator().next();
+ assertEquals(relationshipType, actualRelationshipTemplate.getType());
+
+ final Map<String, ToscaInterfaceDefinition> actualInterfaceMap = actualRelationshipTemplate.getInterfaces();
+ assertNotNull(actualInterfaceMap);
+ assertEquals(1, actualInterfaceMap.size());
+ assertTrue(actualInterfaceMap.containsKey(interfaceConfigureType));
+
+ final ToscaInterfaceDefinition actualToscaInterfaceDefinition =
+ actualInterfaceMap.get(interfaceConfigureType);
+ assertEquals(toscaInterfaceDefinition.getType(), actualToscaInterfaceDefinition.getType());
+
+ final Map<String, Object> actualOperationMap = actualToscaInterfaceDefinition.getOperations();
+ assertNotNull(actualOperationMap);
+ assertEquals(1, actualOperationMap.size());
+ assertTrue(actualOperationMap.containsKey(preConfigSourceOperationType));
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/builder/ToscaRelationshipBuilderTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/builder/ToscaRelationshipBuilderTest.java
new file mode 100644
index 0000000000..cee70661be
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/builder/ToscaRelationshipBuilderTest.java
@@ -0,0 +1,122 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.builder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
+import org.openecomp.sdc.be.tosca.model.ToscaOperationAssignment;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment;
+import org.openecomp.sdc.be.tosca.model.ToscaRelationship;
+import org.openecomp.sdc.be.ui.model.OperationUi;
+import org.openecomp.sdc.be.ui.model.PropertyAssignmentUi;
+
+class ToscaRelationshipBuilderTest {
+
+ @Test
+ void testBuildFromCapabilityRequirementRelationshipSuccess() {
+ final CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ final RelationshipImpl relationshipImpl = new RelationshipImpl();
+ final String relationshipType = "relationshipType";
+ relationshipImpl.setType(relationshipType);
+ final RelationshipInfo relationshipInfo = new RelationshipInfo();
+ relationshipInfo.setRelationships(relationshipImpl);
+ relationship.setRelation(relationshipInfo);
+
+ final List<OperationUi> operationList = new ArrayList<>();
+ final OperationUi operationUi1 = new OperationUi();
+ operationUi1.setInterfaceType("interfaceType1");
+ operationUi1.setOperationType("operation1");
+ operationUi1.setImplementation("implementation");
+ operationList.add(operationUi1);
+
+ final OperationUi operationUi2 = new OperationUi();
+ operationUi2.setInterfaceType("interfaceType1");
+ operationUi2.setOperationType("operation2");
+ operationUi2.setImplementation("implementation");
+ operationList.add(operationUi2);
+ final List<PropertyAssignmentUi> operation2InputList = new ArrayList<>();
+ final PropertyAssignmentUi propertyAssignmentUi1 = new PropertyAssignmentUi();
+ propertyAssignmentUi1.setValue("propertyAssignmentUi1Value");
+ propertyAssignmentUi1.setType("string");
+ propertyAssignmentUi1.setName("propertyAssignmentUi1");
+ operation2InputList.add(propertyAssignmentUi1);
+ final PropertyAssignmentUi propertyAssignmentUi2 = new PropertyAssignmentUi();
+ propertyAssignmentUi2.setValue("propertyAssignmentUi2Value");
+ propertyAssignmentUi2.setType("string");
+ propertyAssignmentUi2.setName("propertyAssignmentUi2");
+ operation2InputList.add(propertyAssignmentUi2);
+ operationUi2.setInputs(operation2InputList);
+
+ final OperationUi operationUi3 = new OperationUi();
+ operationUi3.setInterfaceType("interfaceType2");
+ operationUi3.setOperationType("operation1");
+ operationUi3.setImplementation("implementation");
+ operationList.add(operationUi3);
+
+ relationship.setOperations(operationList);
+
+
+ final ToscaRelationship toscaRelationship = new ToscaRelationshipBuilder().from(relationship);
+ assertEquals(toscaRelationship.getType(), relationshipType);
+ final Map<String, ToscaInterfaceDefinition> interfaceMap = toscaRelationship.getInterfaces();
+ assertNotNull(interfaceMap);
+ assertFalse(interfaceMap.isEmpty());
+ assertEquals(2, interfaceMap.size());
+ final ToscaInterfaceDefinition toscaInterfaceDefinition = interfaceMap.get(operationUi1.getInterfaceType());
+ assertNull(toscaInterfaceDefinition.getType());
+ assertNotNull(toscaInterfaceDefinition.getOperations());
+ assertEquals(2, toscaInterfaceDefinition.getOperations().size());
+ final Object actualOperation1Obj = toscaInterfaceDefinition.getOperations().get(operationUi1.getOperationType());
+ assertTrue(actualOperation1Obj instanceof ToscaOperationAssignment);
+ final ToscaOperationAssignment actualOperation1 = (ToscaOperationAssignment) actualOperation1Obj;
+ assertOperationUi(actualOperation1, operationUi1);
+ }
+
+ private void assertOperationUi(final ToscaOperationAssignment toscaOperationAssignment, final OperationUi operationUi1) {
+ if (operationUi1 == null) {
+ assertNull(toscaOperationAssignment);
+ return;
+ }
+ assertEquals(toscaOperationAssignment.getImplementation(), operationUi1.getImplementation());
+ if (operationUi1.getInputs() == null) {
+ assertNull(toscaOperationAssignment.getInputs());
+ return;
+ }
+ assertEquals(toscaOperationAssignment.getInputs().size(), operationUi1.getInputs().size());
+ operationUi1.getInputs().forEach(propertyAssignmentUi -> {
+ final ToscaPropertyAssignment toscaPropertyAssignment = toscaOperationAssignment.getInputs()
+ .get(propertyAssignmentUi.getName());
+ assertNotNull(toscaPropertyAssignment);
+ assertEquals(propertyAssignmentUi.getValue(), toscaPropertyAssignment.getValue());
+ });
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaRequirementTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaRequirementTest.java
deleted file mode 100644
index bb3af40e36..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaRequirementTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.tosca.model;
-
-import org.junit.Test;
-
-import java.util.List;
-import java.util.Map;
-
-
-public class ToscaRequirementTest {
-
- private ToscaRequirement createTestSubject() {
- return new ToscaRequirement();
- }
-
-
- @Test
- public void testGetOccurrences() throws Exception {
- ToscaRequirement testSubject;
- List<Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOccurrences();
- }
-
-
- @Test
- public void testSetOccurrences() throws Exception {
- ToscaRequirement testSubject;
- List<Object> occurrences = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setOccurrences(occurrences);
- }
-
-
- @Test
- public void testToMap() throws Exception {
- ToscaRequirement testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.toMap();
- }
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirementTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirementTest.java
index 5d45407843..bb5a3e50f0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirementTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirementTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,91 +20,60 @@
package org.openecomp.sdc.be.tosca.model;
-import org.junit.Test;
-
-import java.util.Map;
-
-
-public class ToscaTemplateRequirementTest {
-
- private ToscaTemplateRequirement createTestSubject() {
- return new ToscaTemplateRequirement();
- }
-
-
- @Test
- public void testGetCapability() throws Exception {
- ToscaTemplateRequirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCapability();
- }
-
-
- @Test
- public void testSetCapability() throws Exception {
- ToscaTemplateRequirement testSubject;
- String capability = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCapability(capability);
- }
-
-
- @Test
- public void testGetNode() throws Exception {
- ToscaTemplateRequirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getNode();
- }
-
-
- @Test
- public void testSetNode() throws Exception {
- ToscaTemplateRequirement testSubject;
- String node = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setNode(node);
- }
-
-
- @Test
- public void testGetRelationship() throws Exception {
- ToscaTemplateRequirement testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRelationship();
- }
-
-
- @Test
- public void testSetRelationship() throws Exception {
- ToscaTemplateRequirement testSubject;
- String relationship = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setRelationship(relationship);
- }
-
-
- @Test
- public void testToMap() throws Exception {
- ToscaTemplateRequirement testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.toMap();
- }
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.exception.InvalidArgumentException;
+
+class ToscaTemplateRequirementTest {
+
+ @Test
+ void testSetRelationship() {
+ final ToscaTemplateRequirement toscaTemplateRequirement = new ToscaTemplateRequirement();
+ toscaTemplateRequirement.setRelationship(null);
+ assertNull(toscaTemplateRequirement.getRelationship());
+
+ final String relationshipType = "aType";
+ toscaTemplateRequirement.setRelationship(relationshipType);
+ Object actualRelationship = toscaTemplateRequirement.getRelationship();
+ assertEquals(relationshipType, actualRelationship);
+
+ final ToscaRelationship toscaRelationship = new ToscaRelationship();
+ toscaRelationship.setType(relationshipType);
+ toscaTemplateRequirement.setRelationship(toscaRelationship);
+ actualRelationship = toscaTemplateRequirement.getRelationship();
+ assertEquals(toscaRelationship, actualRelationship);
+
+ assertThrows(InvalidArgumentException.class, () -> toscaTemplateRequirement.setRelationship(1));
+ }
+
+ @Test
+ void testIsRelationshipComplexNotation() {
+ final ToscaTemplateRequirement toscaTemplateRequirement = new ToscaTemplateRequirement();
+ assertFalse(toscaTemplateRequirement.isRelationshipComplexNotation());
+ toscaTemplateRequirement.setRelationship("");
+ assertFalse(toscaTemplateRequirement.isRelationshipComplexNotation());
+ toscaTemplateRequirement.setRelationship(new ToscaRelationship());
+ assertTrue(toscaTemplateRequirement.isRelationshipComplexNotation());
+ }
+
+ @Test
+ void testGetRelationshipAsComplexType() {
+ final ToscaTemplateRequirement toscaTemplateRequirement = new ToscaTemplateRequirement();
+ ToscaRelationship actualRelationship = toscaTemplateRequirement.getRelationshipAsComplexType();
+ assertNull(actualRelationship);
+ final String relationshipType = "aType";
+ toscaTemplateRequirement.setRelationship(relationshipType);
+ actualRelationship = toscaTemplateRequirement.getRelationshipAsComplexType();
+ assertEquals(relationshipType, actualRelationship.getType());
+
+ final ToscaRelationship expectedRelationship = new ToscaRelationship();
+ toscaTemplateRequirement.setRelationship(expectedRelationship);
+ actualRelationship = toscaTemplateRequirement.getRelationshipAsComplexType();
+ assertEquals(expectedRelationship, actualRelationship);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfaceTypesNameUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfaceTypesNameUtilTest.java
new file mode 100644
index 0000000000..8eebebe5cf
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfaceTypesNameUtilTest.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.utils;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+
+class InterfaceTypesNameUtilTest {
+
+ @Test
+ void testBuildInterfaceShortNameSuccess() {
+ String interfaceShortName = InterfaceTypesNameUtil.buildShortName("an.interface.name");
+ assertEquals("name", interfaceShortName);
+
+ interfaceShortName = InterfaceTypesNameUtil.buildShortName("name");
+ assertEquals("name", interfaceShortName);
+
+ interfaceShortName = InterfaceTypesNameUtil.buildShortName("");
+ assertEquals("", interfaceShortName);
+
+ interfaceShortName = InterfaceTypesNameUtil.buildShortName("an.");
+ assertEquals("an.", interfaceShortName);
+
+ interfaceShortName = InterfaceTypesNameUtil.buildShortName(".");
+ assertEquals(".", interfaceShortName);
+
+ interfaceShortName = InterfaceTypesNameUtil.buildShortName(".");
+ assertEquals(".", interfaceShortName);
+ }
+
+ @Test
+ void testBuildInterfaceShortNameNullArgument() {
+ assertThrows(IllegalArgumentException.class, () -> InterfaceTypesNameUtil.buildShortName(null));
+ }
+} \ No newline at end of file