-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathassertj-neo4j.html
254 lines (200 loc) · 12.2 KB
/
assertj-neo4j.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="AssertJ site">
<meta name="author" content="Joel Costigliola">
<title>AssertJ / Fluent assertions for java</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Inconsolata|Source+Code+Pro|Open+Sans|Ubuntu|Varela+Round|Karla">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet">
<script src="highlight/highlight.pack.js"></script>
<link rel="stylesheet" href="highlight/styles/railscasts.css">
<script>hljs.initHighlightingOnLoad();</script>
<link href="css/assertj.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.png" />
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- You'll want to use a responsive image option so this logo looks good on devices - I recommend using something like retina.js (do a quick Google search for it and you'll find it) -->
<a class="navbar-brand" href="index.html">AssertJ</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="assertj-core-quick-start.html">Quick start</a></li>
<li><a href="assertj-news.html">News</a></li>
<li><a href="assertj-core.html">Core</a></li>
<li><a href="assertj-assertions-generator.html">Assertions generator</a></li>
<li><a href="assertj-guava.html">Guava</a></li>
<li><a href="assertj-joda-time.html">Joda-Time</a></li>
<li><a href="assertj-db.html">DB</a></li>
<li><a href="assertj-neo4j.html">Neo4j</a></li>
<li><a href="assertj-swing.html">Swing</a></li>
<li><a href="assertj-help.html">Help</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-2 assertj-sidebar-menu">
<div class="bs-sidebar hidden-print affix-top" role="complementary">
<ul class="bs-sidenav nav ">
<li class="sidenav-header"></li>
<li><a href="assertj-neo4j.html">Overview</a></li>
<li><a href="assertj-neo4j.html#quickstart">Quick start</a></li>
<li><a href="assertj-neo4j.html#latest-release">Releases</a></li>
<li><a href="http://joel-costigliola.github.io/assertj/neo4j/api/index.html" target="_blank">Javadoc</a></li>
<li><a href="assertj-neo4j.html#mailing-list">Mailing list</a></li>
<li><a href="assertj-neo4j.html#code">Code & issues <i class="fa fa-github"></i></a></li>
<li><a href="assertj-neo4j.html#contributing">Contributing</a></li>
</ul>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-10 text-left">
<h1 class="page-header">AssertJ Neo4j assertions</h1>
<p>Provides assertions for <a href="http://www.neo4j.org/">Neo4j</a> 3 or higher.</p>
<p>This module have been written by <span class="contributor">Florent Biville</span>, huge thanks to him! Great Work!<br>
If you need additional assertions, just fill a ticket in <a href="https://github.com/joel-costigliola/assertj-neo4j/issues?labels=&milestone=&page=1&state=open">AssertJ Neo4j issue tracker</a>.</p>
<p>AssertJ Neo4j is hosted on github : <a href="https://github.com/joel-costigliola/assertj-neo4j">https://github.com/joel-costigliola/assertj-neo4j</a>.</p>
<h3 class="page-header"><span id="quickstart"></span>Neo4j assertions quickstart guide</h3>
<p>To quickly start using Neo4j assertions, follow the steps below.</p>
<h4 class="page-header">1 - Add assertj-neo4j dependency to your project pom.xml</h4>
<pre><code class="xml"><dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-neo4j</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency></code></pre>
<p>You also need to provide Neo4j 3+ dependencies.</p>
<p>If you use another dependency tool, please check this page to find the relevant <a href="http://search.maven.org/#artifactdetails|org.assertj|assertj-neo4j|2.0.1|bundle">assertj dependency declaration</a> for your tool.</p>
<h4 class="page-header">2 - Statically import <span class="small-code">org.assertj.neo4j.api.Assertions.assertThat</span> ...</h4>
<p>... and use your preferred IDE code completion after <span class="small-code">assertThat.</span></p>
<p>Example from <a href="https://github.com/joel-costigliola/assertj-examples/blob/master/assertions-examples/src/test/java/org/assertj/examples/neo4j/PathAssertionExamples.java">PathAssertionExamples.java</a> and <a href="https://github.com/joel-costigliola/assertj-examples/blob/master/assertions-examples/src/test/java/org/assertj/examples/neo4j/ResultAssertionExamples.java">ResultAssertionExamples.java</a>:</p>
<pre><code class="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"));
}</code></pre>
<p><span class="small-code">assertThat</span> and <span class="small-code">entry</span> are static imports from the <span class="small-code">Assertions</span> class.</p>
<p>Note that you can find more working examples in <a href="https://github.com/joel-costigliola/assertj-examples/blob/master/assertions-examples/src/test/java/org/assertj/examples/neo4j">neo4j package</a> of <a href="https://github.com/joel-costigliola/assertj-examples/">assertj-examples</a> project.</p>
<h3 class="page-header"><span id="latest-release"/></span><span id="2.0.1"/></span>Neo4j assertions 2.0.0 and 2.0.1 release</h3>
<p>Release date : 2017-10-05</p>
<p><strong>Neo4j required minimum version is now 3.0.0!</strong></p>
<div class="release-section-category">New assertions:</div>
<ul>
<li>Path assertions
<ul>
<li>doesNotStartWithNode</li>
<li>doesNotEndWithNode</li>
<li>doesNotEndWithRelationship</li>
</ul>
</li>
<li>Relationship assertions
<ul>
<li>doesNotStartWithNode</li>
<li>doesNotEndWithNode</li>
</ul>
</li>
<li>Result assertions</li>
</ul>
<h3 class="page-header"><span id="1.0.0"/></span>Neo4j assertions 1.0.0 release</h3>
<p>Release date : 2014-01-02</p>
<div class="release-section-category">Available assertions:</div>
<ul>
<li>Node assertions</li>
<li>Path assertions</li>
<li>Relationship assertions</li>
<li>PropertyContainer assertions</li>
</ul>
<h3 class="page-header"><span id="javadoc"/></span>Javadoc of latest release</h3>
<p>Latest javadoc release : <a href="http://joel-costigliola.github.io/assertj/neo4j/api/index.html">AssertJ Neo4j javadoc</a>.</p>
<h3 class="page-header"><span id="core-and-neo4j-assertions"/></span>Using both AssertJ <a href="https://github.com/joel-costigliola/assertj-core">Core assertions</a> and Neo4j assertions</h3>
<p>You will have to make two static imports: one for <span class="small-code">org.assertj.core.api.Assertions.assertThat</span>
to get core assertions and one <span class="small-code">org.assertj.neo4j.api.Assertions.assertThat</span> for neo4j assertions.</p>
<pre><code class="java">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");</code></pre>
<h3 class="page-header"><span id="mailing-list"/></span>Mailing list</h3>
<p>If you have any questions, please use
<a href="https://groups.google.com/forum/?fromgroups=#!forum/assertj">AssertJ google group</a>.</p>
<h3 class="page-header"><span id="code"/></span>Code and issue tracker</h3>
<p>AssertJ Neo4j is hosted on github : <a href="https://github.com/joel-costigliola/assertj-neo4j">https://github.com/joel-costigliola/assertj-neo4j</a>.</p>
<p>Please report bugs or missing features in <a href="https://github.com/joel-costigliola/assertj-neo4j/issues?labels=&milestone=&page=1&state=open">AssertJ Neo4j issue tracker</a>.</p>
<h3 class="page-header"><span id="contributing"/></span>Contributing</h3>
<p>Thanks for your interest! Please check our <a href="https://github.com/joel-costigliola/assertj-neo4j/blob/master/CONTRIBUTING.md#contributing">contributor's guidelines</a>.</p>
<p>Special thanks to <span class="contributor">Florent Biville</span> AssertJ Neo4j main contributor.</p>
</div>
</div>
</div>
<br>
<!--
<div class="container">
<footer>
<div class="row">
<div class="col-lg-12">
<p>AssertJ - Licensed under the Apache License, Version 2.0.</p>
</div>
</div>
</footer>
</div>
-->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/modern-business.js"></script>
<script src="js/assertj.js"></script>
</body>
</html>