AssertJ Neo4j assertions

Provides assertions for Neo4j 3 or higher.

This module have been written by Florent Biville, huge thanks to him! Great Work!
If you need additional assertions, just fill a ticket in AssertJ Neo4j issue tracker.

AssertJ Neo4j is hosted on github : https://github.com/joel-costigliola/assertj-neo4j.

Neo4j assertions quickstart guide

To quickly start using Neo4j assertions, follow the steps below.

1 - Add assertj-neo4j dependency to your project pom.xml

<dependency>
 <groupId>org.assertj</groupId>
 <artifactId>assertj-neo4j</artifactId>
 <version>2.0.1</version>
 <scope>test</scope>
</dependency>

You also need to provide Neo4j 3+ dependencies.

If you use another dependency tool, please check this page to find the relevant assertj dependency declaration for your tool.

2 - Statically import org.assertj.neo4j.api.Assertions.assertThat ...

... and use your preferred IDE code completion after assertThat.

Example from PathAssertionExamples.java and ResultAssertionExamples.java:

import static org.assertj.neo4j.api.Assertions.assertThat;
try (Transaction ignored = graphDatabaseService.beginTx()) {
 // path assertion example
 Node tienShinhan = dragonBallGraph.findUniqueCharacter("Tien Shinhan");
 Node doctorGero = dragonBallGraph.findUniqueCharacter("Dr. Gero");
 Node bulmaNode = dragonBallGraph.findUniqueCharacter("Bulma");
 Node masterRoshiNode = dragonBallGraph.findCharacter("Master Roshi");
 Relationship masterShenTraining = dragonBallGraph.findUniqueTraining("Master Shen");
 Relationship trainingFromSonGoku = dragonBallGraph.findUniqueTraining("Son Goku");
 Path bulmaToMasterRoshiPath = dragonBallGraph.findShortestPathBetween(
 "Bulma",
 "Master Roshi");
 /*
 * You can test several Path properties such as:
 * - length
 * - start/end node
 * - last relationship
 */
 assertThat(bulmaToMasterRoshiPath).hasLength(3)
 .startsWithNode(bulmaNode)
 .endsWithNode(masterRoshiNode)
 .endsWithRelationship(trainingFromSonGoku)
 .doesNotStartWithNode(doctorGero)
 .doesNotEndWithNode(tienShinhan)
 .doesNotEndWithRelationship(masterShenTraining);
 /*
 * Cypher execution result (of Result type) is just an iterable of Map<String, Object>
 * ResultAssertion is just a convenient wrapper of the usual Map assertions :)
 */
 Result result = graphDatabaseService.execute(
 "MATCH (character:Character) " +
 "WHERE character.name =~ 'Master.*' " +
 "RETURN character.name AS name ORDER BY name ASC");
 assertThat(result).hasSize(3)
 .doesNotContainNull()
 .containsExactly(Maps.newHashMap("name", "Master Mutaito"),
 Maps.newHashMap("name", "Master Roshi"),
 Maps.newHashMap("name", "Master Shen"));
}

assertThat and entry are static imports from the Assertions class.

Note that you can find more working examples in neo4j package of assertj-examples project.

Neo4j assertions 2.0.0 and 2.0.1 release

Release date : 2017年10月05日

Neo4j required minimum version is now 3.0.0!

New assertions:
  • Path assertions
    • doesNotStartWithNode
    • doesNotEndWithNode
    • doesNotEndWithRelationship
  • Relationship assertions
    • doesNotStartWithNode
    • doesNotEndWithNode
  • Result assertions

Neo4j assertions 1.0.0 release

Release date : 2014年01月02日

Available assertions:
  • Node assertions
  • Path assertions
  • Relationship assertions
  • PropertyContainer assertions

Javadoc of latest release

Latest javadoc release : AssertJ Neo4j javadoc.

Using both AssertJ Core assertions and Neo4j assertions

You will have to make two static imports: one for org.assertj.core.api.Assertions.assertThat to get core assertions and one org.assertj.neo4j.api.Assertions.assertThat for neo4j assertions.

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.neo4j.api.Assertions.assertThat;
// initialization omitted for brevity ...
Node firstDisciple = ...;
// assertThat comes from org.assertj.neo4j.api.Assertions.assertThat static import
assertThat(firstDisciple).hasPropertyKey("name")
 .hasProperty("name", "Son Goku")
 .doesNotHavePropertyKey("firstName")
 .doesNotHaveProperty("name", "Bulma");
// assertThat comes from org.assertj.core.api.Assertions.assertThat static import
assertThat("hello world").startsWith("hello");

Mailing list

If you have any questions, please use AssertJ google group.

Code and issue tracker

AssertJ Neo4j is hosted on github : https://github.com/joel-costigliola/assertj-neo4j.

Please report bugs or missing features in AssertJ Neo4j issue tracker.

Contributing

Thanks for your interest! Please check our contributor's guidelines.

Special thanks to Florent Biville AssertJ Neo4j main contributor.


AltStyle によって変換されたページ (->オリジナル) /