18
18
import static org .assertj .core .api .Assertions .*;
19
19
import static org .springframework .data .domain .Sort .Order .*;
20
20
21
- import io .r2dbc .postgresql .PostgresqlConnectionConfiguration ;
22
- import io .r2dbc .postgresql .PostgresqlConnectionFactory ;
23
21
import io .r2dbc .spi .ConnectionFactory ;
24
22
import lombok .Data ;
25
23
import reactor .core .publisher .Hooks ;
26
24
import reactor .test .StepVerifier ;
27
25
28
26
import org .junit .Before ;
29
- import org .junit .ClassRule ;
30
27
import org .junit .Test ;
31
- import org .postgresql .ds .PGSimpleDataSource ;
32
28
import org .springframework .data .domain .PageRequest ;
33
29
import org .springframework .data .domain .Sort ;
34
- import org .springframework .data .jdbc .core .function .ExternalDatabase .ProvidedDatabase ;
35
30
import org .springframework .data .jdbc .core .mapping .Table ;
31
+ import org .springframework .data .jdbc .testing .R2dbcIntegrationTestSupport ;
36
32
import org .springframework .jdbc .core .JdbcTemplate ;
37
33
38
34
/**
39
35
* Integration tests for {@link DatabaseClient} against PostgreSQL.
40
36
*
41
37
* @author Mark Paluch
42
38
*/
43
- public class DatabaseClientIntegrationTests {
44
-
45
- /**
46
- * Local test database at {@code postgres:@localhost:5432/postgres}.
47
- */
48
- @ ClassRule public static final ExternalDatabase database = ProvidedDatabase .builder ().hostname ("localhost" ).port (5432 )
49
- .database ("postgres" ).username ("postgres" ).password ("" ).build ();
39
+ public class DatabaseClientIntegrationTests extends R2dbcIntegrationTestSupport {
50
40
51
41
private ConnectionFactory connectionFactory ;
52
42
@@ -57,22 +47,13 @@ public void before() {
57
47
58
48
Hooks .onOperatorDebug ();
59
49
60
- connectionFactory = new PostgresqlConnectionFactory (
61
- PostgresqlConnectionConfiguration .builder ().host (database .getHostname ()).database (database .getDatabase ())
62
- .username (database .getUsername ()).password (database .getPassword ()).build ());
63
-
64
- PGSimpleDataSource dataSource = new PGSimpleDataSource ();
65
- dataSource .setUser (database .getUsername ());
66
- dataSource .setPassword (database .getPassword ());
67
- dataSource .setDatabaseName (database .getDatabase ());
68
- dataSource .setServerName (database .getHostname ());
69
- dataSource .setPortNumber (database .getPort ());
50
+ connectionFactory = createConnectionFactory ();
70
51
71
52
String tableToCreate = "CREATE TABLE IF NOT EXISTS legoset (\n "
72
53
+ " id integer CONSTRAINT id PRIMARY KEY,\n " + " name varchar(255) NOT NULL,\n "
73
54
+ " manual integer NULL\n " + ");" ;
74
55
75
- jdbc = new JdbcTemplate ( dataSource );
56
+ jdbc = createJdbcTemplate ( createDataSource () );
76
57
jdbc .execute (tableToCreate );
77
58
jdbc .execute ("DELETE FROM legoset" );
78
59
}
0 commit comments