diff options
author | Ittay Stern <ittay.stern@att.com> | 2020-02-23 13:24:47 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2020-02-23 13:24:47 +0200 |
commit | 23716ef5c8d80455399fb9239449e09e34d609f3 (patch) | |
tree | f1002f3099453e8790c605d2ded0edbb66cf1f40 /vid-app-common/src | |
parent | 3bfa1d957d77f9e40c47e654a629e73bd77fdfcd (diff) |
Topology tree: test fetchCustomizationIdsFromToscaModelsWhileNeeded
Issue-ID: VID-771
Change-Id: I5c1bf1f4eba8b5f53702ae2192b8ac9a962f1344
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java | 6 | ||||
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodesEnricherTest.java | 51 |
2 files changed, 55 insertions, 2 deletions
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<String, Names> inOutMutableNamesByCustomizationId, ListIterator<ModelVer> modelVersions, String yieldCustomizationId + void fetchCustomizationIdsFromToscaModelsWhileNeeded( + Map<String, Names> inOutMutableNamesByCustomizationId, + ListIterator<ModelVer> 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<ModelVer> 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<String, Names> 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<ModelVer> manyModelVerIteratorMock() { + final ModelVer modelVerMock = mock(ModelVer.class); + final ListIterator<ModelVer> 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<T, R> { R by(T t); |