diff --git a/core/common/junit/build.gradle.kts b/core/common/junit/build.gradle.kts index 7a373e8cd4c..f8bfaebfefc 100644 --- a/core/common/junit/build.gradle.kts +++ b/core/common/junit/build.gradle.kts @@ -30,6 +30,7 @@ dependencies { runtimeOnly(libs.junit.jupiter.engine) implementation(libs.junit.pioneer) + implementation(libs.testcontainers.junit) } diff --git a/core/common/junit/src/main/java/org/eclipse/edc/junit/annotations/PostgresqlDbIntegrationTest.java b/core/common/junit/src/main/java/org/eclipse/edc/junit/annotations/PostgresqlDbIntegrationTest.java index a5d22495d87..f53e314ca18 100644 --- a/core/common/junit/src/main/java/org/eclipse/edc/junit/annotations/PostgresqlDbIntegrationTest.java +++ b/core/common/junit/src/main/java/org/eclipse/edc/junit/annotations/PostgresqlDbIntegrationTest.java @@ -16,6 +16,7 @@ package org.eclipse.edc.junit.annotations; import org.junit.jupiter.api.Tag; +import org.testcontainers.junit.jupiter.Testcontainers; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -28,6 +29,7 @@ @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @IntegrationTest +@Testcontainers @Tag("PostgresqlIntegrationTest") public @interface PostgresqlDbIntegrationTest { } diff --git a/extensions/common/sql/sql-core/build.gradle.kts b/extensions/common/sql/sql-core/build.gradle.kts index 4aa2415c66d..cf8ba2ab73e 100644 --- a/extensions/common/sql/sql-core/build.gradle.kts +++ b/extensions/common/sql/sql-core/build.gradle.kts @@ -32,6 +32,9 @@ dependencies { testFixturesImplementation(project(":spi:common:transaction-datasource-spi")) testFixturesImplementation(libs.mockito.core) + testFixturesImplementation(libs.testcontainers.junit) + testFixturesImplementation(libs.testcontainers.postgres) + } diff --git a/extensions/common/sql/sql-core/src/test/java/org/eclipse/edc/sql/SqlQueryExecutorIntegrationTest.java b/extensions/common/sql/sql-core/src/test/java/org/eclipse/edc/sql/SqlQueryExecutorIntegrationTest.java index d7cc9c5b4a0..1b610b78116 100644 --- a/extensions/common/sql/sql-core/src/test/java/org/eclipse/edc/sql/SqlQueryExecutorIntegrationTest.java +++ b/extensions/common/sql/sql-core/src/test/java/org/eclipse/edc/sql/SqlQueryExecutorIntegrationTest.java @@ -15,7 +15,7 @@ package org.eclipse.edc.sql; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.spi.persistence.EdcPersistenceException; import org.eclipse.edc.sql.testfixtures.PostgresqlStoreSetupExtension; import org.jetbrains.annotations.NotNull; @@ -35,7 +35,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) public class SqlQueryExecutorIntegrationTest { @@ -114,5 +114,6 @@ private KeyValue insertRow(Connection connection) { return keyValue; } - private record KeyValue(String key, String value) { } + private record KeyValue(String key, String value) { + } } diff --git a/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlLocalInstance.java b/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlLocalInstance.java index c0d14c3552b..f2158aef69d 100644 --- a/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlLocalInstance.java +++ b/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlLocalInstance.java @@ -24,40 +24,57 @@ import static java.lang.String.format; public final class PostgresqlLocalInstance { - public static final String USER = "postgres"; - public static final String PASSWORD = "password"; - public static final String JDBC_URL_PREFIX = "jdbc:postgresql://localhost:5432/"; - private static final String TEST_DATABASE = "itest"; + private final String password; + private final String jdbcUrlPrefix; + private final String username; + private final String databaseName; - private PostgresqlLocalInstance() { } + public PostgresqlLocalInstance(String user, String password, String jdbcUrlPrefix, String db) { + username = user; + this.password = password; + this.jdbcUrlPrefix = jdbcUrlPrefix; + databaseName = db; + } - public static void createTestDatabase() { - createDatabase(TEST_DATABASE); + public void createDatabase() { + createDatabase(databaseName); } - public static void createDatabase(String name) { - try (var connection = DriverManager.getConnection(JDBC_URL_PREFIX + USER, USER, PASSWORD)) { + public void createDatabase(String name) { + try (var connection = DriverManager.getConnection(jdbcUrlPrefix + username, username, password)) { connection.createStatement().execute(format("create database %s;", name)); } catch (SQLException e) { // database could already exist } } - public static Connection getTestConnection() { + public Connection getTestConnection(String hostName, int port, String dbName) { try { - return createTestDataSource().getConnection(); + return createTestDataSource(hostName, port, dbName).getConnection(); } catch (SQLException e) { throw new RuntimeException(e); } } - private static DataSource createTestDataSource() { + public Connection getConnection() { + try { + return DriverManager.getConnection(jdbcUrlPrefix, username, password); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + public String getJdbcUrlPrefix() { + return jdbcUrlPrefix; + } + + private DataSource createTestDataSource(String hostName, int port, String dbName) { var dataSource = new PGSimpleDataSource(); - dataSource.setServerNames(new String[]{ "localhost" }); - dataSource.setPortNumbers(new int[]{ 5432 }); - dataSource.setUser(USER); - dataSource.setPassword(PASSWORD); - dataSource.setDatabaseName(TEST_DATABASE); + dataSource.setServerNames(new String[]{ hostName }); + dataSource.setPortNumbers(new int[]{ port }); + dataSource.setUser(username); + dataSource.setPassword(password); + dataSource.setDatabaseName(dbName); return dataSource; } } diff --git a/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlStoreSetupExtension.java b/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlStoreSetupExtension.java index 10eee1a32d3..c6e2a403d8a 100644 --- a/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlStoreSetupExtension.java +++ b/extensions/common/sql/sql-core/src/testFixtures/java/org/eclipse/edc/sql/testfixtures/PostgresqlStoreSetupExtension.java @@ -19,6 +19,7 @@ import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.NoopTransactionContext; import org.eclipse.edc.transaction.spi.TransactionContext; +import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; @@ -26,12 +27,14 @@ import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; +import org.testcontainers.containers.PostgreSQLContainer; import java.sql.Connection; import java.util.List; import java.util.UUID; import javax.sql.DataSource; +import static java.lang.String.format; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; @@ -42,14 +45,21 @@ * Extension for running PG SQL store implementation. It automatically creates a test database and provided all the base data structure * for a SQL store to run such as {@link DataSourceRegistry}, {@link TransactionContext} and data source name which is automatically generated */ -public class PostgresqlStoreSetupExtension implements BeforeEachCallback, AfterEachCallback, BeforeAllCallback, ParameterResolver { - +public class PostgresqlStoreSetupExtension implements BeforeEachCallback, AfterEachCallback, BeforeAllCallback, AfterAllCallback, ParameterResolver { + + public static final String POSTGRES_IMAGE_NAME = "postgres:14.2"; + public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>(POSTGRES_IMAGE_NAME) + .withExposedPorts(5432) + .withUsername("postgres") + .withPassword("password") + .withDatabaseName("itest"); private final String datasourceName; + private final QueryExecutor queryExecutor = new SqlQueryExecutor(); private DataSourceRegistry dataSourceRegistry = null; private DataSource dataSource = null; private Connection connection = null; private TransactionContext transactionContext = null; - private final QueryExecutor queryExecutor = new SqlQueryExecutor(); + private PostgresqlLocalInstance helper; @SuppressWarnings("unused") public PostgresqlStoreSetupExtension() { @@ -89,7 +99,7 @@ public void beforeEach(ExtensionContext context) throws Exception { transactionContext = new NoopTransactionContext(); dataSourceRegistry = mock(DataSourceRegistry.class); dataSource = mock(DataSource.class); - connection = spy(PostgresqlLocalInstance.getTestConnection()); + connection = spy(helper.getTestConnection(postgreSQLContainer.getHost(), postgreSQLContainer.getFirstMappedPort(), postgreSQLContainer.getDatabaseName())); when(dataSourceRegistry.resolve(datasourceName)).thenReturn(dataSource); when(dataSource.getConnection()).thenReturn(connection); @@ -104,18 +114,26 @@ public void afterEach(ExtensionContext context) throws Exception { @Override public void beforeAll(ExtensionContext context) { - PostgresqlLocalInstance.createTestDatabase(); + postgreSQLContainer.start(); + var jdbcUrlPrefix = format("jdbc:postgresql://%s:%s/", postgreSQLContainer.getHost(), postgreSQLContainer.getFirstMappedPort()); + helper = new PostgresqlLocalInstance(postgreSQLContainer.getUsername(), postgreSQLContainer.getPassword(), jdbcUrlPrefix, postgreSQLContainer.getDatabaseName()); + helper.createDatabase(); + } + + @Override + public void afterAll(ExtensionContext context) { + postgreSQLContainer.stop(); + postgreSQLContainer.close(); } @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { var type = parameterContext.getParameter().getParameterizedType(); - return List.of(PostgresqlStoreSetupExtension.class, Connection.class, QueryExecutor.class).contains(type); + return List.of(PostgresqlStoreSetupExtension.class, Connection.class, QueryExecutor.class, PostgresqlLocalInstance.class).contains(type); } @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws - ParameterResolutionException { + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { var type = parameterContext.getParameter().getParameterizedType(); if (type.equals(PostgresqlStoreSetupExtension.class)) { return this; @@ -123,6 +141,8 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte return connection; } else if (type.equals(QueryExecutor.class)) { return queryExecutor; + } else if (type.equals(PostgresqlLocalInstance.class)) { + return helper; } return null; } diff --git a/extensions/common/sql/sql-lease/src/test/java/org/eclipse/edc/sql/lease/PostgresLeaseContextTest.java b/extensions/common/sql/sql-lease/src/test/java/org/eclipse/edc/sql/lease/PostgresLeaseContextTest.java index 33b460305af..156271c28b3 100644 --- a/extensions/common/sql/sql-lease/src/test/java/org/eclipse/edc/sql/lease/PostgresLeaseContextTest.java +++ b/extensions/common/sql/sql-lease/src/test/java/org/eclipse/edc/sql/lease/PostgresLeaseContextTest.java @@ -15,7 +15,7 @@ package org.eclipse.edc.sql.lease; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.sql.ResultSetMapper; import org.eclipse.edc.sql.SqlQueryExecutor; import org.eclipse.edc.sql.testfixtures.PostgresqlLocalInstance; @@ -48,7 +48,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresLeaseContextTest { @@ -57,13 +57,13 @@ class PostgresLeaseContextTest { private final TransactionContext transactionContext = new NoopTransactionContext(); private final TestEntityLeaseStatements dialect = new TestEntityLeaseStatements(); + private final SqlQueryExecutor queryExecutor = new SqlQueryExecutor(); private SqlLeaseContextBuilder builder; private SqlLeaseContext leaseContext; - private final SqlQueryExecutor queryExecutor = new SqlQueryExecutor(); @BeforeAll - static void prepare() { - PostgresqlLocalInstance.createTestDatabase(); + static void prepare(PostgresqlLocalInstance postgres) { + postgres.createDatabase(); } @BeforeEach diff --git a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultIntegrationTest.java b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultIntegrationTest.java index eb72509be32..f599c1d7cd9 100644 --- a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultIntegrationTest.java +++ b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultIntegrationTest.java @@ -19,15 +19,6 @@ import org.eclipse.edc.junit.extensions.EdcExtension; import org.eclipse.edc.spi.security.CertificateResolver; import org.eclipse.edc.spi.security.Vault; -import org.eclipse.edc.spi.system.ServiceExtension; -import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.system.health.HealthCheckResult; -import org.eclipse.edc.spi.system.health.HealthCheckService; -import org.eclipse.edc.spi.system.health.HealthStatus; -import org.eclipse.edc.spi.system.health.LivenessProvider; -import org.eclipse.edc.spi.system.health.ReadinessProvider; -import org.eclipse.edc.spi.system.health.StartupStatusProvider; -import org.junit.ClassRule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -36,18 +27,14 @@ import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.shaded.org.bouncycastle.operator.OperatorCreationException; import org.testcontainers.vault.VaultContainer; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; @@ -67,32 +54,25 @@ class HashicorpVaultIntegrationTest { static final String TOKEN = UUID.randomUUID().toString(); @Container - @ClassRule public static final VaultContainer VAULTCONTAINER = new VaultContainer<>(DOCKER_IMAGE_NAME) .withVaultToken(TOKEN) .withSecretInVault("secret/" + VAULT_ENTRY_KEY, format("%s=%s", VAULT_DATA_ENTRY_NAME, VAULT_ENTRY_VALUE)); - private final TestExtension testExtension = new TestExtension(); - @BeforeEach - final void beforeEach(EdcExtension extension) { + void beforeEach(EdcExtension extension) { extension.setConfiguration(getConfig()); - extension.registerServiceMock(HealthCheckService.class, new MyHealthCheckService()); - extension.registerSystemExtension(ServiceExtension.class, testExtension); } @Test @DisplayName("Resolve a secret that exists") - void testResolveSecret_exists() { - var vault = getVault(); + void testResolveSecret_exists(Vault vault) { var secretValue = vault.resolveSecret(VAULT_ENTRY_KEY); assertThat(secretValue).isEqualTo(VAULT_ENTRY_VALUE); } @Test @DisplayName("Resolve a secret from a sub directory") - void testResolveSecret_inSubDirectory() { - var vault = getVault(); + void testResolveSecret_inSubDirectory(Vault vault) { var key = "sub/" + VAULT_ENTRY_KEY; var value = key + "value"; @@ -104,10 +84,8 @@ void testResolveSecret_inSubDirectory() { @ParameterizedTest @ValueSource(strings = { "foo!bar", "foo.bar", "foo[bar]", "sub/foo{bar}" }) @DisplayName("Resolve a secret with url encoded characters") - void testResolveSecret_withUrlEncodedCharacters(String key) { - var vault = getVault(); + void testResolveSecret_withUrlEncodedCharacters(String key, Vault vault) { var value = key + "value"; - vault.storeSecret(key, value); var secretValue = vault.resolveSecret(key); assertThat(secretValue).isEqualTo(value); @@ -115,19 +93,17 @@ void testResolveSecret_withUrlEncodedCharacters(String key) { @Test @DisplayName("Resolve a secret that does not exist") - void testResolveSecret_doesNotExist() { - var vault = getVault(); + void testResolveSecret_doesNotExist(Vault vault) { assertThat(vault.resolveSecret("wrong_key")).isNull(); } @Test @DisplayName("Update a secret that exists") - void testSetSecret_exists() { + void testSetSecret_exists(Vault vault) { var key = UUID.randomUUID().toString(); var value1 = UUID.randomUUID().toString(); var value2 = UUID.randomUUID().toString(); - var vault = getVault(); vault.storeSecret(key, value1); vault.storeSecret(key, value2); var secretValue = vault.resolveSecret(key); @@ -136,11 +112,10 @@ void testSetSecret_exists() { @Test @DisplayName("Create a secret that does not exist") - void testSetSecret_doesNotExist() { + void testSetSecret_doesNotExist(Vault vault) { var key = UUID.randomUUID().toString(); var value = UUID.randomUUID().toString(); - var vault = getVault(); vault.storeSecret(key, value); var secretValue = vault.resolveSecret(key); assertThat(secretValue).isEqualTo(value); @@ -148,11 +123,10 @@ void testSetSecret_doesNotExist() { @Test @DisplayName("Delete a secret that exists") - void testDeleteSecret_exists() { + void testDeleteSecret_exists(Vault vault) { var key = UUID.randomUUID().toString(); var value = UUID.randomUUID().toString(); - var vault = getVault(); vault.storeSecret(key, value); vault.deleteSecret(key); @@ -161,50 +135,37 @@ void testDeleteSecret_exists() { @Test @DisplayName("Try to delete a secret that does not exist") - void testDeleteSecret_doesNotExist() { + void testDeleteSecret_doesNotExist(Vault vault) { var key = UUID.randomUUID().toString(); - var vault = getVault(); vault.deleteSecret(key); - assertThat(vault.resolveSecret(key)).isNull(); } @Test - void resolveCertificate_success() throws CertificateException, IOException, NoSuchAlgorithmException, OperatorCreationException, org.bouncycastle.operator.OperatorCreationException { + void resolveCertificate_success(Vault vault, CertificateResolver resolver) throws CertificateException, IOException, NoSuchAlgorithmException, org.bouncycastle.operator.OperatorCreationException { var key = UUID.randomUUID().toString(); var certificateExpected = generateCertificate(5, "Test"); var pem = convertToPem(certificateExpected); - var vault = getVault(); vault.storeSecret(key, pem); - var resolver = getCertificateResolver(); var certificateResult = resolver.resolveCertificate(key); assertThat(certificateExpected).isEqualTo(certificateResult); } @Test - void resolveCertificate_malformed() { + void resolveCertificate_malformed(Vault vault, CertificateResolver resolver) { var key = UUID.randomUUID().toString(); var value = UUID.randomUUID().toString(); - var vault = getVault(); vault.storeSecret(key, value); - var resolver = getCertificateResolver(); var certificateResult = resolver.resolveCertificate(key); assertThat(certificateResult).isNull(); } - protected Vault getVault() { - return testExtension.getVault(); - } - - protected CertificateResolver getCertificateResolver() { - return testExtension.getCertificateResolver(); - } - protected Map getConfig() { + private Map getConfig() { return new HashMap<>() { { put(VAULT_URL, format("http://%s:%s", VAULTCONTAINER.getHost(), VAULTCONTAINER.getFirstMappedPort())); @@ -212,78 +173,4 @@ protected Map getConfig() { } }; } - - private static class TestExtension implements ServiceExtension { - private Vault vault; - private CertificateResolver certificateResolver; - - @Override - public void initialize(ServiceExtensionContext context) { - vault = context.getService(Vault.class); - certificateResolver = context.getService(CertificateResolver.class); - } - - public CertificateResolver getCertificateResolver() { - return certificateResolver; - } - - public Vault getVault() { - return vault; - } - } - - private static class MyHealthCheckService implements HealthCheckService { - private final List livenessProviders = new ArrayList<>(); - private final List readinessProviders = new ArrayList<>(); - private final List startupStatusProviders = new ArrayList<>(); - - @Override - public void addLivenessProvider(LivenessProvider provider) { - livenessProviders.add(provider); - } - - @Override - public void addReadinessProvider(ReadinessProvider provider) { - readinessProviders.add(provider); - } - - @Override - public void addStartupStatusProvider(StartupStatusProvider provider) { - startupStatusProviders.add(provider); - } - - @Override - public HealthStatus isLive() { - return new HealthStatus( - livenessProviders.stream() - .map( - p -> - p.get().failed() ? HealthCheckResult.failed("") : HealthCheckResult.success()) - .collect(Collectors.toList())); - } - - @Override - public HealthStatus isReady() { - return new HealthStatus( - readinessProviders.stream() - .map( - p -> - p.get().failed() ? HealthCheckResult.failed("") : HealthCheckResult.success()) - .collect(Collectors.toList())); - } - - @Override - public HealthStatus getStartupStatus() { - return new HealthStatus( - startupStatusProviders.stream() - .map( - p -> - p.get().failed() ? HealthCheckResult.failed("") : HealthCheckResult.success()) - .collect(Collectors.toList())); - } - - @Override - public void refresh() { - } - } } diff --git a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultTest.java b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultTest.java index 43ea41c36ce..f64a0781d3a 100644 --- a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultTest.java +++ b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/HashicorpVaultTest.java @@ -16,15 +16,16 @@ import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.result.Result; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class HashicorpVaultTest { private static final String KEY = "key"; @@ -35,34 +36,34 @@ class HashicorpVaultTest { @BeforeEach void setup() { - vaultClient = Mockito.mock(HashicorpVaultClient.class); - var monitor = Mockito.mock(Monitor.class); + vaultClient = mock(); + var monitor = mock(Monitor.class); vault = new HashicorpVault(vaultClient, monitor); } @Test void getSecretSuccess() { // prepare - Mockito.when(vaultClient.getSecretValue(KEY)).thenReturn(Result.success("test-secret")); + when(vaultClient.getSecretValue(KEY)).thenReturn(Result.success("test-secret")); // invoke var returnValue = vault.resolveSecret(KEY); // verify - verify(vaultClient, Mockito.times(1)).getSecretValue(KEY); + verify(vaultClient, times(1)).getSecretValue(KEY); assertThat(returnValue).isEqualTo("test-secret"); } @Test void getSecretFailure() { // prepare - Mockito.when(vaultClient.getSecretValue(KEY)).thenReturn(Result.failure("test-failure")); + when(vaultClient.getSecretValue(KEY)).thenReturn(Result.failure("test-failure")); // invoke var returnValue = vault.resolveSecret(KEY); // verify - verify(vaultClient, Mockito.times(1)).getSecretValue(KEY); + verify(vaultClient, times(1)).getSecretValue(KEY); assertThat(returnValue).isNull(); } @@ -70,53 +71,53 @@ void getSecretFailure() { void setSecretSuccess() { // prepare var value = UUID.randomUUID().toString(); - Mockito.when(vaultClient.setSecret(KEY, value)).thenReturn(Result.success(null)); + when(vaultClient.setSecret(KEY, value)).thenReturn(Result.success(null)); // invoke var returnValue = vault.storeSecret(KEY, value); // verify - verify(vaultClient, Mockito.times(1)).setSecret(KEY, value); - Assertions.assertTrue(returnValue.succeeded()); + verify(vaultClient, times(1)).setSecret(KEY, value); + assertThat(returnValue.succeeded()).isTrue(); } @Test void setSecretFailure() { // prepare var value = UUID.randomUUID().toString(); - Mockito.when(vaultClient.setSecret(KEY, value)).thenReturn(Result.failure("test-failure")); + when(vaultClient.setSecret(KEY, value)).thenReturn(Result.failure("test-failure")); // invoke var returnValue = vault.storeSecret(KEY, value); // verify - verify(vaultClient, Mockito.times(1)).setSecret(KEY, value); - Assertions.assertTrue(returnValue.failed()); + verify(vaultClient, times(1)).setSecret(KEY, value); + assertThat(returnValue.failed()).isTrue(); } @Test void destroySecretSuccess() { // prepare - Mockito.when(vaultClient.destroySecret(KEY)).thenReturn(Result.success()); + when(vaultClient.destroySecret(KEY)).thenReturn(Result.success()); // invoke var returnValue = vault.deleteSecret(KEY); // verify - verify(vaultClient, Mockito.times(1)).destroySecret(KEY); - Assertions.assertTrue(returnValue.succeeded()); + verify(vaultClient, times(1)).destroySecret(KEY); + assertThat(returnValue.succeeded()).isTrue(); } @Test void destroySecretFailure() { // prepare - Mockito.when(vaultClient.destroySecret(KEY)).thenReturn(Result.failure("test-failure")); + when(vaultClient.destroySecret(KEY)).thenReturn(Result.failure("test-failure")); // invoke var returnValue = vault.deleteSecret(KEY); // verify - verify(vaultClient, Mockito.times(1)).destroySecret(KEY); - Assertions.assertTrue(returnValue.failed()); + verify(vaultClient, times(1)).destroySecret(KEY); + assertThat(returnValue.failed()).isTrue(); } } diff --git a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/PathUtilTest.java b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/PathUtilTest.java index 1bdf0e5b4f9..3ae20c39a4f 100644 --- a/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/PathUtilTest.java +++ b/extensions/common/vault/vault-hashicorp/src/test/java/org/eclipse/edc/vault/hashicorp/PathUtilTest.java @@ -14,28 +14,35 @@ package org.eclipse.edc.vault.hashicorp; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.stream.Stream; +import static org.assertj.core.api.Assertions.assertThat; + class PathUtilTest { - private static Stream provideStringsForTrimsPathsCorrect() { - return Stream.of( - Arguments.of("v1/secret/data", "v1/secret/data"), - Arguments.of("/v1/secret/data", "v1/secret/data"), - Arguments.of("/v1/secret/data/", "v1/secret/data"), - Arguments.of("v1/secret/data/", "v1/secret/data")); - } @ParameterizedTest - @MethodSource("provideStringsForTrimsPathsCorrect") + @ArgumentsSource(CorrectPathsProvider.class) void trimsPathsCorrect(String path, String expected) { final String result = PathUtil.trimLeadingOrEndingSlash(path); - Assertions.assertEquals(expected, result); + assertThat(expected).isEqualTo(result); + } + + private static class CorrectPathsProvider implements ArgumentsProvider { + @Override + public Stream provideArguments(ExtensionContext context) { + return Stream.of( + Arguments.of("v1/secret/data", "v1/secret/data"), + Arguments.of("/v1/secret/data", "v1/secret/data"), + Arguments.of("/v1/secret/data/", "v1/secret/data"), + Arguments.of("v1/secret/data/", "v1/secret/data")); + } } } diff --git a/extensions/control-plane/store/sql/asset-index-sql/build.gradle.kts b/extensions/control-plane/store/sql/asset-index-sql/build.gradle.kts index d59d41f57ab..163244fc611 100644 --- a/extensions/control-plane/store/sql/asset-index-sql/build.gradle.kts +++ b/extensions/control-plane/store/sql/asset-index-sql/build.gradle.kts @@ -31,6 +31,8 @@ dependencies { testImplementation(testFixtures(project(":extensions:common:sql:sql-core"))) testImplementation(libs.postgres) + testImplementation(libs.testcontainers.junit) + testImplementation(libs.testcontainers.postgres) } diff --git a/extensions/control-plane/store/sql/asset-index-sql/src/test/java/org/eclipse/edc/connector/store/sql/assetindex/PostgresAssetIndexTest.java b/extensions/control-plane/store/sql/asset-index-sql/src/test/java/org/eclipse/edc/connector/store/sql/assetindex/PostgresAssetIndexTest.java index de80fa44bde..758b6dc1a9b 100644 --- a/extensions/control-plane/store/sql/asset-index-sql/src/test/java/org/eclipse/edc/connector/store/sql/assetindex/PostgresAssetIndexTest.java +++ b/extensions/control-plane/store/sql/asset-index-sql/src/test/java/org/eclipse/edc/connector/store/sql/assetindex/PostgresAssetIndexTest.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.edc.connector.store.sql.assetindex.schema.BaseSqlDialectStatements; import org.eclipse.edc.connector.store.sql.assetindex.schema.postgres.PostgresDialectStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.policy.model.PolicyRegistrationTypes; import org.eclipse.edc.spi.testfixtures.asset.AssetIndexTestBase; import org.eclipse.edc.spi.types.TypeManager; @@ -32,7 +32,7 @@ import java.nio.file.Files; import java.nio.file.Paths; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresAssetIndexTest extends AssetIndexTestBase { diff --git a/extensions/control-plane/store/sql/contract-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractdefinition/PostgresContractDefinitionStoreTest.java b/extensions/control-plane/store/sql/contract-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractdefinition/PostgresContractDefinitionStoreTest.java index 7671dcc6aaa..f3c2d758d65 100644 --- a/extensions/control-plane/store/sql/contract-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractdefinition/PostgresContractDefinitionStoreTest.java +++ b/extensions/control-plane/store/sql/contract-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractdefinition/PostgresContractDefinitionStoreTest.java @@ -20,7 +20,7 @@ import org.eclipse.edc.connector.contract.spi.testfixtures.offer.store.TestFunctions; import org.eclipse.edc.connector.store.sql.contractdefinition.schema.BaseSqlDialectStatements; import org.eclipse.edc.connector.store.sql.contractdefinition.schema.postgres.PostgresDialectStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.policy.model.PolicyRegistrationTypes; import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.spi.query.QuerySpec; @@ -42,7 +42,7 @@ import static java.util.stream.IntStream.range; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresContractDefinitionStoreTest extends ContractDefinitionStoreTestBase { diff --git a/extensions/control-plane/store/sql/contract-negotiation-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractnegotiation/store/PostgresContractNegotiationStoreTest.java b/extensions/control-plane/store/sql/contract-negotiation-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractnegotiation/store/PostgresContractNegotiationStoreTest.java index cc0979e3b2e..60afb1602e4 100644 --- a/extensions/control-plane/store/sql/contract-negotiation-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractnegotiation/store/PostgresContractNegotiationStoreTest.java +++ b/extensions/control-plane/store/sql/contract-negotiation-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/contractnegotiation/store/PostgresContractNegotiationStoreTest.java @@ -17,7 +17,7 @@ import org.eclipse.edc.connector.contract.spi.ContractId; import org.eclipse.edc.connector.contract.spi.testfixtures.negotiation.store.ContractNegotiationStoreTestBase; import org.eclipse.edc.connector.store.sql.contractnegotiation.store.schema.postgres.PostgresDialectStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.policy.model.Action; import org.eclipse.edc.policy.model.AtomicConstraint; import org.eclipse.edc.policy.model.LiteralExpression; @@ -62,14 +62,14 @@ * This test aims to verify those parts of the contract negotiation store, that are specific to Postgres, e.g. JSON * query operators. */ -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresContractNegotiationStoreTest extends ContractNegotiationStoreTestBase { private static final String TEST_ASSET_ID = "test-asset-id"; + private final Clock clock = Clock.systemUTC(); private SqlContractNegotiationStore store; private LeaseUtil leaseUtil; - private final Clock clock = Clock.systemUTC(); @BeforeEach void setUp(PostgresqlStoreSetupExtension extension, QueryExecutor queryExecutor) throws IOException { @@ -257,7 +257,7 @@ void nextNotLeased_typeFilter() { .state(REQUESTED.code()) .type(CONSUMER) .build()).forEach(store::save); - var criteria = new Criterion[]{hasState(REQUESTED.code()), new Criterion("type", "=", "CONSUMER")}; + var criteria = new Criterion[]{ hasState(REQUESTED.code()), new Criterion("type", "=", "CONSUMER") }; var result = store.nextNotLeased(10, criteria); diff --git a/extensions/control-plane/store/sql/policy-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/policydefinition/PostgresPolicyDefinitionStoreTest.java b/extensions/control-plane/store/sql/policy-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/policydefinition/PostgresPolicyDefinitionStoreTest.java index 5cbca3473fb..d2547f315bd 100644 --- a/extensions/control-plane/store/sql/policy-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/policydefinition/PostgresPolicyDefinitionStoreTest.java +++ b/extensions/control-plane/store/sql/policy-definition-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/policydefinition/PostgresPolicyDefinitionStoreTest.java @@ -18,7 +18,7 @@ import org.eclipse.edc.connector.policy.spi.testfixtures.store.PolicyDefinitionStoreTestBase; import org.eclipse.edc.connector.store.sql.policydefinition.store.SqlPolicyDefinitionStore; import org.eclipse.edc.connector.store.sql.policydefinition.store.schema.postgres.PostgresDialectStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.policy.model.PolicyRegistrationTypes; import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.edc.spi.query.SortOrder; @@ -44,7 +44,7 @@ * This test aims to verify those parts of the policy definition store, that are specific to Postgres, e.g. JSON query * operators. */ -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresPolicyDefinitionStoreTest extends PolicyDefinitionStoreTestBase { diff --git a/extensions/control-plane/store/sql/transfer-process-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/transferprocess/PostgresTransferProcessStoreTest.java b/extensions/control-plane/store/sql/transfer-process-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/transferprocess/PostgresTransferProcessStoreTest.java index 62f25c3478e..6b701cff8c0 100644 --- a/extensions/control-plane/store/sql/transfer-process-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/transferprocess/PostgresTransferProcessStoreTest.java +++ b/extensions/control-plane/store/sql/transfer-process-store-sql/src/test/java/org/eclipse/edc/connector/store/sql/transferprocess/PostgresTransferProcessStoreTest.java @@ -20,7 +20,7 @@ import org.eclipse.edc.connector.transfer.spi.testfixtures.store.TransferProcessStoreTestBase; import org.eclipse.edc.connector.transfer.spi.types.ProvisionedResourceSet; import org.eclipse.edc.connector.transfer.spi.types.ResourceManifest; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.policy.model.PolicyRegistrationTypes; import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.spi.query.QuerySpec; @@ -49,7 +49,7 @@ import static org.eclipse.edc.connector.transfer.spi.testfixtures.store.TestFunctions.createTransferProcess; import static org.eclipse.edc.connector.transfer.spi.testfixtures.store.TestFunctions.createTransferProcessBuilder; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) class PostgresTransferProcessStoreTest extends TransferProcessStoreTestBase { diff --git a/extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/selector/store/sql/PostgresDataPlaneInstanceStoreTest.java b/extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/selector/store/sql/PostgresDataPlaneInstanceStoreTest.java index c8e533a12b9..aec8fcaabb6 100644 --- a/extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/selector/store/sql/PostgresDataPlaneInstanceStoreTest.java +++ b/extensions/data-plane-selector/store/sql/data-plane-instance-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/selector/store/sql/PostgresDataPlaneInstanceStoreTest.java @@ -19,7 +19,7 @@ import org.eclipse.edc.connector.dataplane.selector.spi.testfixtures.store.DataPlaneInstanceStoreTestBase; import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.DataPlaneInstanceStatements; import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.postgres.PostgresDataPlaneInstanceStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.testfixtures.PostgresqlLocalInstance; @@ -35,7 +35,7 @@ import java.sql.SQLException; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) public class PostgresDataPlaneInstanceStoreTest extends DataPlaneInstanceStoreTestBase { @@ -45,8 +45,8 @@ public class PostgresDataPlaneInstanceStoreTest extends DataPlaneInstanceStoreTe SqlDataPlaneInstanceStore store; @BeforeAll - static void prepare() { - PostgresqlLocalInstance.createTestDatabase(); + static void prepare(PostgresqlLocalInstance postgres) { + postgres.createDatabase(); } @BeforeEach diff --git a/extensions/data-plane/store/sql/data-plane-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/store/sql/PostgresDataPlaneStoreTest.java b/extensions/data-plane/store/sql/data-plane-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/store/sql/PostgresDataPlaneStoreTest.java index 2d45603cc9d..fd9874f42ee 100644 --- a/extensions/data-plane/store/sql/data-plane-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/store/sql/PostgresDataPlaneStoreTest.java +++ b/extensions/data-plane/store/sql/data-plane-store-sql/src/test/java/org/eclipse/edc/connector/dataplane/store/sql/PostgresDataPlaneStoreTest.java @@ -18,7 +18,7 @@ import org.eclipse.edc.connector.dataplane.spi.testfixtures.store.DataPlaneStoreTestBase; import org.eclipse.edc.connector.dataplane.store.sql.schema.DataPlaneStatements; import org.eclipse.edc.connector.dataplane.store.sql.schema.postgres.PostgresDataPlaneStatements; -import org.eclipse.edc.junit.annotations.PostgresqlDbIntegrationTest; +import org.eclipse.edc.junit.annotations.ComponentTest; import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.testfixtures.PostgresqlStoreSetupExtension; @@ -32,7 +32,7 @@ import java.time.Clock; -@PostgresqlDbIntegrationTest +@ComponentTest @ExtendWith(PostgresqlStoreSetupExtension.class) public class PostgresDataPlaneStoreTest extends DataPlaneStoreTestBase { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3c889829fd1..125f516f5b6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -90,6 +90,7 @@ swagger-annotations-jakarta = { module = "io.swagger.core.v3:swagger-annotations titaniumJsonLd = { module = "com.apicatalog:titanium-json-ld", version.ref = "titanium" } testcontainers-vault = { module = "org.testcontainers:vault", version.ref = "testcontainers" } testcontainers-junit = { module = "org.testcontainers:junit-jupiter", version.ref = "testcontainers" } +testcontainers-postgres = { module = "org.testcontainers:postgresql", version.ref = "testcontainers" } # other technology extensions apache-commons-pool = { module = "org.apache.commons:commons-pool2", version.ref = "apacheCommonsPool2" } diff --git a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/EndToEndTransferPostgresqlTest.java b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/EndToEndTransferPostgresqlTest.java index cfec5435133..e0f8e34ad93 100644 --- a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/EndToEndTransferPostgresqlTest.java +++ b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/EndToEndTransferPostgresqlTest.java @@ -29,8 +29,9 @@ import java.util.HashMap; import java.util.stream.Stream; -import static org.eclipse.edc.sql.testfixtures.PostgresqlLocalInstance.PASSWORD; -import static org.eclipse.edc.sql.testfixtures.PostgresqlLocalInstance.USER; +import static org.eclipse.edc.test.e2e.PostgresConstants.JDBC_URL_PREFIX; +import static org.eclipse.edc.test.e2e.PostgresConstants.PASSWORD; +import static org.eclipse.edc.test.e2e.PostgresConstants.USER; @PostgresqlDbIntegrationTest class EndToEndTransferPostgresqlTest extends AbstractEndToEndTransfer { @@ -94,7 +95,8 @@ static void beforeAll() throws SQLException, IOException, ClassNotFoundException private static void createDatabase(Participant consumer) throws ClassNotFoundException, SQLException, IOException { Class.forName("org.postgresql.Driver"); - PostgresqlLocalInstance.createDatabase(consumer.getName()); + var helper = new PostgresqlLocalInstance(USER, PASSWORD, JDBC_URL_PREFIX, consumer.getName()); + helper.createDatabase(consumer.getName()); var scripts = Stream.of( "asset-index-sql", diff --git a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/Participant.java b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/Participant.java index 3bd559361c9..514b6c303ae 100644 --- a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/Participant.java +++ b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/Participant.java @@ -27,7 +27,6 @@ import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.monitor.ConsoleMonitor; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; -import org.eclipse.edc.sql.testfixtures.PostgresqlLocalInstance; import org.hamcrest.Matcher; import org.jetbrains.annotations.NotNull; @@ -425,24 +424,24 @@ public Map controlPlanePostgresConfiguration() { { put("edc.datasource.asset.name", "asset"); put("edc.datasource.asset.url", jdbcUrl()); - put("edc.datasource.asset.user", PostgresqlLocalInstance.USER); - put("edc.datasource.asset.password", PostgresqlLocalInstance.PASSWORD); + put("edc.datasource.asset.user", PostgresConstants.USER); + put("edc.datasource.asset.password", PostgresConstants.PASSWORD); put("edc.datasource.contractdefinition.name", "contractdefinition"); put("edc.datasource.contractdefinition.url", jdbcUrl()); - put("edc.datasource.contractdefinition.user", PostgresqlLocalInstance.USER); - put("edc.datasource.contractdefinition.password", PostgresqlLocalInstance.PASSWORD); + put("edc.datasource.contractdefinition.user", PostgresConstants.USER); + put("edc.datasource.contractdefinition.password", PostgresConstants.PASSWORD); put("edc.datasource.contractnegotiation.name", "contractnegotiation"); put("edc.datasource.contractnegotiation.url", jdbcUrl()); - put("edc.datasource.contractnegotiation.user", PostgresqlLocalInstance.USER); - put("edc.datasource.contractnegotiation.password", PostgresqlLocalInstance.PASSWORD); + put("edc.datasource.contractnegotiation.user", PostgresConstants.USER); + put("edc.datasource.contractnegotiation.password", PostgresConstants.PASSWORD); put("edc.datasource.policy.name", "policy"); put("edc.datasource.policy.url", jdbcUrl()); - put("edc.datasource.policy.user", PostgresqlLocalInstance.USER); - put("edc.datasource.policy.password", PostgresqlLocalInstance.PASSWORD); + put("edc.datasource.policy.user", PostgresConstants.USER); + put("edc.datasource.policy.password", PostgresConstants.PASSWORD); put("edc.datasource.transferprocess.name", "transferprocess"); put("edc.datasource.transferprocess.url", jdbcUrl()); - put("edc.datasource.transferprocess.user", PostgresqlLocalInstance.USER); - put("edc.datasource.transferprocess.password", PostgresqlLocalInstance.PASSWORD); + put("edc.datasource.transferprocess.user", PostgresConstants.USER); + put("edc.datasource.transferprocess.password", PostgresConstants.PASSWORD); } }; baseConfiguration.putAll(postgresConfiguration); @@ -452,7 +451,7 @@ public Map controlPlanePostgresConfiguration() { @NotNull public String jdbcUrl() { - return PostgresqlLocalInstance.JDBC_URL_PREFIX + name; + return PostgresConstants.JDBC_URL_PREFIX + name; } public Map dataPlaneConfiguration() { diff --git a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/PostgresConstants.java b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/PostgresConstants.java new file mode 100644 index 00000000000..e4de1505587 --- /dev/null +++ b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/PostgresConstants.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.test.e2e; + +public interface PostgresConstants { + String USER = "postgres"; + String PASSWORD = "password"; + String JDBC_URL_PREFIX = "jdbc:postgresql://localhost:5432/"; +}