Add newly introduced ExecutionResultAssert example
This commit is contained in:
parent
a68a2ed45c
commit
9c67156f50
|
@ -14,6 +14,7 @@ package org.assertj.examples.data.neo4j;
|
||||||
|
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import org.neo4j.cypher.javacompat.ExecutionEngine;
|
import org.neo4j.cypher.javacompat.ExecutionEngine;
|
||||||
|
import org.neo4j.cypher.javacompat.ExecutionResult;
|
||||||
import org.neo4j.graphdb.*;
|
import org.neo4j.graphdb.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -50,14 +51,8 @@ public class DragonBallGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Node> disciplesOf(String masterName) {
|
public Iterable<Node> disciplesOf(String masterName) {
|
||||||
Map<String,Object> parameters = newHashMap();
|
|
||||||
parameters.put("name", masterName);
|
|
||||||
try (Transaction transaction = graphDB.beginTx();
|
try (Transaction transaction = graphDB.beginTx();
|
||||||
ResourceIterator<Node> nodes = cypherEngine.execute(
|
ResourceIterator<Node> nodes = discipleRowsOf(masterName).columnAs("disciples")) {
|
||||||
"MATCH (disciples:CHARACTER)-[:HAS_TRAINED_WITH]->(:MASTER {name: {name}}) " +
|
|
||||||
"RETURN disciples",
|
|
||||||
parameters
|
|
||||||
).columnAs("disciples")) {
|
|
||||||
|
|
||||||
Collection<Node> disciples = new LinkedList<>();
|
Collection<Node> disciples = new LinkedList<>();
|
||||||
while (nodes.hasNext()) {
|
while (nodes.hasNext()) {
|
||||||
|
@ -68,7 +63,18 @@ public class DragonBallGraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Relationship> fusions() {
|
public ExecutionResult discipleRowsOf(String masterName) {
|
||||||
|
Map<String, Object> parameters = newHashMap();
|
||||||
|
parameters.put("name", masterName);
|
||||||
|
|
||||||
|
return cypherEngine.execute(
|
||||||
|
"MATCH (disciples:CHARACTER)-[:HAS_TRAINED_WITH]->(:MASTER {name: {name}}) " +
|
||||||
|
"RETURN disciples",
|
||||||
|
parameters
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Relationship> fusions() {
|
||||||
try (Transaction transaction = graphDB.beginTx();
|
try (Transaction transaction = graphDB.beginTx();
|
||||||
ResourceIterator<Relationship> relationships = cypherEngine.execute(
|
ResourceIterator<Relationship> relationships = cypherEngine.execute(
|
||||||
"MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN fusions"
|
"MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN fusions"
|
||||||
|
@ -129,8 +135,8 @@ public class DragonBallGraph {
|
||||||
parameters.put("name", characterName);
|
parameters.put("name", characterName);
|
||||||
try (Transaction transaction = graphDB.beginTx();
|
try (Transaction transaction = graphDB.beginTx();
|
||||||
ResourceIterator<Relationship> relationships = cypherEngine.execute(
|
ResourceIterator<Relationship> relationships = cypherEngine.execute(
|
||||||
"MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training",
|
"MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training",
|
||||||
parameters
|
parameters
|
||||||
).columnAs("training")) {
|
).columnAs("training")) {
|
||||||
|
|
||||||
LinkedList<Relationship> trainings = new LinkedList<>();
|
LinkedList<Relationship> trainings = new LinkedList<>();
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
* Copyright 2012-2014 the original author or authors.
|
||||||
|
*/
|
||||||
|
package org.assertj.examples.neo4j;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.neo4j.cypher.javacompat.ExecutionResult;
|
||||||
|
import org.neo4j.graphdb.Transaction;
|
||||||
|
|
||||||
|
import static org.assertj.neo4j.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ExecutionResultAssertionExamples extends Neo4jAssertionExamples {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void execution_result_assertion_examples() {
|
||||||
|
try (Transaction tx = graphDB.beginTx()) {
|
||||||
|
// as in NodeAssertionExamples, let us find disciples of Master Roshi
|
||||||
|
// this time, however, the raw results will be returned
|
||||||
|
ExecutionResult result = dragonBallGraph.discipleRowsOf("Master Roshi");
|
||||||
|
|
||||||
|
// this is NOT an assertj-core assertion ;-)
|
||||||
|
assertThat(result).hasSize(3);
|
||||||
|
|
||||||
|
tx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue