forked from Archives/Athou_commafeed
reset database completely after each test so that tests cannot impact each other
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
package com.commafeed;
|
package com.commafeed;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
@@ -15,9 +12,6 @@ import io.dropwizard.testing.junit5.DropwizardAppExtension;
|
|||||||
|
|
||||||
public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<CommaFeedConfiguration> {
|
public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<CommaFeedConfiguration> {
|
||||||
|
|
||||||
private static final List<String> TABLES = Arrays.asList("FEEDENTRYSTATUSES", "FEEDENTRYTAGS", "FEEDENTRIES", "FEEDENTRYCONTENTS",
|
|
||||||
"FEEDSUBSCRIPTIONS", "FEEDS", "FEEDCATEGORIES");
|
|
||||||
|
|
||||||
public CommaFeedDropwizardAppExtension() {
|
public CommaFeedDropwizardAppExtension() {
|
||||||
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
|
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
|
||||||
}
|
}
|
||||||
@@ -29,10 +23,7 @@ public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<Comm
|
|||||||
// clean database after each test
|
// clean database after each test
|
||||||
DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
|
DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
for (String table : TABLES) {
|
connection.prepareStatement("DROP ALL OBJECTS").executeUpdate();
|
||||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + table);
|
|
||||||
statement.executeUpdate();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("could not cleanup database", e);
|
throw new RuntimeException("could not cleanup database", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user