Reformat.
This commit is contained in:
parent
9c67156f50
commit
67eb2db98d
|
@ -22,20 +22,20 @@ import java.io.IOException;
|
|||
|
||||
public class Neo4jAssertionExamples {
|
||||
|
||||
protected static GraphDatabaseService graphDB;
|
||||
protected static DragonBallGraph dragonBallGraph;
|
||||
protected static GraphDatabaseService graphDB;
|
||||
protected static DragonBallGraph dragonBallGraph;
|
||||
|
||||
@BeforeClass
|
||||
public static void prepare_graph() throws IOException {
|
||||
graphDB = new TestGraphDatabaseFactory().newImpermanentDatabase();
|
||||
dragonBallGraph = new DragonBallGraph(graphDB);
|
||||
dragonBallGraph.importGraph(
|
||||
Neo4jAssertionExamples.class.getResourceAsStream("/dragonBall.cypher")
|
||||
);
|
||||
}
|
||||
@BeforeClass
|
||||
public static void prepare_graph() throws IOException {
|
||||
graphDB = new TestGraphDatabaseFactory().newImpermanentDatabase();
|
||||
dragonBallGraph = new DragonBallGraph(graphDB);
|
||||
dragonBallGraph.importGraph(
|
||||
Neo4jAssertionExamples.class.getResourceAsStream("/dragonBall.cypher")
|
||||
);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
graphDB.shutdown();
|
||||
}
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
graphDB.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,52 +22,52 @@ import static org.assertj.neo4j.api.Assertions.assertThat;
|
|||
|
||||
public class NodeAssertionExamples extends Neo4jAssertionExamples {
|
||||
|
||||
@Test
|
||||
public void node_assertions_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the disciples of Master Roshi persisted in Neo4j
|
||||
Iterable<Node> disciples = dragonBallGraph.disciplesOf("Master Roshi");
|
||||
@Test
|
||||
public void node_assertions_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the disciples of Master Roshi persisted in Neo4j
|
||||
Iterable<Node> disciples = dragonBallGraph.disciplesOf("Master Roshi");
|
||||
|
||||
// you can enjoy the usual assertj-core assertions ;-)
|
||||
assertThat(disciples).hasSize(3);
|
||||
// you can enjoy the usual assertj-core assertions ;-)
|
||||
assertThat(disciples).hasSize(3);
|
||||
|
||||
// you can benefit from all PropertyContainer assertions
|
||||
// when you give a Node instance
|
||||
Node firstDisciple = disciples.iterator().next();
|
||||
assertThat(firstDisciple)
|
||||
.hasPropertyKey("name")
|
||||
.hasProperty("name", "Son Goku")
|
||||
.doesNotHavePropertyKey("firstName")
|
||||
.doesNotHaveProperty("name", "Bulma")
|
||||
// you can benefit from all PropertyContainer assertions
|
||||
// when you give a Node instance
|
||||
Node firstDisciple = disciples.iterator().next();
|
||||
assertThat(firstDisciple)
|
||||
.hasPropertyKey("name")
|
||||
.hasProperty("name", "Son Goku")
|
||||
.doesNotHavePropertyKey("firstName")
|
||||
.doesNotHaveProperty("name", "Bulma")
|
||||
|
||||
// you can test against node labels: their String representation or
|
||||
// the equivalent Label object
|
||||
.hasLabel("CHARACTER")
|
||||
.hasLabel(DynamicLabel.label("HERO"))
|
||||
.doesNotHaveLabel("VILLAIN")
|
||||
.doesNotHaveLabel(DynamicLabel.label("MASTER"));
|
||||
// you can test against node labels: their String representation or
|
||||
// the equivalent Label object
|
||||
.hasLabel("CHARACTER")
|
||||
.hasLabel(DynamicLabel.label("HERO"))
|
||||
.doesNotHaveLabel("VILLAIN")
|
||||
.doesNotHaveLabel(DynamicLabel.label("MASTER"));
|
||||
|
||||
// and you can enjoy the same error message mechanism from assertj-core !
|
||||
try {
|
||||
assertThat(firstDisciple)
|
||||
.as("[check %s's name]", firstDisciple.getProperty("name"))
|
||||
.doesNotHaveProperty("name", "Son Goku");
|
||||
}
|
||||
catch (AssertionError ae) {
|
||||
assertThat(ae).hasMessage("[[check Son Goku's name]] \n" +
|
||||
"Expecting:\n" +
|
||||
" <Node[0]>\n" +
|
||||
"not to have property with key:\n" +
|
||||
" <\"name\">\n" +
|
||||
"and value:\n" +
|
||||
" <\"Son Goku\">\n" +
|
||||
"but actually found such property ");
|
||||
}
|
||||
// and you can enjoy the same error message mechanism from assertj-core !
|
||||
try {
|
||||
assertThat(firstDisciple)
|
||||
.as("[check %s's name]", firstDisciple.getProperty("name"))
|
||||
.doesNotHaveProperty("name", "Son Goku");
|
||||
}
|
||||
catch (AssertionError ae) {
|
||||
assertThat(ae).hasMessage("[[check Son Goku's name]] \n" +
|
||||
"Expecting:\n" +
|
||||
" <Node[0]>\n" +
|
||||
"not to have property with key:\n" +
|
||||
" <\"name\">\n" +
|
||||
"and value:\n" +
|
||||
" <\"Son Goku\">\n" +
|
||||
"but actually found such property ");
|
||||
}
|
||||
|
||||
tx.close();
|
||||
tx.close();
|
||||
|
||||
// just check that we can use standard assertions along with Neo4j ones
|
||||
assertThat("hello world").startsWith("hello");
|
||||
}
|
||||
// just check that we can use standard assertions along with Neo4j ones
|
||||
assertThat("hello world").startsWith("hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,27 +22,27 @@ import static org.assertj.neo4j.api.Assertions.assertThat;
|
|||
|
||||
public class PathAssertionExamples extends Neo4jAssertionExamples {
|
||||
|
||||
@Test
|
||||
public void path_assertion_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the shortest path between Bulma and Master Roshi
|
||||
Path bulmaToMasterRoshiPath = dragonBallGraph.findShortestPathBetween("Bulma", "Master Roshi");
|
||||
@Test
|
||||
public void path_assertion_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the shortest path between Bulma and Master Roshi
|
||||
Path bulmaToMasterRoshiPath = dragonBallGraph.findShortestPathBetween("Bulma", "Master Roshi");
|
||||
|
||||
// you can test several Path properties such as length,
|
||||
// start/end node and last relationship
|
||||
final Node bulmaNode = dragonBallGraph.findCharacter("Bulma");
|
||||
final Node masterRoshiNode = dragonBallGraph.findCharacter("Master Roshi");
|
||||
final Relationship trainingFromSonGoku = dragonBallGraph.findTrainingFrom("Son Goku");
|
||||
assertThat(bulmaToMasterRoshiPath)
|
||||
.hasLength(3)
|
||||
.startsWithNode(bulmaNode)
|
||||
.endsWithNode(masterRoshiNode)
|
||||
.endsWithRelationship(trainingFromSonGoku)
|
||||
// you can test several Path properties such as length,
|
||||
// start/end node and last relationship
|
||||
final Node bulmaNode = dragonBallGraph.findCharacter("Bulma");
|
||||
final Node masterRoshiNode = dragonBallGraph.findCharacter("Master Roshi");
|
||||
final Relationship trainingFromSonGoku = dragonBallGraph.findTrainingFrom("Son Goku");
|
||||
assertThat(bulmaToMasterRoshiPath)
|
||||
.hasLength(3)
|
||||
.startsWithNode(bulmaNode)
|
||||
.endsWithNode(masterRoshiNode)
|
||||
.endsWithRelationship(trainingFromSonGoku)
|
||||
|
||||
// you can enjoy the usual assertj-core assertions (Path is an Iterable) ;-)
|
||||
.doesNotContainNull();
|
||||
.doesNotContainNull();
|
||||
|
||||
tx.close();
|
||||
}
|
||||
}
|
||||
tx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,80 +28,80 @@ import static org.assertj.neo4j.api.Assertions.assertThat;
|
|||
|
||||
public class RelationshipAssertionExamples extends Neo4jAssertionExamples {
|
||||
|
||||
@Test
|
||||
public void relationship_assertions_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the fusions between Dragon Ball characters persisted in Neo4j
|
||||
Iterable<Relationship> fusions = dragonBallGraph.fusions();
|
||||
@Test
|
||||
public void relationship_assertions_examples() {
|
||||
try (Transaction tx = graphDB.beginTx()) {
|
||||
// let us find the fusions between Dragon Ball characters persisted in Neo4j
|
||||
Iterable<Relationship> fusions = dragonBallGraph.fusions();
|
||||
|
||||
// you can enjoy the usual assertj-core assertions ;-)
|
||||
assertThat(fusions).hasSize(4);
|
||||
Iterable<Relationship> funnyFusions = filter(fusions, FUNNY_ONLY());
|
||||
assertThat(funnyFusions).hasSize(2);
|
||||
// you can enjoy the usual assertj-core assertions ;-)
|
||||
assertThat(fusions).hasSize(4);
|
||||
Iterable<Relationship> funnyFusions = filter(fusions, FUNNY_ONLY());
|
||||
assertThat(funnyFusions).hasSize(2);
|
||||
|
||||
// you can chain assertions on relationship types: their String representation
|
||||
// or the equivalent RelationshipType instance
|
||||
Iterator<Relationship> iterator = funnyFusions.iterator();
|
||||
Relationship veku = iterator.next();
|
||||
// you can chain assertions on relationship types: their String representation
|
||||
// or the equivalent RelationshipType instance
|
||||
Iterator<Relationship> iterator = funnyFusions.iterator();
|
||||
Relationship veku = iterator.next();
|
||||
|
||||
assertThat(veku)
|
||||
.hasType("IN_FUSION_WITH")
|
||||
.hasType(DynamicRelationshipType.withName("IN_FUSION_WITH"))
|
||||
.doesNotHaveType("HAS_WORKED_FOR")
|
||||
.doesNotHaveType(DynamicRelationshipType.withName("HAS_WORKED_FOR"));
|
||||
assertThat(veku)
|
||||
.hasType("IN_FUSION_WITH")
|
||||
.hasType(DynamicRelationshipType.withName("IN_FUSION_WITH"))
|
||||
.doesNotHaveType("HAS_WORKED_FOR")
|
||||
.doesNotHaveType(DynamicRelationshipType.withName("HAS_WORKED_FOR"));
|
||||
|
||||
// you can benefit from all PropertyContainer assertions
|
||||
// when you give a Relationship instance
|
||||
Relationship krillinPiccoloFusion = iterator.next();
|
||||
Node krillin = dragonBallGraph.findCharacter("Krillin");
|
||||
Node piccolo = dragonBallGraph.findCharacter("Piccolo");
|
||||
// you can benefit from all PropertyContainer assertions
|
||||
// when you give a Relationship instance
|
||||
Relationship krillinPiccoloFusion = iterator.next();
|
||||
Node krillin = dragonBallGraph.findCharacter("Krillin");
|
||||
Node piccolo = dragonBallGraph.findCharacter("Piccolo");
|
||||
|
||||
assertThat(krillinPiccoloFusion)
|
||||
.hasPropertyKey("into")
|
||||
.hasProperty("into", "Prilin")
|
||||
.hasProperty("useless", true)
|
||||
.doesNotHaveProperty("useless", false)
|
||||
.doesNotHavePropertyKey("name")
|
||||
assertThat(krillinPiccoloFusion)
|
||||
.hasPropertyKey("into")
|
||||
.hasProperty("into", "Prilin")
|
||||
.hasProperty("useless", true)
|
||||
.doesNotHaveProperty("useless", false)
|
||||
.doesNotHavePropertyKey("name")
|
||||
|
||||
// you can test relationship start/end nodes
|
||||
.startsOrEndsWithNode(krillin)
|
||||
.startsWithNode(krillin)
|
||||
.startsOrEndsWithNode(piccolo)
|
||||
.endsWithNode(piccolo);
|
||||
// you can test relationship start/end nodes
|
||||
.startsOrEndsWithNode(krillin)
|
||||
.startsWithNode(krillin)
|
||||
.startsOrEndsWithNode(piccolo)
|
||||
.endsWithNode(piccolo);
|
||||
|
||||
|
||||
// and you can enjoy the same error message mechanism from assertj-core !
|
||||
try {
|
||||
assertThat(veku).as("[check %s's start/end node]", veku.getProperty("into"))
|
||||
.startsOrEndsWithNode(krillin);
|
||||
}
|
||||
catch (AssertionError ae) {
|
||||
assertThat(ae).hasMessage("[[check Veku's start/end node]] \n" +
|
||||
"Expecting:\n" +
|
||||
" <Relationship[19]>\n" +
|
||||
"to either start or end with node:\n" +
|
||||
" <Node[6]>\n"
|
||||
);
|
||||
}
|
||||
// and you can enjoy the same error message mechanism from assertj-core !
|
||||
try {
|
||||
assertThat(veku).as("[check %s's start/end node]", veku.getProperty("into"))
|
||||
.startsOrEndsWithNode(krillin);
|
||||
}
|
||||
catch (AssertionError ae) {
|
||||
assertThat(ae).hasMessage("[[check Veku's start/end node]] \n" +
|
||||
"Expecting:\n" +
|
||||
" <Relationship[19]>\n" +
|
||||
"to either start or end with node:\n" +
|
||||
" <Node[6]>\n"
|
||||
);
|
||||
}
|
||||
|
||||
tx.close();
|
||||
}
|
||||
tx.close();
|
||||
}
|
||||
}
|
||||
|
||||
static class UselessFusion implements Predicate<Relationship> {
|
||||
|
||||
private UselessFusion() {}
|
||||
|
||||
public static UselessFusion FUNNY_ONLY() {
|
||||
return new UselessFusion();
|
||||
}
|
||||
|
||||
static class UselessFusion implements Predicate<Relationship> {
|
||||
|
||||
private UselessFusion() {}
|
||||
|
||||
public static UselessFusion FUNNY_ONLY() {
|
||||
return new UselessFusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Relationship input) {
|
||||
if (input == null) {
|
||||
return false;
|
||||
}
|
||||
return (boolean) input.getProperty("useless", Boolean.FALSE);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Relationship input) {
|
||||
if (input == null) {
|
||||
return false;
|
||||
}
|
||||
return (boolean) input.getProperty("useless", Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue