diff options
Diffstat (limited to 'graph-inventory')
4 files changed, 50 insertions, 5 deletions
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java index 59e3895ce2..c56ce0bfee 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java @@ -63,7 +63,7 @@ public class DSLQueryBuilder<S, E> { Object obj = steps.get(steps.size() - 1); if (obj instanceof DSLNodeBase) { - ((DSLNodeBase) steps.get(steps.size() - 1)).output(); + consumer.accept((DSLNodeBase) steps.get(steps.size() - 1)); } else if (obj.getClass().getName().contains("$$Lambda$")) { // process lambda expressions for (Field f : obj.getClass().getDeclaredFields()) { diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java index 48feba25df..881b7e9a8e 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Predicate; +import java.util.function.UnaryOperator; import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType; @@ -56,6 +57,11 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory return this.getAll(Optional.of(type)); } + public List<Wrapper> getByType(GraphInventoryObjectName type, UnaryOperator<Uri> func) { + + return this.getAll(Optional.of(type), func); + } + public List<Wrapper> getAll() { return this.getAll(Optional.empty()); @@ -99,6 +105,10 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory protected List<Wrapper> getAll(final Optional<GraphInventoryObjectName> type) { + return getAll(type, UnaryOperator.identity()); + } + + protected List<Wrapper> getAll(final Optional<GraphInventoryObjectName> type, UnaryOperator<Uri> func) { List<Uri> relatedLinks; if (type.isPresent()) { relatedLinks = this.getRelatedUris(type.get()); @@ -107,7 +117,7 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory } ArrayList<Wrapper> result = new ArrayList<>(); for (Uri link : relatedLinks) { - result.add(this.get(link)); + result.add(this.get(func.apply(link))); } return result; } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java index 9cae761399..b0b0c6aca9 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.onap.aaiclient.client.graphinventory.entities.DSLNodeKey; import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder; import org.onap.aaiclient.client.graphinventory.entities.DSLStartNode; +import org.onap.aaiclient.client.graphinventory.entities.Node; import org.onap.aaiclient.client.graphinventory.entities.Output; import org.onap.aaiclient.client.graphinventory.entities.Start; import org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder; @@ -149,12 +150,20 @@ public class DSLQueryBuilderTest { @Test public void selectOutputFilterTest() { - DSLQueryBuilder<Output, Output> builder = - TraversalBuilder.traversal(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "att-nc")) + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")) .output("cloud-region-id", "a", "b")); builder.to(__.node(AAIObjectType.PSERVER)).output("x", "y", "z"); - assertEquals("cloud-region{'cloud-region-id', 'a', 'b'}('cloud-owner', 'att-nc') > pserver{'x', 'y', 'z'}", + assertEquals("cloud-region{'cloud-region-id', 'a', 'b'}('cloud-owner', 'CloudOwner') > pserver{'x', 'y', 'z'}", builder.build().toString()); } + + @Test + public void selectOutputFilterOnNodeTest() { + DSLStartNode node = new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")); + DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(node).output("cloud-region-id"); + + assertEquals("cloud-region{'cloud-region-id'}('cloud-owner', 'CloudOwner')", builder.build().toString()); + } } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java index 10162f83ee..9e106fab85 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java @@ -21,12 +21,15 @@ package org.onap.aaiclient.client.aai.entities; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; @@ -53,4 +56,27 @@ public class RelationshipsTest { } + @Test + public void getByTypeTest() throws IOException { + final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json"))); + + AAIResultWrapper wrapper = new AAIResultWrapper(content); + Relationships relationships = wrapper.getRelationships().get(); + + Relationships spy = Mockito.spy(relationships); + ArgumentCaptor<AAIResourceUri> argument = ArgumentCaptor.forClass(AAIResourceUri.class); + doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture()); + + spy.getByType(AAIObjectType.VCE, uri -> uri.nodesOnly(true)); + + assertTrue(argument.getAllValues().stream().allMatch(item -> item.build().toString().contains("nodes-only"))); + + argument = ArgumentCaptor.forClass(AAIResourceUri.class); + + doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture()); + spy.getByType(AAIObjectType.VCE); + + assertTrue(argument.getAllValues().stream().allMatch(item -> !item.build().toString().contains("?"))); + + } } |