Files
Athou_commafeed/commafeed-server/src/test/java/com/commafeed/CommaFeedDropwizardAppExtension.java

42 lines
1.3 KiB
Java
Raw Normal View History

2023-08-23 20:21:45 +02:00
package com.commafeed;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
2023-08-23 20:21:45 +02:00
import javax.sql.DataSource;
import com.codahale.metrics.MetricRegistry;
import io.dropwizard.testing.ResourceHelpers;
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");
2023-08-23 20:21:45 +02:00
public CommaFeedDropwizardAppExtension() {
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
}
@Override
public void after() {
super.after();
// clean database after each test
DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
try (Connection connection = dataSource.getConnection()) {
for (String table : TABLES) {
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + table);
statement.executeUpdate();
}
2023-08-23 20:21:45 +02:00
} catch (SQLException e) {
throw new RuntimeException("could not cleanup database", e);
}
}
}