From 032525a375681fb18cc498d8daed9d73faa21ec3 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 23 Jun 2020 09:15:48 +0100 Subject: Support for Nested/Hierarchical Services Change-Id: I478cf2e1f9cf96443a3e35bf22ac2c9d72bca8f1 Issue-ID: SDC-3145 Signed-off-by: MichaelMorris --- .../operations/ToscaOperationFacadeTest.java | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'catalog-model/src/test/java/org/openecomp') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java index caf1805b83..1c730e5718 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java @@ -106,6 +106,7 @@ public class ToscaOperationFacadeTest { private static final String ICON_NAME = "icon"; private static final String SERVICE_MODEL_NAME = "Test_Service"; private static final String SERVICE_PROXY_INSTANCE0_NAME = "testservice_proxy0"; + private static final String SERVICE_SUBSTITUTION_INSTANCE0_NAME = "testservice0"; @InjectMocks private ToscaOperationFacade testInstance; @@ -637,7 +638,7 @@ public class ToscaOperationFacadeTest { } @Test - public void testAddComponentInstanceToTopologyTemplate() { + public void testAddComponentInstanceToTopologyTemplate_ServiceProxy() { Component containerComponent = new Service(); Component originalComponent = new Service(); ComponentInstance componentInstance = new ComponentInstance(); @@ -677,6 +678,45 @@ public class ToscaOperationFacadeTest { verify(nodeTemplateOperationMock, times(1)) .addComponentInstanceToTopologyTemplate(any(), any(), eq("1"), eq(componentInstance), eq(false), eq(user)); } + @Test + public void testAddComponentInstanceToTopologyTemplate_ServiceSubstitution() { + Component containerComponent = new Service(); + Component originalComponent = new Service(); + ComponentInstance componentInstance = new ComponentInstance(); + ComponentInstance existingComponentInstance = new ComponentInstance(); + User user = new User(); + + containerComponent.setComponentType(ComponentTypeEnum.SERVICE); + + originalComponent.setComponentType(ComponentTypeEnum.SERVICE); + originalComponent.setIcon(ICON_NAME); + + componentInstance.setOriginType(OriginTypeEnum.ServiceSubstitution); + componentInstance.setSourceModelName(SERVICE_MODEL_NAME); + + List existingInstances = new ArrayList<>(); + existingComponentInstance.setNormalizedName(SERVICE_SUBSTITUTION_INSTANCE0_NAME); + existingInstances.add(existingComponentInstance); + containerComponent.setComponentInstances(existingInstances); + + when(nodeTemplateOperationMock + .addComponentInstanceToTopologyTemplate(any(), any(), eq("1"), eq(componentInstance), eq(false), eq(user))) + .thenReturn(Either.left(new ImmutablePair<>(new TopologyTemplate(), COMPONENT_ID))); + TopologyTemplate topologyTemplate = new TopologyTemplate(); + topologyTemplate.setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); + when(topologyTemplateOperationMock.getToscaElement(containerComponent.getUniqueId())) + .thenReturn(Either.left(topologyTemplate)); + + Either, StorageOperationStatus> result = + testInstance.addComponentInstanceToTopologyTemplate( + containerComponent, originalComponent, componentInstance, false, user); + + assertTrue(result.isLeft()); + assertEquals(ICON_NAME, componentInstance.getIcon()); + assertEquals(COMPONENT_ID, result.left().value().getRight()); + verify(nodeTemplateOperationMock, times(1)) + .addComponentInstanceToTopologyTemplate(any(), any(), eq("1"), eq(componentInstance), eq(false), eq(user)); + } private Either associatePolicyToComponentWithStatus(StorageOperationStatus status) { PolicyDefinition policy = new PolicyDefinition(); -- cgit 1.2.3-korg