aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2020-06-23 09:15:48 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-04 14:42:04 +0000
commit032525a375681fb18cc498d8daed9d73faa21ec3 (patch)
tree20cf4c17f406b8d30c29ce904fe1f19ea4a2c989 /catalog-be/src/test/java
parentc16117e08b97da93da61be841c22f5759cdadd37 (diff)
Support for Nested/Hierarchical Services
Change-Id: I478cf2e1f9cf96443a3e35bf22ac2c9d72bca8f1 Issue-ID: SDC-3145 Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java78
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java32
3 files changed, 127 insertions, 3 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
index 4be50e81ae..1d96272716 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
@@ -43,7 +43,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
-
+import java.util.Optional;
+import java.util.stream.Stream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -86,8 +89,21 @@ public class CategoriesImportManagerTest {
public void importCategoriesTest() throws IOException {
String ymlContent = getYmlContent();
Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
- assertTrue(createCapabilityTypes.isLeft());
+
+ assertTrue(createCapabilityTypes.isLeft());
+ final Map<String, List<CategoryDefinition>> categories = createCapabilityTypes.left().value();
+ final Optional<CategoryDefinition> categoryVoIPCallControl = categories.get("services").stream().filter(category -> category.getName().equals("VoIP Call Control")).findAny();
+ final Optional<CategoryDefinition> categoryWithServiceSubstitutionTrue = categories.get("services").stream().filter(category -> category.getName().equals("Category With Service Substitution True")).findAny();
+ final Optional<CategoryDefinition> categoryWithServiceSubstitutionFalse = categories.get("services").stream().filter(category -> category.getName().equals("Category With Service Substitution False")).findAny();
+
+
+ assertTrue(categoryVoIPCallControl.isPresent());
+ assertFalse(categoryVoIPCallControl.get().isUseServiceSubstitutionForNestedServices());
+ assertTrue(categoryWithServiceSubstitutionTrue.isPresent());
+ assertTrue(categoryWithServiceSubstitutionTrue.get().isUseServiceSubstitutionForNestedServices());
+ assertTrue(categoryWithServiceSubstitutionFalse.isPresent());
+ assertFalse(categoryWithServiceSubstitutionFalse.get().isUseServiceSubstitutionForNestedServices());
}
private String getYmlContent() throws IOException {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index f213835406..d585c6f77a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -1556,7 +1556,7 @@ class ComponentInstanceBusinessLogicTest {
componentInst.setDeploymentArtifacts(component.getDeploymentArtifacts());
return componentInst;
}
-
+
// Prepare ComponentInstance & Resource objects used in createComponentInstance() tests
private Pair<ComponentInstance, Resource> prepareResourcesForCreateComponentInstanceTest() {
ComponentInstance instanceToBeCreated = new ComponentInstance();
@@ -1802,4 +1802,80 @@ class ComponentInstanceBusinessLogicTest {
// Check graph db change was committed
verify(janusGraphDao, times(1)).commit();
}
+
+ @Test
+ void testCreateComponentInstanceServiceSubstitutionSuccess() {
+ ComponentInstance instanceToBeCreated = createServiceSubstitutionComponentInstance();
+ Service originService = createServiceSubstitutionOriginService();
+ Component serviceBaseComponent = createServiceSubstitutionServiceDerivedFromComponent();
+
+ Service updatedService = new Service();
+ updatedService.setComponentInstances(Collections.singletonList(instanceToBeCreated));
+ updatedService.setUniqueId(service.getUniqueId());
+
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID)))
+ .thenReturn(Either.left(originService));
+ when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType())))
+ .thenReturn(Either.left(serviceBaseComponent));
+ when(toscaOperationFacade.getToscaElement(eq(ORIGIN_COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(originService));
+ Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(instanceToBeCreated);
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(service, serviceBaseComponent, instanceToBeCreated, false, user))
+ .thenReturn(Either.left(new ImmutablePair<>(updatedService, COMPONENT_INSTANCE_ID)));
+ when(artifactsBusinessLogic.getArtifacts(
+ "baseComponentId", NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null))
+ .thenReturn(Either.left(new HashMap<>()));
+ when(toscaOperationFacade
+ .addInformationalArtifactsToInstance(service.getUniqueId(), instanceToBeCreated, originService.getArtifacts()))
+ .thenReturn(StorageOperationStatus.OK);
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+
+ ComponentInstance result = componentInstanceBusinessLogic.createComponentInstance(
+ ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, instanceToBeCreated);
+ assertThat(result).isEqualTo(instanceToBeCreated);
+ assertThat(instanceToBeCreated.getComponentVersion()).isEqualTo(originService.getVersion());
+ assertThat(instanceToBeCreated.getIcon()).isEqualTo(originService.getIcon());
+ verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(instanceToBeCreated);
+ verify(toscaOperationFacade, times(1))
+ .addComponentInstanceToTopologyTemplate(service, serviceBaseComponent, instanceToBeCreated, false, user);
+ // Check graph db change was committed
+ verify(janusGraphDao, times(1)).commit();
+ }
+
+ private ComponentInstance createServiceSubstitutionComponentInstance() {
+ final ComponentInstance instanceToBeCreated = new ComponentInstance();
+ instanceToBeCreated.setName(COMPONENT_INSTANCE_NAME);
+ instanceToBeCreated.setUniqueId(COMPONENT_INSTANCE_ID);
+ instanceToBeCreated.setComponentUid(ORIGIN_COMPONENT_ID);
+ instanceToBeCreated.setOriginType(OriginTypeEnum.ServiceSubstitution);
+
+ return instanceToBeCreated;
+ }
+
+ private Service createServiceSubstitutionOriginService() {
+ final Service originComponent = new Service();
+ originComponent.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ originComponent.setVersion(ORIGIN_COMPONENT_VERSION);
+ originComponent.setIcon(ICON_NAME);
+ originComponent.setDerivedFromGenericType("org.openecomp.resource.abstract.nodes.service");
+ originComponent.setName("myService");
+ return originComponent;
+ }
+
+
+ private Component createServiceSubstitutionServiceDerivedFromComponent() {
+ final Resource component = new Resource();
+ component.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ component.setVersion(ORIGIN_COMPONENT_VERSION);
+ component.setIcon(ICON_NAME);
+ component.setToscaResourceName("org.openecomp.resource.abstract.nodes.service");
+ component.setUniqueId("baseComponentId");
+ return component;
+ }
}
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 45cdbbdfaa..d54fc98c9a 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
@@ -997,6 +997,38 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
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");
+ referencedService.setUniqueId("targetModelUid");
+ referencedService.setDescription("desc");
+ componentCache.put("targetModelUid", referencedService);
+
+ Component containerService = new Service();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setOriginType(OriginTypeEnum.ServiceSubstitution);
+ instance.setSourceModelUid("targetModelUid");
+
+ componentInstances.add(instance);
+ containerService.setComponentInstances(componentInstances);
+
+ Mockito.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),
+ 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());
+ }
@Test
public void testCreateProxyNodeTypesWhenGetLatestByNameReturnValue() {