@Test public void shouldBeAbleToTraverseWithMaxDepthAndPruneEvaluatorCombined() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse( startNode, MapUtil.map( "max_depth", 2, "prune_evaluator", MapUtil.map( "language", "javascript", "body", "position.endNode().getProperty('name').equals('Emil')")), TraverserReturnType.node)); assertEquals(3, hits.size()); hits = serialize( actions.traverse( startNode, MapUtil.map( "max_depth", 1, "prune_evaluator", MapUtil.map( "language", "javascript", "body", "position.endNode().getProperty('name').equals('Emil')")), TraverserReturnType.node)); assertEquals(2, hits.size()); }
@Test public void shouldBeAbleToTraverseEverything() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse( startNode, MapUtil.map( "return_filter", MapUtil.map("language", "javascript", "body", "true;"), "max_depth", 10), TraverserReturnType.node)); assertEquals(6, hits.size()); hits = serialize( actions.traverse( startNode, MapUtil.map( "return_filter", MapUtil.map("language", "builtin", "name", "all"), "max_depth", 10), TraverserReturnType.node)); assertEquals(6, hits.size()); }
@Test public void shouldBeAbleToTraverseDepthTwo() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse(startNode, MapUtil.map("max_depth", 2), TraverserReturnType.node)); assertEquals(3, hits.size()); }
@Test public void shouldBeAbleToTraverseWithDefaultParameters() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse(startNode, new HashMap<String, Object>(), TraverserReturnType.node)); assertEquals(2, hits.size()); }
@Test public void shouldBeAbleToGetRelationshipsIfSpecified() { long startNode = createBasicTraversableGraph(); ListRepresentation traverse = actions.traverse( startNode, new HashMap<String, Object>(), TraverserReturnType.relationship); List<Object> hits = serialize(traverse); for (Object hit : hits) { RelationshipRepresentationTest.verifySerialisation((Map<String, Object>) hit); } }
@Test public void shouldBeAbleToGetPathsIfSpecified() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse(startNode, new HashMap<String, Object>(), TraverserReturnType.path)); for (Object hit : hits) { Map<String, Object> map = (Map<String, Object>) hit; assertThat(map, hasKey("start")); assertThat(map, hasKey("end")); assertThat(map, hasKey("length")); } }
@Test public void shouldBeAbleToUseCustomReturnFilter() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse( startNode, MapUtil.map( "prune_evaluator", MapUtil.map("language", "builtin", "name", "none"), "return_filter", MapUtil.map( "language", "javascript", "body", "position.endNode().getProperty( 'name' ).contains( 'o' )")), TraverserReturnType.node)); assertEquals(3, hits.size()); }
@Test public void shouldBeAbleToGetFullPathsIfSpecified() { long startNode = createBasicTraversableGraph(); List<Object> hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(), TraverserReturnType.fullpath)); for (Object hit : hits) { Map<String, Object> map = (Map<String, Object>) hit; Collection<Object> relationships = (Collection<Object>) map.get("relationships"); for (Object relationship : relationships) { RelationshipRepresentationTest.verifySerialisation((Map<String, Object>) relationship); } Collection<Object> nodes = (Collection<Object>) map.get("nodes"); for (Object node : nodes) { NodeRepresentationTest.verifySerialisation((Map<String, Object>) node); } assertThat(map, hasKey("start")); assertThat(map, hasKey("end")); assertThat(map, hasKey("length")); } }