Add newly introduced ExecutionResultAssert example

This commit is contained in:
Florent Biville 2014-01-24 13:38:14 +01:00
parent a68a2ed45c
commit 9c67156f50
2 changed files with 52 additions and 10 deletions

View File

@ -14,6 +14,7 @@ package org.assertj.examples.data.neo4j;
import com.google.common.io.CharStreams;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.*;
import java.io.IOException;
@ -50,14 +51,8 @@ public class DragonBallGraph {
}
public Iterable<Node> disciplesOf(String masterName) {
Map<String,Object> parameters = newHashMap();
parameters.put("name", masterName);
try (Transaction transaction = graphDB.beginTx();
ResourceIterator<Node> nodes = cypherEngine.execute(
"MATCH (disciples:CHARACTER)-[:HAS_TRAINED_WITH]->(:MASTER {name: {name}}) " +
"RETURN disciples",
parameters
).columnAs("disciples")) {
ResourceIterator<Node> nodes = discipleRowsOf(masterName).columnAs("disciples")) {
Collection<Node> disciples = new LinkedList<>();
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();
ResourceIterator<Relationship> relationships = cypherEngine.execute(
"MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN fusions"
@ -129,8 +135,8 @@ public class DragonBallGraph {
parameters.put("name", characterName);
try (Transaction transaction = graphDB.beginTx();
ResourceIterator<Relationship> relationships = cypherEngine.execute(
"MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training",
parameters
"MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training",
parameters
).columnAs("training")) {
LinkedList<Relationship> trainings = new LinkedList<>();

View File

@ -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();
}
}
}