2023-08-23 20:21:45 +02:00
|
|
|
package com.commafeed;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
2024-04-14 16:49:26 +02:00
|
|
|
import org.mockserver.socket.PortFactory;
|
|
|
|
|
|
2023-08-23 20:21:45 +02:00
|
|
|
import com.codahale.metrics.MetricRegistry;
|
|
|
|
|
|
2024-04-14 16:49:26 +02:00
|
|
|
import io.dropwizard.testing.ConfigOverride;
|
2023-08-23 20:21:45 +02:00
|
|
|
import io.dropwizard.testing.ResourceHelpers;
|
|
|
|
|
import io.dropwizard.testing.junit5.DropwizardAppExtension;
|
|
|
|
|
|
|
|
|
|
public class CommaFeedDropwizardAppExtension extends DropwizardAppExtension<CommaFeedConfiguration> {
|
|
|
|
|
|
|
|
|
|
public CommaFeedDropwizardAppExtension() {
|
2024-04-14 16:49:26 +02:00
|
|
|
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"),
|
|
|
|
|
ConfigOverride.config("server.applicationConnectors[0].port", String.valueOf(PortFactory.findFreePort())));
|
2023-08-23 20:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void after() {
|
|
|
|
|
super.after();
|
|
|
|
|
|
|
|
|
|
// clean database after each test
|
|
|
|
|
DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
|
2023-12-15 08:59:52 +01:00
|
|
|
try (Connection connection = dataSource.getConnection()) {
|
2023-12-24 10:52:09 +01:00
|
|
|
connection.prepareStatement("DROP ALL OBJECTS").executeUpdate();
|
2023-08-23 20:21:45 +02:00
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new RuntimeException("could not cleanup database", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|