From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../org/onap/vid/services/AAIServiceTreeTest.java | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java (limited to 'vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java') diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java new file mode 100644 index 000000000..815c6b9ee --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java @@ -0,0 +1,160 @@ +package org.onap.vid.services; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Streams; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.jetbrains.annotations.NotNull; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.vid.asdc.parser.ServiceModelInflator; +import org.onap.vid.asdc.parser.ServiceModelInflator.Names; +import org.onap.vid.model.aaiTree.AAITreeNode; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static java.util.stream.Collectors.toList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +public class AAIServiceTreeTest { + + @Mock + private VidService sdcService; + @Mock + private ServiceModelInflator serviceModelInflator; + @InjectMocks + private AAIServiceTree aaiServiceTree; + + @BeforeTest + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + private final static String nullString = "null placeholder"; + + + + @Test + public void enrichNodesWithModelCustomizationName_simple3NodesCase_nodesEnriched() { + + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of( + "version id a", new Names("name a", "key a"), + "version id b", new Names("name b", "key b"), + "version id c", new Names("name c", "key c") + )); + + final ImmutableList versionIds = ImmutableList.of("version id a", "version id b", "version id c"); + final ImmutableList expectedNames = ImmutableList.of( + new Names("name a", "key a"), + new Names("name b", "key b"), + new Names("name c", "key c")); + + + final List nodesUnderTest = nodesWithVersionIds(versionIds); + aaiServiceTree.enrichNodesWithModelCustomizationName(nodesUnderTest, null); + + assertThat(toStrings(nodesUnderTest), containsInAnyOrder(toStringsArray(nodesWithVersionIdsAndCustomizationNames(versionIds, expectedNames)))); + } + + @Test + public void enrichNodesWithModelCustomizationName_noNodes_noError() { + + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of( + "11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0", new Names("my model cust name", "my key") + )); + + aaiServiceTree.enrichNodesWithModelCustomizationName(emptyList(), null); + } + + @Test + public void enrichNodesWithModelCustomizationName_nothingInModel_nodesUnchanged() { + + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(emptyMap()); + + final ImmutableList versionIds = ImmutableList.of("version id a", "version id b", "version id c"); + final Names nullNames = new Names(nullString, nullString); + final ImmutableList expectedNames = ImmutableList.of(nullNames, nullNames, nullNames); + + + final List nodesUnderTest = nodesWithVersionIds(versionIds); + + aaiServiceTree.enrichNodesWithModelCustomizationName(nodesUnderTest, null); + + assertThat(toStrings(nodesUnderTest), containsInAnyOrder(toStringsArray(nodesWithVersionIdsAndCustomizationNames(versionIds, expectedNames)))); + } + + @Test + public void enrichNodesWithModelCustomizationName_staggered4NodesAndNull_3nodesEnriched2isNull() { + + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of( + "version id Z", new Names("name Z", "key Z"), + "version id d", new Names(null, "key d"), + "version id c", new Names("name c", null), + "version id a", new Names("name a", "key a") + )); + + final ImmutableList versionIds = ImmutableList.of("version id a", "version id b", "version id c", "version id d", nullString); + final ImmutableList expectedNames = ImmutableList.of( + new Names("name a", "key a"), + new Names(nullString, nullString), + new Names("name c", nullString), + new Names(nullString, "key d"), + new Names(nullString, nullString) + ); + + + final List nodesUnderTest = nodesWithVersionIds(versionIds); + + aaiServiceTree.enrichNodesWithModelCustomizationName(nodesUnderTest, null); + + assertThat(toStrings(nodesUnderTest), containsInAnyOrder(toStringsArray(nodesWithVersionIdsAndCustomizationNames(versionIds, expectedNames)))); + } + + + + @NotNull + private String[] toStringsArray(List nodes) { + return toStrings(nodes).toArray(new String[] {}); + } + + @NotNull + private List toStrings(List nodes) { + return nodes.stream().map(n -> { + final ReflectionToStringBuilder reflectionToStringBuilder = new ReflectionToStringBuilder(n, ToStringStyle.SHORT_PREFIX_STYLE); + reflectionToStringBuilder.setExcludeNullValues(true); + return reflectionToStringBuilder.toString(); + }).collect(toList()); + } + + @NotNull + private List nodesWithVersionIdsAndCustomizationNames(List versionIds, List customizationNames) { + return Streams + .zip(versionIds.stream(), customizationNames.stream(), this::nodeWithVersionIdAndCustomizationName) + .collect(toList()); + } + + @NotNull + private List nodesWithVersionIds(List versionIds) { + return versionIds.stream() + .map(versionId -> nodeWithVersionIdAndCustomizationName(versionId, new Names(nullString, nullString))) + .collect(toList()); + } + + private AAITreeNode nodeWithVersionIdAndCustomizationName(String versionId, Names names) { + AAITreeNode newNode = new AAITreeNode(); + newNode.setModelVersionId(versionId.equals(nullString) ? null : versionId); + newNode.setModelCustomizationName(names.getModelCustomizationName().equals(nullString) ? null : names.getModelCustomizationName()); + newNode.setKeyInModel(names.getModelKey().equals(nullString) ? null : names.getModelKey()); + return newNode; + } + +} \ No newline at end of file -- cgit 1.2.3-korg