Skip to content

Commit

Permalink
clean database after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Aug 23, 2023
1 parent 6eabcf9 commit 838ead8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.commafeed;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

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> {

public CommaFeedDropwizardAppExtension() {
super(CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
}

@Override
public void after() {
super.after();

DataSource dataSource = getConfiguration().getDataSourceFactory().build(new MetricRegistry(), "cleanup");
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("DROP ALL OBJECTS")) {
statement.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException("could not cleanup database", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.commafeed.CommaFeedApplication;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.CommaFeedDropwizardAppExtension;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.assertions.PlaywrightAssertions;

import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;

@ExtendWith(DropwizardExtensionsSupport.class)
class AuthentificationIT extends PlaywrightTestBase {

private static final DropwizardAppExtension<CommaFeedConfiguration> EXT = new DropwizardAppExtension<>(CommaFeedApplication.class,
ResourceHelpers.resourceFilePath("config.test.yml"));
private static final CommaFeedDropwizardAppExtension EXT = new CommaFeedDropwizardAppExtension();

@Test
void loginFail() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;

import com.commafeed.CommaFeedApplication;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.CommaFeedDropwizardAppExtension;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Locator.WaitForOptions;
import com.microsoft.playwright.assertions.PlaywrightAssertions;

import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;

@ExtendWith(DropwizardExtensionsSupport.class)
@ExtendWith(MockServerExtension.class)
class ReadingIT extends PlaywrightTestBase {

private static final DropwizardAppExtension<CommaFeedConfiguration> EXT = new DropwizardAppExtension<CommaFeedConfiguration>(
CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml"));
private static final CommaFeedDropwizardAppExtension EXT = new CommaFeedDropwizardAppExtension();

private MockServerClient mockServerClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;

import com.commafeed.CommaFeedApplication;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.CommaFeedDropwizardAppExtension;
import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.request.SubscribeRequest;

import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;

@ExtendWith(DropwizardExtensionsSupport.class)
@ExtendWith(MockServerExtension.class)
class FeedIT {

private static final DropwizardAppExtension<CommaFeedConfiguration> EXT = new DropwizardAppExtension<CommaFeedConfiguration>(
CommaFeedApplication.class, ResourceHelpers.resourceFilePath("config.test.yml")) {
private static final CommaFeedDropwizardAppExtension EXT = new CommaFeedDropwizardAppExtension() {
@Override
protected JerseyClientBuilder clientBuilder() {
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("admin", "admin");
Expand Down

0 comments on commit 838ead8

Please sign in to comment.