Skip to content

Commit 3fd9ae4

Browse files
committed
Docs migration to Antora
1 parent c472192 commit 3fd9ae4

File tree

47 files changed

+2866
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2866
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![alt tag](img/assertj-db_icon.png)
1+
![alt tag](src/main/docs/modules/ROOT/images/assertj-db_icon.png)
22
AssertJ-DB - Assertions for database
33
==========
44

src/main/docs/antora.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: assertj-db
2+
title: AssertJ DB
3+
nav:
4+
- modules/ROOT/nav.adoc
5+
ext:
6+
collector:
7+
scan:
8+
dir: src/test/java/org/example/db
9+
into: modules/ROOT/examples
10+
asciidoc:
11+
attributes:
12+
project-description: 'Provide assertions for Guava types (Multimap, Optional, ...)'
Loading

src/main/docs/modules/ROOT/nav.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
* xref:index.adoc[]
2+
* xref:quickstart.adoc[]
3+
* xref:concepts/index.adoc[]
4+
** xref:concepts/connection.adoc[Connection]
5+
** xref:concepts/elements.adoc[Elements]
6+
** xref:concepts/types.adoc[]
7+
** xref:concepts/navigation.adoc[]
8+
** xref:concepts/datetime.adoc[Date Time]
9+
** xref:concepts/description.adoc[Description]
10+
** xref:concepts/letter-case.adoc[Letter Case]
11+
** xref:concepts/output.adoc[]
12+
* xref:features/index.adoc[]
13+
** xref:features/navigation.adoc[]
14+
** xref:features/assertions.adoc[]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
= Connection to the database
2+
3+
To make assertions on a database, it is necessary to connect. The concept of `AssertDbConnection` represent how
4+
AssertJ-DB can retrieve data and schema information from database.
5+
6+
It's also with a `AssertDbConnection` that you can instantiate the following element : `Table`, `Request`, `Changes`.
7+
8+
[[AssertDbConnection]]
9+
== AssertDbConnection
10+
11+
A https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/AssertDbConnection.html[AssertDbConnection]
12+
is created with the factory https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/AssertDbConnectionFactory.html[AssertDbConnectionFactory].
13+
14+
There are 2 way to begin the AssertDbConnectionFactory, with a http://docs.oracle.com/javase/6/docs/api/javax/sql/DataSource.html[DataSource] ( the classic Java way
15+
to get a http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html[Connection] to a database ) or with JDBC connection information.
16+
17+
Below is an example of using a DataSource to connect to H2 in memory database :
18+
19+
[source,java]
20+
----
21+
AssertDbConnection connection = AssertDbConnectionFactory.of("jdbc:h2:mem:test", "sa", "").create();
22+
----
23+
24+
And using a DataSource to connect :
25+
26+
[source,java]
27+
----
28+
AssertDbConnection connection = AssertDbConnectionFactory.of(dataSource).create();
29+
----
30+
31+
== LetterCase setup
32+
33+
https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/AssertDbConnectionFactory.html[AssertDbConnectionFactory]
34+
provide the capacity to indicate the https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/lettercase/LetterCase.html[LetterCase]
35+
to use for the tables, columns and primary keys.
36+
37+
[source,java]
38+
----
39+
AssertDbConnection connection = AssertDbConnectionFactory
40+
.of(dataSource)
41+
.letterCase(tableLetterCase, columnLetterCase, pkLetterCase)
42+
.create();
43+
----
44+
45+
For more information, see the <<assertj-db-concepts-dblettercase,paragraph on LetterCase>>.
46+
47+
== Schema retrieval mode
48+
49+
For many assertions, AssertJ-DB require to discover database schema metadata ( list of tables, columns, ... ).
50+
When the schema contains many tables this operation can slow down the tests executions.
51+
52+
To avoid that and when the database schema is not updated during the test session, you can use the option
53+
https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/SchemaMetaDataMode.html[SchemaMetaDataMode] of
54+
https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/AssertDbConnectionFactory.html[AssertDbConnectionFactory]
55+
to keep in memory the schema.
56+
57+
Available mode are :
58+
59+
- DYNAMIC ( default ): Retrieve schema metadata each time is required.
60+
- STATIC : Retrieve schema metadata only once and keep in memory for all duration of connection.
61+
62+
Below is an example of using the STATIC mode for a connection :
63+
64+
[source,java]
65+
----
66+
AssertDbConnection connection = AssertDbConnectionFactory.of(dataSource)
67+
.schemaMetaDataMode(SchemaMetaDataMode.STATIC)
68+
.create();
69+
----
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
= DateValue, TimeValue and DateTimeValue
2+
3+
The preferred way to compare values with date, time and date/time is to use java.time.LocalDate, java.time.LocalTime, java.time.LocalDateTime directly.
4+
5+
But for the backward compatibility, it's always possible to use AssertJ-DB DateValue utilities.
6+
7+
So The https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/DateValue.html[DateValue],
8+
https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/TimeValue.html[TimeValue] and
9+
https://www.javadoc.io/doc/org.assertj/assertj-db/latest/org/assertj/db/type/DateTimeValue.html[DateTimeValue] classes are simpler but contains this kind of information.
10+
11+
There is 4 kinds of static methods to instantiate these values :
12+
13+
* `of` which receives the information as `int` parameters
14+
15+
[source,java]
16+
----
17+
DateValue dateValue = DateValue.of(2007, 12, 23);
18+
19+
// With hours and minutes only
20+
TimeValue timeValue1 = TimeValue.of(9, 1);
21+
// With seconds additional
22+
TimeValue timeValue2 = TimeValue.of(9, 1, 6);
23+
// With nanoseconds additional
24+
TimeValue timeValue3 = TimeValue.of(9, 1, 6, 3);
25+
26+
// With date only (so hour is midnight)
27+
DateTimeValue dateTimeValue1 = DateTimeValue.of(dateValue);
28+
// With date and time
29+
DateTimeValue dateTimeValue2 = DateTimeValue.of(dateValue, timeValue1);
30+
----
31+
32+
* `from` which receives the equivalent from `java.sql` package (`java.sql.Date`, `java.sql.Time` and `java.sql.Timestamp`)
33+
or a `java.util.Calendar`
34+
35+
[source,java]
36+
----
37+
Date date = Date.valueOf("2007-12-23");
38+
DateValue dateValue = DateValue.from(date);
39+
40+
Time time = Time.valueOf("09:01:06");
41+
TimeValue timeValue = TimeValue.from(time);
42+
43+
Timestamp timestamp = Timestamp.valueOf("2007-12-23 09:01:06.000000003");
44+
DateTimeValue dateTimeValue = DateTimeValue.from(timestamp);
45+
46+
Calendar calendar = Calendar.getInstance();
47+
DateValue dateValueFromCal = DateValue.from(calendar);
48+
TimeValue timeValueFromCal = TimeValue.from(calendar);
49+
DateTimeValue dateTimeValueFromCal = DateTimeValue.from(calendar);
50+
----
51+
52+
* `parse` which receives a `String` to represent the value (this method can throw a `ParseException`)
53+
54+
[source,java]
55+
----
56+
DateValue dateValue = DateValue.parse("2007-12-23");
57+
58+
// With hours and minutes only
59+
TimeValue timeValue1 = TimeValue.parse("09:01");
60+
// With seconds additional
61+
TimeValue timeValue2 = TimeValue.parse("09:01:06");
62+
// With nanoseconds additional
63+
TimeValue timeValue3 = TimeValue.parse("09:01:06.000000003");
64+
65+
// With date only (so hour is midnight)
66+
DateTimeValue dateTimeValue1 = DateTimeValue.parse("2007-12-23");
67+
// With date and time (hours and minutes only)
68+
DateTimeValue dateTimeValue2 = DateTimeValue.parse("2007-12-23T09:01");
69+
// With date and time (seconds additional)
70+
DateTimeValue dateTimeValue2 = DateTimeValue.parse("2007-12-23T09:01:06");
71+
// With date and time (nanoseconds additional)
72+
DateTimeValue dateTimeValue2 = DateTimeValue.parse("2007-12-23T09:01:06.000000003");
73+
----
74+
75+
* `now` which create an instance corresponding to the current moment.
76+
77+
[source,java]
78+
----
79+
DateValue dateValue = DateValue.now(); // The current date
80+
TimeValue timeValue = TimeValue.now(); // The current time
81+
DateTimeValue dateTimeValue = DateTimeValue.now(); // The current date/time
82+
----
83+
84+
All these static methods (except for `now` method) have equivalent constructors.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
= Default description
2+
3+
In assertj, it is possible to add a description with the methods of the https://www.javadoc.io/doc/org.assertj/assertj-core/latest/org/assertj/core/api/Descriptable.html[Descriptable] interface.
4+
This description is used in the error message if the assertion fails.
5+
6+
Due to the navigation, it is more complicated in assertj-db to know on which element an error is thrown.
7+
So to help the tester, there are default descriptions.
8+
9+
For example :
10+
11+
* `"members table"` for an assertion on a table
12+
* `"'select * from actor' request"` for an assertion on a request
13+
* `"'select id, name, firstname, bi...' request"` for an assertion on a request with more text
14+
* `"Row at index 0 of members table"` for an assertion on a row of a table
15+
* `"Column at index 0 (column name : ID) of 'select * from members' request"` for an assertion on a column of a request
16+
* `"Value at index 0 of Column at index 0 (column name : ID) of 'select * from members' request"` for an assertion on a value of a column of a request
17+
* `"Value at index 0 (column name : ID) of Row at index 0 of 'select * from members' request"` for an assertion on a value of a row of a request
18+
* `"Value at index 0 (column name : ID) of Row at end point of Change at index 0 (on table : MEMBERS and with primary key : [4]) of Changes on tables of 'sa/jdbc:h2:mem:test' source"`
19+
for an assertion on a value of the row at end point of a change on a table
20+
21+
This default description can be replaced by the choice of the tester by using the methods of https://www.javadoc.io/doc/org.assertj/assertj-core/latest/org/assertj/core/api/Descriptable.html[Descriptable].

0 commit comments

Comments
 (0)