-
Notifications
You must be signed in to change notification settings - Fork 30
/
assertj-db.html
282 lines (238 loc) · 15 KB
/
assertj-db.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!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-db.html">Overview</a></li>
<li><a href="assertj-db.html#quickstart">Quick start</a></li>
<li><a href="assertj-db-news.html">News & releases</a></li>
<li><a href="assertj-db-concepts.html">Concepts</a></li>
<li><a href="assertj-db-features-highlight.html">Features highlight</a></li>
<li><a href="https://www.javadoc.io/doc/org.assertj/assertj-db/latest/index.html" target="_blank">Javadoc</a></li>
<li><a href="assertj-db.html#mailing-list">Mailing list</a></li>
<li><a href="assertj-db.html#code">Code & issues <i class="fa fa-github"></i></a></li>
<li><a href="assertj-db.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-DB assertions</h1>
<h2 style="color:darkblue;font-style: italic;"><u>AssertJ-DB site has moved to <a href="https://assertj.github.io/doc/#assertj-db">https://assertj.github.io/doc/</a></u></h2>
<img src="images/assertj-db_icon.png" height="60%" width="60%" />
<p>AssertJ-DB provides assertions to test data in a database.
It requires Java 7 or later and can be used with either JUnit or TestNG.
</p>
<p>If you need additional assertions, please create a ticket in the <a href="https://github.com/assertj/assertj-db/issues?labels=&milestone=&page=1&state=open">AssertJ-DB issue tracker</a>.</p>
<p>AssertJ-DB is hosted on github : <a href="https://github.com/assertj/assertj-db">https://github.com/assertj/assertj-db</a>.<br/>
</p>
<p>
Big thanks to <span class="contributor">Joel Costigliola</span>
for his welcome, for his help and for having accepted to associate this project with a great project like AssertJ.
</p>
<i>Régis Pouiller (AssertJ-DB creator)</i>
<h3 class="page-header"><span id="quickstart"></span>DataBase assertions quickstart guide</h3>
<p>Suppose that the database contains this table :</p>
<table border="5" cellspacing="0" cellpadding="2">
<caption style="font-size:70%">MEMBERS</caption>
<tr>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">ID</th>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">NAME</th>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">FIRSTNAME</th>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">SURNAME</th>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">BIRTHDATE</th>
<th style="text-align:center;font-family:courier;font-size:90%;background-color:white;">SIZE</th>
</tr>
<tr>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">1</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Hewson'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Paul David'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Bono'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">05-10-60</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">1.75</td>
</tr>
<tr>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">2</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Evans'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'David Howell'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'The Edge'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">08-08-61</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">1.77</td>
</tr>
<tr>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">3</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Clayton'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Adam'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;"> </td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">03-13-60</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">1.78</td>
</tr>
<tr>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">4</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Mullen'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">'Larry'</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;"> </td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">10-31-61</td>
<td style="text-align:center;font-family:courier;font-size:80%;background-color:white;">1.70</td>
</tr>
</table>
<p>To quickly start using DataBase assertions, follow the steps below.</p>
<h4 class="page-header">1 - Add the assertj-db dependency to your project pom.xml.</h4>
<pre><code class="xml"><dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-db</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency></code></pre>
<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-db|1.1.1|bundle">assertj-db dependency declaration</a> for your tool.</p>
<h4 class="page-header">2 - Statically import <span class="small-code">org.assertj.db.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/db/TableAssertionExamples.java">TableAssertionExamples.java</a> :</p>
<pre><code class="java">import static org.assertj.db.api.Assertions.assertThat;
import org.assertj.db.type.DateValue;
import org.assertj.db.type.Table;
Table table = new Table(dataSource, "members");
// Check column "name" values
assertThat(table).column("name")
.value().isEqualTo("Hewson")
.value().isEqualTo("Evans")
.value().isEqualTo("Clayton")
.value().isEqualTo("Mullen");
// Check row at index 1 (the second row) values
assertThat(table).row(1)
.value().isEqualTo(2)
.value().isEqualTo("Evans")
.value().isEqualTo("David Howell")
.value().isEqualTo("The Edge")
.value().isEqualTo(DateValue.of(1961, 8, 8))
.value().isEqualTo(1.77);</code></pre>
<p>In this simple example you can see many <a href="assertj-db-concepts.html">concepts of AssertJ-DB</a> (the concepts are simple but I advice you to take the time to get to know them well) :</p>
<ul>
<li><a href="assertj-db-concepts.html#elements">the elements</a> :
<ul>
<li><a href="assertj-db-concepts.html#table">Table</a> which represents a table in the database</li>
<li><a href="assertj-db-concepts.html#column">Column</a> which represents a column of the table</li>
<li><a href="assertj-db-concepts.html#row">Row</a> which represents a row of the table</li>
<li><a href="assertj-db-concepts.html#value">Value</a> which represents a value in a column or in a row</li>
</ul
</li>
<li><a href="assertj-db-concepts.html#tableorrequestasroot">the navigation</a> :
<ul>
<li>The first check, navigates from the table to the column called "name"
(<code>column("name")</code> moves the assertion to the column),
from this column to the first value (the first call of <code>value()</code> moves to the first value)
and after that to each value (each call of <code>value()</code> moves to the next value of the column).
</li>
<li>
The second check, navigates from the table to the row with index 1
(<code>row(1)</code> moves the assertion to the row),
from this row to the first value
and after that to each value (<code>value()</code> calls have similar behavior for rows and columns).
</li>
</ul>
</li>
<li><a href="assertj-db-concepts.html#datevalue-timevalue-datetimevalue">DateValue</a> :
AssertJ-DB works with Java7. So AssertJ-DB provides way to easily compare values with date, time and date/time.
</li>
</ul>
<h3 class="page-header"><span id="latest-release"/></span>Latest release : 1.3.0</h3>
<p>Release date : 2019-12-26 (<a href="http://search.maven.org/#artifactdetails|org.assertj|assertj-db|1.3.0|bundle">dependency declaration</a>)</p>
<div class="release-section-category">Improvements :</div>
<ul>
<li><a href="https://github.com/assertj/assertj-db/issues/58">issue #58</a> : Implement SoftAssertions</li>
<li><a href="https://github.com/assertj/assertj-db/issues/57">issue #57</a> : Implement condition assertions</li>
<li><a href="https://github.com/assertj/assertj-db/issues/12">issue #12</a> : Implement assertions on table existence</li>
</ul>
<div class="release-section-category">Bug fixes :</div>
<ul>
<li><a href="https://github.com/assertj/assertj-db/issues/62">issue #62</a> : Fix close-to when tolerance exceed 60 seconds</li>
</ul>
<h3 class="page-header"><span id="javadoc"/></span>Javadoc of latest release</h3>
<p>Latest javadoc release : <a href="https://www.javadoc.io/doc/org.assertj/assertj-db/latest/index.html">AssertJ DB javadoc</a>.</p>
<h3 class="page-header">Want to see more ?</h3>
<p>
See some of <a href="assertj-db-features-highlight.html">AssertJ-DB noteworthy features</a> to get the maximum of it !
</p>
<p>
You can learn more by looking at the <a href="https://www.javadoc.io/doc/org.assertj/assertj-db/latest/index.html">AssertJ-DB javadoc</a>.
</p>
<p>
Another way is to take a look at the <a href="https://github.com/joel-costigliola/assertj-examples/tree/master/assertions-examples/src/test/java/org/assertj/examples/db">assertj-db-examples tests</a>. They show what is possible with AssertJ DB Assertions with running code. You can clone the repository and run its tests !
</p>
<h3 class="page-header"><span id="mailing-list"/></span>Mailing list</h3>
<p>If you have any questions, please use the
<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-DB is hosted on github : <a href="https://github.com/assertj/assertj-db">https://github.com/assertj/assertj-db</a>.</p>
<p>Please report bugs or missing features in the <a href="https://github.com/assertj/assertj-db/issues?labels=&milestone=&page=1&state=open">AssertJ-DB 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/assertj/assertj-db/blob/master/CONTRIBUTING.md#contributing">contributor's guidelines</a>.</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>