|
| 1 | +package g0101_0200.s0180_consecutive_numbers; |
| 2 | + |
| 3 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 4 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 5 | + |
| 6 | +import java.io.BufferedReader; |
| 7 | +import java.io.FileNotFoundException; |
| 8 | +import java.io.FileReader; |
| 9 | +import java.sql.Connection; |
| 10 | +import java.sql.DriverManager; |
| 11 | +import java.sql.ResultSet; |
| 12 | +import java.sql.SQLException; |
| 13 | +import java.sql.Statement; |
| 14 | +import java.util.stream.Collectors; |
| 15 | +import org.junit.Rule; |
| 16 | +import org.junit.Test; |
| 17 | +import org.zapodot.junit.db.EmbeddedDatabaseRule; |
| 18 | +import org.zapodot.junit.db.common.CompatibilityMode; |
| 19 | + |
| 20 | +public class MysqlTest { |
| 21 | + @Rule |
| 22 | + public final EmbeddedDatabaseRule embeddedDatabaseRule = |
| 23 | + EmbeddedDatabaseRule.builder() |
| 24 | + .withMode(CompatibilityMode.MySQL) |
| 25 | + .withInitialSql( |
| 26 | + "CREATE TABLE Logs(id INTEGER PRIMARY KEY, num INTEGER); " |
| 27 | + + "INSERT INTO Logs(id, num) VALUES (1, 1); " |
| 28 | + + "INSERT INTO Logs(id, num) VALUES (2, 1); " |
| 29 | + + "INSERT INTO Logs(id, num) VALUES (3, 1); " |
| 30 | + + "INSERT INTO Logs(id, num) VALUES (4, 2); " |
| 31 | + + "INSERT INTO Logs(id, num) VALUES (5, 1); " |
| 32 | + + "INSERT INTO Logs(id, num) VALUES (6, 2); " |
| 33 | + + "INSERT INTO Logs(id, num) VALUES (7, 2); ") |
| 34 | + .build(); |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testScript() throws SQLException, FileNotFoundException { |
| 38 | + try (final Connection connection = |
| 39 | + DriverManager.getConnection(embeddedDatabaseRule.getConnectionJdbcUrl())) { |
| 40 | + try (final Statement statement = connection.createStatement(); |
| 41 | + final ResultSet resultSet = |
| 42 | + statement.executeQuery( |
| 43 | + new BufferedReader( |
| 44 | + new FileReader( |
| 45 | + "src/main/java/g0101_0200/" |
| 46 | + + "s0180_consecutive_numbers/script.sql")) |
| 47 | + .lines() |
| 48 | + .collect(Collectors.joining("\n")) |
| 49 | + .replaceAll("#.*?\\r?\\n", ""))) { |
| 50 | + assertThat(resultSet.next(), equalTo(true)); |
| 51 | + assertThat(resultSet.getInt(1), equalTo(1)); |
| 52 | + assertThat(resultSet.next(), equalTo(false)); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments