use of org.umlg.sqlg.step.barrier.SqlgLocalStepBarrier in project sqlg by pietermartin.
the class TestLocalVertexStepOptional method testOptional.
@Test
public void testOptional() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).local(__.optional(__.out()).path());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgLocalStepBarrier);
SqlgLocalStepBarrier<?, ?> localStep = (SqlgLocalStepBarrier) traversal.getSteps().get(1);
List<SqlgVertexStep> sqlgVertexStepCompileds = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0));
Assert.assertEquals(1, sqlgVertexStepCompileds.size());
SqlgVertexStep sqlgVertexStepCompiled = sqlgVertexStepCompileds.get(0);
// isForMultipleQueries is arbitary
assertStep(sqlgVertexStepCompiled, false, false, true, true);
Assert.assertEquals(2, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b2));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
}
Aggregations