|
14 | 14 | package org.stdg.test; |
15 | 15 |
|
16 | 16 | import org.junit.jupiter.api.*; |
| 17 | +import org.junit.jupiter.params.ParameterizedTest; |
| 18 | +import org.junit.jupiter.params.provider.ValueSource; |
17 | 19 | import org.stdg.SqlTestDataGenerator; |
18 | 20 |
|
19 | 21 | import javax.sql.DataSource; |
|
22 | 24 |
|
23 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
24 | 26 | import static org.stdg.test.TestTable.TestTableAssert.assertThat; |
| 27 | +import static org.stdg.test.TestTable.buildUniqueTable; |
25 | 28 |
|
26 | 29 | public class HsqlDbTest { |
27 | 30 |
|
@@ -225,8 +228,46 @@ private int generateRandomPositiveInt() { |
225 | 228 |
|
226 | 229 | } |
227 | 230 |
|
| 231 | + @ParameterizedTest |
| 232 | + @ValueSource(strings = {"INT", "TINYINT", "SMALLINT", "BIGINT"}) |
| 233 | + public void |
| 234 | + should_sort_insert_statements_following_an_integer_primary_key(String intType) { |
| 235 | + |
| 236 | + TestTable table = |
| 237 | + buildUniqueTable(DATA_SOURCE |
| 238 | + , "table_with_int_pk" |
| 239 | + , "col_id " + intType + "," + |
| 240 | + "colA varchar(20), " + |
| 241 | + "colB varchar(20), " + |
| 242 | + "constraint int_pk" + generateRandomPositiveInt() + " primary key (col_id)" |
| 243 | + ) |
| 244 | + .create() |
| 245 | + .insertValues("2, 'A', 'B'") |
| 246 | + .insertValues("10, 'C', 'D'") |
| 247 | + .insertValues("1, 'E', 'F'"); |
| 248 | + |
| 249 | + String selectAll = "SELECT * FROM " + table.getTableName(); |
| 250 | + SqlTestDataGenerator sqlTestDataGenerator = SqlTestDataGenerator.buildFrom(DATA_SOURCE); |
| 251 | + |
| 252 | + // WHEN |
| 253 | + List<String> insertStatements = sqlTestDataGenerator.generateInsertListFor(selectAll); |
| 254 | + |
| 255 | + // THEN |
| 256 | + String insertStatementsAsString = insertStatements.toString(); |
| 257 | + |
| 258 | + String firstQuery = insertStatements.get(0); |
| 259 | + assertThat(firstQuery).as(insertStatementsAsString).contains("VALUES(1"); |
| 260 | + |
| 261 | + String secondQuery = insertStatements.get(1); |
| 262 | + assertThat(secondQuery).as(insertStatementsAsString).contains("VALUES(2"); |
| 263 | + |
| 264 | + String thirdQuery = insertStatements.get(2); |
| 265 | + assertThat(thirdQuery).as(insertStatementsAsString).contains("VALUES(10"); |
| 266 | + |
| 267 | + } |
| 268 | + |
228 | 269 | @RepeatedTest(9) public void |
229 | | - should_sort_insert_statements_following_the_primary_key_values() { |
| 270 | + should_sort_insert_statements_following_a_composite_primary_key() { |
230 | 271 |
|
231 | 272 | // GIVEN |
232 | 273 | TestTable table = |
|
0 commit comments