From 23716ef5c8d80455399fb9239449e09e34d609f3 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Sun, 23 Feb 2020 13:24:47 +0200 Subject: Topology tree: test fetchCustomizationIdsFromToscaModelsWhileNeeded Issue-ID: VID-771 Change-Id: I5c1bf1f4eba8b5f53702ae2192b8ac9a962f1344 Signed-off-by: Ittay Stern --- .../onap/vid/services/AAITreeNodesEnricher.java | 6 ++- .../vid/services/AAITreeNodesEnricherTest.java | 51 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) (limited to 'vid-app-common') diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java index 97bc42368..5956eac20 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java @@ -130,8 +130,10 @@ public class AAITreeNodesEnricher { * @param modelVersions Iterable of model-version-ids to load * @param yieldCustomizationId The key to stop loading on */ - private void fetchCustomizationIdsFromToscaModelsWhileNeeded( - Map inOutMutableNamesByCustomizationId, ListIterator modelVersions, String yieldCustomizationId + void fetchCustomizationIdsFromToscaModelsWhileNeeded( + Map inOutMutableNamesByCustomizationId, + ListIterator modelVersions, + String yieldCustomizationId ) { while (modelVersions.hasNext() && !inOutMutableNamesByCustomizationId.containsKey(yieldCustomizationId)) { inOutMutableNamesByCustomizationId.putAll( diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodesEnricherTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodesEnricherTest.java index 29722563f..1766162b5 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodesEnricherTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodesEnricherTest.java @@ -22,19 +22,28 @@ package org.onap.vid.services; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static java.util.stream.Collectors.toList; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.hamcrest.collection.IsMapContaining.hasKey; +import static org.hamcrest.core.IsNot.not; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Streams; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.ListIterator; +import java.util.Map; import net.javacrumbs.jsonunit.core.Option; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -189,6 +198,48 @@ public class AAITreeNodesEnricherTest { aaiTreeNodesEnricher.enrichVfModulesWithModelCustomizationNameFromOtherVersions(nodes, "modelInvariantId"); } + @Test + public void enrichVfModulesWithModelCustomizationNameFromOtherVersions_givenMissingKeysFoundInFirstSdcModels_sdcRequestsNotExhausted() { + when(featureManager.isActive(Features.FLAG_EXP_TOPOLOGY_TREE_VFMODULE_NAMES_FROM_OTHER_TOSCA_VERSIONS)) + .thenReturn(true); + + final ListIterator manyVersionsIterator = manyModelVerIteratorMock(); + + String customizationIdToFind = "please-find-me"; + Names anyNames = mock(Names.class); + + when(serviceModelInflator.toNamesByCustomizationId(any())) + .thenReturn(singletonMap("uuidBefore", anyNames)) + .thenReturn(singletonMap(customizationIdToFind, anyNames)) + .thenReturn(singletonMap("uuidAfter", anyNames)) + ; + + + final Map inOutMutableNamesByCustomizationId = new HashMap<>(); + aaiTreeNodesEnricher.fetchCustomizationIdsFromToscaModelsWhileNeeded( + inOutMutableNamesByCustomizationId, manyVersionsIterator, customizationIdToFind); + + assertThat(inOutMutableNamesByCustomizationId, allOf( + hasKey(customizationIdToFind), + hasKey("uuidBefore"), + not(hasKey("uuidAfter"))) + ); + + verify(manyVersionsIterator, times(2)).next(); + verify(sdcService, times(2)).getServiceModelOrThrow(any()); + } + + private ListIterator manyModelVerIteratorMock() { + final ModelVer modelVerMock = mock(ModelVer.class); + final ListIterator result = mock(ListIterator.class); + + when(result.next()).thenReturn(modelVerMock); + when(result.hasNext()) + .thenReturn(true, true, true, true, true, true, false); + + return result; + } + @FunctionalInterface public interface Creator { R by(T t); -- cgit 1.2.3-korg