-
Notifications
You must be signed in to change notification settings - Fork 93
Added tests for tasks 620, 626, 1050 #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package g0601_0700.s0620_not_boring_movies; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.stream.Collectors; | ||
import javax.sql.DataSource; | ||
import org.junit.jupiter.api.Test; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabase; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; | ||
import org.zapodot.junit.db.common.CompatibilityMode; | ||
|
||
@EmbeddedDatabaseTest( | ||
compatibilityMode = CompatibilityMode.MySQL, | ||
initialSqls = | ||
"CREATE TABLE cinema(id INTEGER PRIMARY KEY, movie VARCHAR(512)" | ||
+ ", description VARCHAR(512), rating FLOAT); " | ||
+ "INSERT INTO cinema(id, movie, description, rating) " | ||
+ "VALUES (1, 'War', 'great 3D', 8.9); " | ||
+ "INSERT INTO cinema(id, movie, description, rating) " | ||
+ "VALUES (2, 'Science', 'fiction', 8.5); " | ||
+ "INSERT INTO cinema(id, movie, description, rating) " | ||
+ "VALUES (3, 'irish', 'boring', 6.2); " | ||
+ "INSERT INTO cinema(id, movie, description, rating) " | ||
+ "VALUES (4, 'Ice song', 'Fantacy', 8.6);" | ||
+ "INSERT INTO cinema(id, movie, description, rating) " | ||
+ "VALUES (5, 'House card', 'Interesting', 9.1);") | ||
class MysqlTest { | ||
@Test | ||
void testScript(@EmbeddedDatabase DataSource dataSource) | ||
throws SQLException, FileNotFoundException { | ||
try (final Connection connection = dataSource.getConnection()) { | ||
try (final Statement statement = connection.createStatement(); | ||
final ResultSet resultSet = | ||
statement.executeQuery( | ||
new BufferedReader( | ||
new FileReader( | ||
"src/main/java/g0601_0700/s0620_not_boring_movies/script.sql")) | ||
.lines() | ||
.collect(Collectors.joining("\n")) | ||
.replaceAll("#.*?\\r?\\n", ""))) { | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("5")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use getInt(1) method. |
||
assertThat(resultSet.getNString(2), equalTo("House card")); | ||
assertThat(resultSet.getNString(3), equalTo("Interesting")); | ||
assertThat(resultSet.getNString(4), equalTo("9.1")); | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("1")); | ||
assertThat(resultSet.getNString(2), equalTo("War")); | ||
assertThat(resultSet.getNString(3), equalTo("great 3D")); | ||
assertThat(resultSet.getNString(4), equalTo("8.9")); | ||
assertThat(resultSet.next(), equalTo(false)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package g0601_0700.s0626_exchange_seats; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.stream.Collectors; | ||
import javax.sql.DataSource; | ||
import org.junit.jupiter.api.Test; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabase; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; | ||
import org.zapodot.junit.db.common.CompatibilityMode; | ||
|
||
@EmbeddedDatabaseTest( | ||
compatibilityMode = CompatibilityMode.MySQL, | ||
initialSqls = | ||
"CREATE TABLE seat(id INTEGER PRIMARY KEY, student VARCHAR(512));" | ||
+ "INSERT INTO seat(id, student) " | ||
+ "VALUES (1, 'Abbot'); " | ||
+ "INSERT INTO seat(id, student) " | ||
+ "VALUES (2, 'Doris'); " | ||
+ "INSERT INTO seat(id, student) " | ||
+ "VALUES (3, 'Emerson'); " | ||
+ "INSERT INTO seat(id, student) " | ||
+ "VALUES (4, 'Green'); " | ||
+ "INSERT INTO seat(id, student) " | ||
+ "VALUES (5, 'Jeames'); ") | ||
class MysqlTest { | ||
@Test | ||
void testScript(@EmbeddedDatabase DataSource dataSource) | ||
throws SQLException, FileNotFoundException { | ||
try (final Connection connection = dataSource.getConnection()) { | ||
try (final Statement statement = connection.createStatement(); | ||
final ResultSet resultSet = | ||
statement.executeQuery( | ||
new BufferedReader( | ||
new FileReader( | ||
"src/main/java/g0601_0700/s0626_exchange_seats/script.sql")) | ||
.lines() | ||
.collect(Collectors.joining("\n")) | ||
.replaceAll("#.*?\\r?\\n", ""))) { | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("1")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use getInt(1) method. |
||
assertThat(resultSet.getNString(2), equalTo("Doris")); | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("2")); | ||
assertThat(resultSet.getNString(2), equalTo("Abbot")); | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("3")); | ||
assertThat(resultSet.getNString(2), equalTo("Green")); | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("4")); | ||
assertThat(resultSet.getNString(2), equalTo("Emerson")); | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("5")); | ||
assertThat(resultSet.getNString(2), equalTo("Jeames")); | ||
assertThat(resultSet.next(), equalTo(false)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package g1001_1100.s1050_actors_and_directors_who_cooperated_at_least_three_times; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.stream.Collectors; | ||
import javax.sql.DataSource; | ||
import org.junit.jupiter.api.Test; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabase; | ||
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; | ||
import org.zapodot.junit.db.common.CompatibilityMode; | ||
|
||
@EmbeddedDatabaseTest( | ||
compatibilityMode = CompatibilityMode.MySQL, | ||
initialSqls = | ||
"CREATE TABLE ACTORDIRECTOR(actor_id INTEGER, director_id INTEGER, timestamp INTEGER PRIMARY KEY); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 1,0); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 1,1); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 1,2); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 2,3); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 2,4); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (1, 1,5); " | ||
+ "INSERT INTO ACTORDIRECTOR(actor_id, director_id, timestamp) " | ||
+ "VALUES (2, 1,6); ") | ||
class MysqlTest { | ||
@Test | ||
void testScript(@EmbeddedDatabase DataSource dataSource) | ||
throws SQLException, FileNotFoundException { | ||
try (final Connection connection = dataSource.getConnection()) { | ||
try (final Statement statement = connection.createStatement(); | ||
final ResultSet resultSet = | ||
statement.executeQuery( | ||
new BufferedReader( | ||
new FileReader( | ||
"src/main/java/g1001_1100/s1050_actors_and_directors_who_cooperated_at_least_three_times/script.sql")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String too long. |
||
.lines() | ||
.collect(Collectors.joining("\n")) | ||
.replaceAll("#.*?\\r?\\n", ""))) { | ||
assertThat(resultSet.next(), equalTo(true)); | ||
assertThat(resultSet.getNString(1), equalTo("1")); | ||
assertThat(resultSet.getNString(2), equalTo("1")); | ||
assertThat(resultSet.next(), equalTo(false)); | ||
} | ||
} | ||
} | ||
} |