diff options
Diffstat (limited to 'aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java')
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java | 193 |
1 files changed, 163 insertions, 30 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java index fa06e17f..41daf17f 100644 --- a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java +++ b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java @@ -21,44 +21,51 @@ */ package org.onap.aai.query.builder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; +import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.mockito.Mock; -import org.onap.aai.AAISetup; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.introspection.ModelType; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; - -import static org.junit.Assert.assertEquals; - -public class TraversalQueryTest extends AAISetup { - - private Loader loader; +import org.onap.aai.serialization.db.EdgeType; - @Mock - private GraphTraversalSource g; +public class TraversalQueryTest extends QueryBuilderTestAbstraction { - @Before - public void configure() throws Exception { - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); + + @Override + protected QueryBuilder<Edge> getNewEdgeTraversal(Vertex v) { + return new TraversalQuery<>(loader, g, v, testEdgeRules); + } + + @Override + protected QueryBuilder<Edge> getNewEdgeTraversal() { + return new TraversalQuery<>(loader, g, testEdgeRules); + } + + @Override + protected QueryBuilder<Vertex> getNewVertexTraversal(Vertex v) { + return new TraversalQuery<>(loader, g, v, testEdgeRules); + } + + @Override + protected QueryBuilder<Vertex> getNewVertexTraversal() { + return new TraversalQuery<>(loader, g, testEdgeRules); } @Test public void unionQuery() { - TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g); - TraversalQuery<Vertex> tQ2 = new TraversalQuery<>(loader, g); - TraversalQuery<Vertex> tQ3 = new TraversalQuery<>(loader, g); + QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g); + QueryBuilder<Vertex> tQ2 = new TraversalQuery<>(loader, g); + QueryBuilder<Vertex> tQ3 = new TraversalQuery<>(loader, g); tQ.union( tQ2.getVerticesByProperty("test1", "value1"), tQ3.getVerticesByIndexedProperty("test2", "value2")); @@ -68,12 +75,12 @@ public class TraversalQueryTest extends AAISetup { assertEquals("they are equal", expected, tQ.getQuery()); + g.tx().rollback(); } - @Ignore @Test public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException { - TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g); + QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g); QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/test-objects/test-object/key1")).getQueryBuilder(); GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "test-object"); GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "test-object"); @@ -81,13 +88,13 @@ public class TraversalQueryTest extends AAISetup { assertEquals("query object", expected.toString(), builder.getQuery().toString()); assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString()); + g.tx().rollback(); } - @Ignore @Test public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException { - TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g); + QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g); QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder(); GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2"); GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface"); @@ -95,6 +102,132 @@ public class TraversalQueryTest extends AAISetup { assertEquals("query object", expected.toString(), builder.getQuery().toString()); assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString()); + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexTraversalTest() throws AAIException { + + Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next(); + Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next(); + + testEdgeRules.addEdge(g, gvnf, vnfc1); + + QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf); + tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc"); + + List<Vertex> list = tQ.toList(); + + assertEquals("Has 1 vertexes ", 1, list.size()); + assertTrue("Has vertex on the default edge ", list.contains(vnfc1)); + + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexTraversalSingleOutRuleTest() throws AAIException { + + Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next(); + Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next(); + + testEdgeRules.addEdge(g, vce, vnfc1); + + QueryBuilder<Vertex> tQ1 = new TraversalQuery<>(loader, g, vce, testEdgeRules); + tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc"); + + QueryBuilder<Vertex> tQ2 = new TraversalQuery<>(loader, g, vnfc1, testEdgeRules); + tQ2.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "vnf"); + + List<Vertex> list1 = tQ1.toList(); + List<Vertex> list2 = tQ2.toList(); + + assertEquals("1 - Has 1 vertexes ", 1, list1.size()); + assertTrue("1 - traversal results in vnfc ", list1.contains(vnfc1)); + assertEquals("2 - Has 1 vertexes ", 1, list2.size()); + assertTrue("2 - traversal results in vce ", list2.contains(vce)); + + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexTraversalSingleInRuleTest() throws AAIException { + + Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next(); + Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next(); + + testEdgeRules.addEdge(g, vce, pserver); + + QueryBuilder<Vertex> tQ1 = new TraversalQuery<>(loader, g, vce, testEdgeRules); + tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver"); + + List<Vertex> list = tQ1.toList(); + + assertEquals("1 - Has 1 vertexes ", 1, list.size()); + assertTrue("1 - traversal results in vnfc ", list.contains(pserver)); + + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexMultiRuleTraversalTest() throws AAIException { + + Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next(); + Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next(); + Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next(); + + testEdgeRules.addEdge(g, gvnf, vnfc1); + testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses"); + + QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf); + tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc"); + + List<Vertex> list = tQ.toList(); + + assertEquals("Has 2 vertexes ", 2, list.size()); + assertTrue("Has vertex on the default edge ", list.contains(vnfc1)); + assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2)); + + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexMultiRuleOutTraversalTest() throws AAIException { + + Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next(); + Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next(); + + testEdgeRules.addEdge(g, gvnf, pserver); + testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B"); + + QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf); + tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver"); + + List<Vertex> list = tQ.toList(); + + assertEquals("Has 2 vertexes ", 2, list.size()); + assertTrue("result has pserver ", list.contains(pserver)); + + g.tx().rollback(); + } + + @Test + public void abstractEdgeToVertexMultiRuleInTraversalTest() throws AAIException { + + Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next(); + Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next(); + + testEdgeRules.addEdge(g, gvnf, complex); + testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B"); + + QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf); + tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "complex"); + + List<Vertex> list = tQ.toList(); + + assertEquals("Has 2 vertexes ", 2, list.size()); + assertTrue("result has pserver ", list.contains(complex)); + + g.tx().rollback(); } |