add more IT tests to ease transition to dropwizard 4

This commit is contained in:
Athou
2023-12-15 08:59:52 +01:00
parent 929df60f09
commit 6ed5637e57
6 changed files with 496 additions and 59 deletions

View File

@@ -3,6 +3,8 @@ package com.commafeed;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import javax.sql.DataSource;
@@ -13,6 +15,9 @@ import io.dropwizard.testing.junit5.DropwizardAppExtension;
public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<CommaFeedConfiguration> {
private static final List<String> TABLES = Arrays.asList("FEEDENTRYSTATUSES", "FEEDENTRYTAGS", "FEEDENTRIES", "FEEDENTRYCONTENTS",
"FEEDSUBSCRIPTIONS", "FEEDS", "FEEDCATEGORIES");
public CommaFeedDropwizardAppExtension() {
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
}
@@ -23,9 +28,11 @@ public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<Comm
// clean database after each test
DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("DROP ALL OBJECTS")) {
statement.executeUpdate();
try (Connection connection = dataSource.getConnection()) {
for (String table : TABLES) {
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + table);
statement.executeUpdate();
}
} catch (SQLException e) {
throw new RuntimeException("could not cleanup database", e);
}