Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assertions-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-db</artifactId>
<version>1.1.1</version>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.sql.Connection;
import java.sql.SQLException;

import org.assertj.db.type.AssertDbConnection;
import org.assertj.db.type.AssertDbConnectionFactory;
import org.h2.jdbcx.JdbcConnectionPool;
import org.junit.jupiter.api.BeforeEach;

Expand All @@ -23,10 +25,12 @@
* Init data for assertions examples.
*
* @author Régis Pouiller
* @author Julien Roy
*/
public class AbstractAssertionsExamples {

protected static JdbcConnectionPool dataSource;
protected static AssertDbConnection assertConnection;

private static final String MEMBERS_CREATE_REQUEST = "create table members(id number primary key, name varchar not null, firstname varchar not null, surname varchar, birthdate date, size decimal);";
private static final String[] MEMBERS_INSERT_REQUESTS = {
Expand Down Expand Up @@ -58,6 +62,7 @@ public class AbstractAssertionsExamples {
public void setUp() throws SQLException {
if (dataSource == null) {
dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "user", "password");
assertConnection = AssertDbConnectionFactory.of(dataSource).create();
}
else {
Connection conn = dataSource.getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* {@link Changes} assertions example.
*
* @author Régis Pouiller
* @author Julien Roy
*/
public class ChangesAssertionExamples extends AbstractAssertionsExamples {

Expand All @@ -39,7 +40,7 @@ public class ChangesAssertionExamples extends AbstractAssertionsExamples {
*/
@Test
public void basic_changes_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -58,7 +59,7 @@ public void basic_changes_assertion_examples() throws SQLException {
*/
@Test
public void basic_change_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -92,7 +93,7 @@ public void basic_change_assertion_examples() throws SQLException {
*/
@Test
public void basic_row_assertion_examples() throws SQLException, ParseException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -128,7 +129,7 @@ public void basic_row_assertion_examples() throws SQLException, ParseException {
*/
@Test
public void basic_column_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -166,7 +167,7 @@ public void basic_column_assertion_examples() throws SQLException {
*/
@Test
public void basic_value_assertion_examples() throws SQLException, ParseException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -193,8 +194,7 @@ public void basic_value_assertion_examples() throws SQLException, ParseException
*/
@Test
public void changes_about_table_assertion_examples() throws SQLException {
Table table = new Table(dataSource, "members");
Changes changes = new Changes(table);
Changes changes = assertConnection.changes().table("members").build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -211,8 +211,7 @@ public void changes_about_table_assertion_examples() throws SQLException {
*/
@Test
public void changes_about_request_assertion_examples() throws SQLException {
Request request = new Request(dataSource, "select title from albums");
Changes changes = new Changes(request);
Changes changes = assertConnection.changes().request("select title from albums").build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -227,7 +226,7 @@ public void changes_about_request_assertion_examples() throws SQLException {
*/
@Test
public void changetype_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -243,7 +242,7 @@ public void changetype_assertion_examples() throws SQLException {
*/
@Test
public void datatype_isontable_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -258,9 +257,8 @@ public void datatype_isontable_assertion_examples() throws SQLException {
* This example shows a simple case of test on data type for change on a request.
*/
@Test
public void datatype_isonrequest_assertion_examples() throws SQLException {
Request request = new Request(dataSource, "select title from albums");
Changes changes = new Changes(request);
public void datatype_is_on_request_assertion_examples() throws SQLException {
Changes changes = assertConnection.changes().request("select title from albums").build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand All @@ -274,7 +272,7 @@ public void datatype_isonrequest_assertion_examples() throws SQLException {
*/
@Test
public void column_equality_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -304,8 +302,8 @@ public void column_equality_assertion_examples() throws SQLException {
*/
@Test
public void changes_number_assertion_examples() throws SQLException {
Changes changesDataSource = new Changes(dataSource).setStartPointNow();
Changes changesRequest = new Changes(new Request(dataSource, "select title from albums"));
Changes changesDataSource = assertConnection.changes().build().setStartPointNow();
Changes changesRequest = assertConnection.changes().request("select title from albums").build();
changesRequest.setStartPointNow();
makeChangesInTheData();
changesDataSource.setEndPointNow();
Expand All @@ -320,7 +318,7 @@ public void changes_number_assertion_examples() throws SQLException {
*/
@Test
public void columns_number_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand All @@ -339,7 +337,7 @@ public void columns_number_assertion_examples() throws SQLException {
*/
@Test
public void primary_keys_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand All @@ -354,7 +352,7 @@ public void primary_keys_assertion_examples() throws SQLException {
*/
@Test
public void modified_columns_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand All @@ -378,7 +376,7 @@ public void modified_columns_assertion_examples() throws SQLException {
*/
@Test
public void column_type_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -408,7 +406,7 @@ public void column_type_assertion_examples() throws SQLException {
*/
@Test
public void modified_column_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -442,7 +440,7 @@ public void modified_column_assertion_examples() throws SQLException {
*/
@Test
public void column_name_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();
Expand Down Expand Up @@ -483,7 +481,7 @@ public void column_name_assertion_examples() throws SQLException {
*/
@Test
public void row_existence_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand All @@ -504,7 +502,7 @@ public void row_existence_assertion_examples() throws SQLException {
*/
@Test
public void row_equality_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand All @@ -523,7 +521,7 @@ public void row_equality_assertion_examples() throws SQLException {
*/
@Test
public void value_equality_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down Expand Up @@ -601,7 +599,7 @@ public void value_equality_assertion_examples() throws SQLException {
*/
@Test
public void value_non_equality_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down Expand Up @@ -679,7 +677,7 @@ public void value_non_equality_assertion_examples() throws SQLException {
*/
@Test
public void value_type_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down Expand Up @@ -757,7 +755,7 @@ public void value_type_assertion_examples() throws SQLException {
*/
@Test
public void value_nullity_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down Expand Up @@ -842,7 +840,7 @@ public void value_nullity_assertion_examples() throws SQLException {
*/
@Test
public void value_comparison_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down Expand Up @@ -936,7 +934,7 @@ public void value_comparison_assertion_examples() throws SQLException {
*/
@Test
public void value_chronology_assertion_examples() throws SQLException {
Changes changes = new Changes(dataSource).setStartPointNow();
Changes changes = assertConnection.changes().build().setStartPointNow();
makeChangesInTheData();
changes.setEndPointNow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Examples of navigation for a table, a request and changes
*
* @author Régis Pouiller
*
* @author Julien Roy
*/
public class NavigationExamples extends AbstractAssertionsExamples {

Expand All @@ -35,7 +35,7 @@ public class NavigationExamples extends AbstractAssertionsExamples {
*/
@Test
public void basic_navigation_examples_for_a_table() {
Table table = new Table(dataSource, "members");
Table table = assertConnection.table("members").build();

assertThat(table)
.row() // First row
Expand Down Expand Up @@ -87,7 +87,7 @@ public void basic_navigation_examples_for_a_table() {
*/
@Test
public void basic_navigation_examples_for_a_request() {
Request request = new Request(dataSource, "select * from members");
Request request = assertConnection.request("select * from members").build();

assertThat(request)
.row() // First row
Expand Down Expand Up @@ -139,7 +139,7 @@ public void basic_navigation_examples_for_a_request() {
*/
@Test
public void basic_navigation_examples_for_changes() throws SQLException {
Changes changes = new Changes(dataSource);
Changes changes = assertConnection.changes().build();
changes.setStartPointNow(); // Start point (the moment when the changes start to be taken into account)
makeChangesInTheData();
changes.setEndPointNow(); // End point (the moment when the changes stop to be taken into account)
Expand Down
Loading