aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2020-02-12 12:28:59 +0200
committerIttay Stern <ittay.stern@att.com>2020-02-20 15:09:01 +0200
commitd6eedb1f342ac32c8339b553848267e443410d57 (patch)
treeb029af0b321d24ac53e616e72fdc19f8fe9d9f47 /vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java
parenta5ba6b59e4fc84b6aeae456c1860fcf7517e99cf (diff)
Topology tree: extract AAITreeNodesEnricher out of AAIServiceTree
Issue-ID: VID-771 Change-Id: I138a89b7b2f00e6e603ff26addefc494aeb019b0 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java143
1 files changed, 5 insertions, 138 deletions
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
index be195c89b..ca3e98e2d 100644
--- 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
@@ -20,37 +20,24 @@
package org.onap.vid.services;
-import static java.util.Collections.emptyList;
-import static java.util.Collections.emptyMap;
-import static java.util.stream.Collectors.toList;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.vid.services.AAITreeNodeBuilderTest.createExpectedVnfTreeNode;
import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Streams;
import com.google.common.util.concurrent.MoreExecutors;
-import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import net.javacrumbs.jsonunit.core.Option;
-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.aai.AaiClient;
import org.onap.vid.aai.util.AAITreeConverter;
import org.onap.vid.asdc.parser.ServiceModelInflator;
-import org.onap.vid.asdc.parser.ServiceModelInflator.Names;
import org.onap.vid.model.ModelUtil;
import org.onap.vid.model.aaiTree.AAITreeNode;
import org.onap.vid.model.aaiTree.NodeType;
@@ -76,136 +63,16 @@ public class AAIServiceTreeTest {
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<String> versionIds = ImmutableList.of("version id a", "version id b", "version id c");
- final ImmutableList<Names> expectedNames = ImmutableList.of(
- new Names("name a", "key a"),
- new Names("name b", "key b"),
- new Names("name c", "key c"));
-
-
- final List<AAITreeNode> 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<String> versionIds = ImmutableList.of("version id a", "version id b", "version id c");
- final Names nullNames = new Names(nullString, nullString);
- final ImmutableList<Names> expectedNames = ImmutableList.of(nullNames, nullNames, nullNames);
-
-
- final List<AAITreeNode> 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<String> versionIds = ImmutableList.of("version id a", "version id b", "version id c", "version id d", nullString);
- final ImmutableList<Names> 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<AAITreeNode> nodesUnderTest = nodesWithVersionIds(versionIds);
-
- aaiServiceTree.enrichNodesWithModelCustomizationName(nodesUnderTest, null);
-
- assertThat(toStrings(nodesUnderTest), containsInAnyOrder(toStringsArray(nodesWithVersionIdsAndCustomizationNames(versionIds, expectedNames))));
- }
-
-
-
- @NotNull
- private String[] toStringsArray(List<AAITreeNode> nodes) {
- return toStrings(nodes).toArray(new String[] {});
- }
-
- @NotNull
- private List<String> toStrings(List<AAITreeNode> 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<AAITreeNode> nodesWithVersionIdsAndCustomizationNames(List<String> versionIds, List<Names> customizationNames) {
- return Streams
- .zip(versionIds.stream(), customizationNames.stream(), this::nodeWithVersionIdAndCustomizationName)
- .collect(toList());
- }
-
- @NotNull
- private List<AAITreeNode> nodesWithVersionIds(List<String> 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;
- }
-
@Test
- public void whenBuildTreeForOneResource_resultAsExpected() throws IOException {
+ public void whenBuildTreeForOneResource_resultAsExpected() {
AaiClient aaiClientMock = mock(AaiClient.class);
ExecutorService executorService = MoreExecutors.newDirectExecutorService();
AAIServiceTree aaiServiceTree = new AAIServiceTree(
- aaiClientMock,
- new AAITreeNodeBuilder(aaiClientMock, new Logging()),
- new AAITreeConverter(new ModelUtil()),
- null,
- null,
- executorService
+ new AAITreeNodeBuilder(aaiClientMock, new Logging()),
+ null,
+ new AAITreeConverter(new ModelUtil()), null,
+ executorService
);
String url = "anyUrl/vnf";