diff --git a/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitAnnotationsParserTest.java b/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitAnnotationsParserTest.java index d2f49347..c84341fb 100644 --- a/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitAnnotationsParserTest.java +++ b/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitAnnotationsParserTest.java @@ -170,6 +170,7 @@ void it_should_extract_sql_scripts_from_annotation() { assertThat(sqlScripts).isNotEmpty().hasSize(2); assertThat(sqlScripts.get(0).getQueries()).isNotEmpty().containsExactly( + "DROP TABLE IF EXISTS users_movies_events;", "DROP TABLE IF EXISTS users_movies;", "DROP TABLE IF EXISTS movies;", "DROP TABLE IF EXISTS users;" @@ -183,6 +184,13 @@ void it_should_extract_sql_scripts_from_annotation() { " PRIMARY KEY (user_id, movie_id), " + " FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, " + " FOREIGN KEY (movie_id) REFERENCES movies(id) ON DELETE CASCADE " + + ");", + "CREATE TABLE users_movies_events ( " + + " user_id INT, " + + " movie_id INT, " + + " id INT PRIMARY KEY, " + + " event VARCHAR(200), " + + " FOREIGN KEY (user_id, movie_id) REFERENCES users_movies (user_id, movie_id) ON DELETE CASCADE " + ");" ); } diff --git a/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitClassContextFactoryTest.java b/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitClassContextFactoryTest.java index a1ef8b05..5f74a624 100644 --- a/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitClassContextFactoryTest.java +++ b/src/test/java/com/github/mjeanroy/dbunit/core/runner/DbUnitClassContextFactoryTest.java @@ -74,6 +74,7 @@ void it_should_extract_sql_scripts_from_class_context() { assertThat(ctx).isNotNull(); assertThat(ctx.getInitScripts()).isNotEmpty().hasSize(2); assertThat(ctx.getInitScripts().get(0).getQueries()).isNotEmpty().containsExactly( + "DROP TABLE IF EXISTS users_movies_events;", "DROP TABLE IF EXISTS users_movies;", "DROP TABLE IF EXISTS movies;", "DROP TABLE IF EXISTS users;" @@ -87,6 +88,13 @@ void it_should_extract_sql_scripts_from_class_context() { " PRIMARY KEY (user_id, movie_id), " + " FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, " + " FOREIGN KEY (movie_id) REFERENCES movies(id) ON DELETE CASCADE " + + ");", + "CREATE TABLE users_movies_events ( " + + " user_id INT, " + + " movie_id INT, " + + " id INT PRIMARY KEY, " + + " event VARCHAR(200), " + + " FOREIGN KEY (user_id, movie_id) REFERENCES users_movies (user_id, movie_id) ON DELETE CASCADE " + ");" ); } diff --git a/src/test/java/com/github/mjeanroy/dbunit/core/sql/SqlScriptParserTest.java b/src/test/java/com/github/mjeanroy/dbunit/core/sql/SqlScriptParserTest.java index a56ca554..f9468634 100644 --- a/src/test/java/com/github/mjeanroy/dbunit/core/sql/SqlScriptParserTest.java +++ b/src/test/java/com/github/mjeanroy/dbunit/core/sql/SqlScriptParserTest.java @@ -269,6 +269,13 @@ private static void verifyParsedQueries(List queries) { " PRIMARY KEY (user_id, movie_id), " + " FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, " + " FOREIGN KEY (movie_id) REFERENCES movies(id) ON DELETE CASCADE " + + ");", + "CREATE TABLE users_movies_events ( " + + " user_id INT, " + + " movie_id INT, " + + " id INT PRIMARY KEY, " + + " event VARCHAR(200), " + + " FOREIGN KEY (user_id, movie_id) REFERENCES users_movies (user_id, movie_id) ON DELETE CASCADE " + ");" ); } @@ -294,6 +301,16 @@ private static void verifyExecutedQueries(Connection connection, PreparedStateme ");" ); + verifyQueryExecution(inOrder, connection, statement, + "CREATE TABLE users_movies_events ( " + + " user_id INT, " + + " movie_id INT, " + + " id INT PRIMARY KEY, " + + " event VARCHAR(200), " + + " FOREIGN KEY (user_id, movie_id) REFERENCES users_movies (user_id, movie_id) ON DELETE CASCADE " + + ");" + ); + inOrder.verifyNoMoreInteractions(); } diff --git a/src/test/resources/liquibase/changelog.xml b/src/test/resources/liquibase/changelog.xml index 47706a53..7cfe719c 100644 --- a/src/test/resources/liquibase/changelog.xml +++ b/src/test/resources/liquibase/changelog.xml @@ -30,5 +30,6 @@ + diff --git a/src/test/resources/liquibase/changesets/04-create-users-movies-events.xml b/src/test/resources/liquibase/changesets/04-create-users-movies-events.xml new file mode 100644 index 00000000..585d4105 --- /dev/null +++ b/src/test/resources/liquibase/changesets/04-create-users-movies-events.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/sql/drop.sql b/src/test/resources/sql/drop.sql index 75c6b192..48a7d6a5 100644 --- a/src/test/resources/sql/drop.sql +++ b/src/test/resources/sql/drop.sql @@ -25,6 +25,7 @@ -- -- Drop tables if it already exist. -- +DROP TABLE IF EXISTS users_movies_events; DROP TABLE IF EXISTS users_movies; DROP TABLE IF EXISTS movies; DROP TABLE IF EXISTS users; diff --git a/src/test/resources/sql/schema.sql b/src/test/resources/sql/schema.sql index 3e6eee48..6a71a975 100644 --- a/src/test/resources/sql/schema.sql +++ b/src/test/resources/sql/schema.sql @@ -27,6 +27,7 @@ -- CREATE TABLE users (id INT PRIMARY KEY, name varchar(100)); CREATE TABLE movies (id INT PRIMARY KEY, title varchar(100), synopsys varchar(200)); + CREATE TABLE users_movies ( user_id INT, movie_id INT, @@ -34,3 +35,11 @@ CREATE TABLE users_movies ( FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (movie_id) REFERENCES movies(id) ON DELETE CASCADE ); + +CREATE TABLE users_movies_events ( + user_id INT, + movie_id INT, + id INT PRIMARY KEY, + event VARCHAR(200), + FOREIGN KEY (user_id, movie_id) REFERENCES users_movies (user_id, movie_id) ON DELETE CASCADE +);