You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/12/04 07:38:43 UTC
(james-project) branch postgresql updated: JAMES-2586 postgres-app should run tests against Postgresql container for both JPA and Postgres r2dbc
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch postgresql
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/postgresql by this push:
new d13bc2d856 JAMES-2586 postgres-app should run tests against Postgresql container for both JPA and Postgres r2dbc
d13bc2d856 is described below
commit d13bc2d8560f4c6541dda54809b0c14c87c1391a
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Mon Dec 4 13:35:15 2023 +0700
JAMES-2586 postgres-app should run tests against Postgresql container for both JPA and Postgres r2dbc
JPA code was pointed to embedded Derby before.
---
.../james/backends/postgres/PostgresExtension.java | 8 +++
.../apache/james/JamesCapabilitiesServerTest.java | 6 +-
.../org/apache/james/PostgresJamesServerTest.java | 6 +-
...WithAuthenticatedDatabaseSqlValidationTest.java | 5 +-
...atabaseAuthenticaticationSqlValidationTest.java | 38 +++++++++-
.../james/PostgresWithLDAPJamesServerTest.java | 6 +-
server/container/guice/postgres-common/pom.xml | 17 ++++-
.../apache/james/TestJPAConfigurationModule.java | 17 +++--
...estJPAConfigurationModuleWithSqlValidation.java | 80 ++++++++--------------
9 files changed, 115 insertions(+), 68 deletions(-)
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
index 476b5819ee..126cc722b1 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
@@ -194,6 +194,14 @@ public class PostgresExtension implements GuiceModuleTestExtension {
return executorFactory;
}
+ public PostgresConfiguration getPostgresConfiguration() {
+ return postgresConfiguration;
+ }
+
+ public String getJdbcUrl() {
+ return String.format("jdbc:postgresql://%s:%d/%s", getHost(), getMappedPort(), postgresConfiguration.getDatabaseName());
+ }
+
private void initTablesAndIndexes() {
PostgresTableManager postgresTableManager = new PostgresTableManager(postgresExecutor, postgresModule, postgresConfiguration.rowLevelSecurityEnabled());
postgresTableManager.initializeTables().block();
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 16568dc900..652d35788b 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -41,6 +41,8 @@ class JamesCapabilitiesServerTest {
return mailboxManager;
}
+ static PostgresExtension postgresExtension = PostgresExtension.empty();
+
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
PostgresJamesConfiguration.builder()
@@ -49,9 +51,9 @@ class JamesCapabilitiesServerTest {
.usersRepository(DEFAULT)
.build())
.server(configuration -> PostgresJamesServerMain.createServer(configuration)
- .overrideWith(new TestJPAConfigurationModule())
+ .overrideWith(new TestJPAConfigurationModule(postgresExtension))
.overrideWith(binder -> binder.bind(MailboxManager.class).toInstance(mailboxManager())))
- .extension(PostgresExtension.empty())
+ .extension(postgresExtension)
.build();
@Test
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
index 52654ba7b6..2e03f181cd 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
@@ -41,6 +41,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import com.google.common.base.Strings;
class PostgresJamesServerTest implements JamesServerConcreteContract {
+ static PostgresExtension postgresExtension = PostgresExtension.empty();
+
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
PostgresJamesConfiguration.builder()
@@ -49,8 +51,8 @@ class PostgresJamesServerTest implements JamesServerConcreteContract {
.usersRepository(DEFAULT)
.build())
.server(configuration -> PostgresJamesServerMain.createServer(configuration)
- .overrideWith(new TestJPAConfigurationModule()))
- .extension(PostgresExtension.empty())
+ .overrideWith(new TestJPAConfigurationModule(postgresExtension)))
+ .extension(postgresExtension)
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
index 55fd090c49..2e0fc42cd5 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
@@ -25,6 +25,7 @@ import org.apache.james.backends.postgres.PostgresExtension;
import org.junit.jupiter.api.extension.RegisterExtension;
class PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest extends PostgresJamesServerWithSqlValidationTest {
+ static PostgresExtension postgresExtension = PostgresExtension.empty();
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
@@ -34,8 +35,8 @@ class PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest extends Post
.usersRepository(DEFAULT)
.build())
.server(configuration -> PostgresJamesServerMain.createServer(configuration)
- .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.WithDatabaseAuthentication()))
- .extension(PostgresExtension.empty())
+ .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.WithDatabaseAuthentication(postgresExtension)))
+ .extension(postgresExtension)
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();
}
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
index 44f9620748..37d5491075 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
@@ -22,9 +22,12 @@ package org.apache.james;
import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;
import org.apache.james.backends.postgres.PostgresExtension;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.RegisterExtension;
class PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest extends PostgresJamesServerWithSqlValidationTest {
+ static PostgresExtension postgresExtension = PostgresExtension.empty();
+
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
PostgresJamesConfiguration.builder()
@@ -33,8 +36,39 @@ class PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest exten
.usersRepository(DEFAULT)
.build())
.server(configuration -> PostgresJamesServerMain.createServer(configuration)
- .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.NoDatabaseAuthentication()))
- .extension(PostgresExtension.empty())
+ .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.NoDatabaseAuthentication(postgresExtension)))
+ .extension(postgresExtension)
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void jpaGuiceServerShouldUpdateQuota(GuiceJamesServer jamesServer) {
+
+ }
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void connectIMAPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) {
+ }
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void connectOnSecondaryIMAPServerIMAPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) {
+ }
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void connectPOP3ServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) {
+ }
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void connectSMTPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) {
+ }
+
+ @Override
+ @Disabled("PostgresExtension does not support non-authentication mode. SQL validation for JPA code with authentication should be enough.")
+ public void connectLMTPServerShouldSendShabangOnConnect(GuiceJamesServer jamesServer) {
+ }
}
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
index 6bc0e02a95..8f02723bf5 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
@@ -34,6 +34,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
class PostgresWithLDAPJamesServerTest {
+ static PostgresExtension postgresExtension = PostgresExtension.empty();
+
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
PostgresJamesConfiguration.builder()
@@ -42,10 +44,10 @@ class PostgresWithLDAPJamesServerTest {
.usersRepository(LDAP)
.build())
.server(configuration -> PostgresJamesServerMain.createServer(configuration)
- .overrideWith(new TestJPAConfigurationModule()))
+ .overrideWith(new TestJPAConfigurationModule(postgresExtension)))
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.extension(new LdapTestExtension())
- .extension(PostgresExtension.empty())
+ .extension(postgresExtension)
.build();
diff --git a/server/container/guice/postgres-common/pom.xml b/server/container/guice/postgres-common/pom.xml
index dc1f2e8ad8..503c786433 100644
--- a/server/container/guice/postgres-common/pom.xml
+++ b/server/container/guice/postgres-common/pom.xml
@@ -38,6 +38,12 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-backends-postgres</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-data-file</artifactId>
@@ -50,6 +56,12 @@
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>james-server-guice-common</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-mailbox-adapter</artifactId>
@@ -60,8 +72,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>42.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModule.java b/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModule.java
index 957cddc27d..19ca6b6188 100644
--- a/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModule.java
+++ b/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModule.java
@@ -22,14 +22,19 @@ package org.apache.james;
import javax.inject.Singleton;
import org.apache.james.backends.jpa.JPAConfiguration;
+import org.apache.james.backends.postgres.PostgresExtension;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
public class TestJPAConfigurationModule extends AbstractModule {
+ public static final String JDBC_EMBEDDED_DRIVER = org.postgresql.Driver.class.getName();
- private static final String JDBC_EMBEDDED_URL = "jdbc:derby:memory:mailboxintegration;create=true";
- private static final String JDBC_EMBEDDED_DRIVER = org.apache.derby.jdbc.EmbeddedDriver.class.getName();
+ private final PostgresExtension postgresExtension;
+
+ public TestJPAConfigurationModule(PostgresExtension postgresExtension) {
+ this.postgresExtension = postgresExtension;
+ }
@Override
protected void configure() {
@@ -39,8 +44,10 @@ public class TestJPAConfigurationModule extends AbstractModule {
@Singleton
JPAConfiguration provideConfiguration() {
return JPAConfiguration.builder()
- .driverName(JDBC_EMBEDDED_DRIVER)
- .driverURL(JDBC_EMBEDDED_URL)
- .build();
+ .driverName(JDBC_EMBEDDED_DRIVER)
+ .driverURL(postgresExtension.getJdbcUrl())
+ .username(postgresExtension.getPostgresConfiguration().getCredential().getUsername())
+ .password(postgresExtension.getPostgresConfiguration().getCredential().getPassword())
+ .build();
}
}
diff --git a/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java b/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
index 1cf89b519b..dce784827b 100644
--- a/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
+++ b/server/container/guice/postgres-common/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
@@ -19,14 +19,12 @@
package org.apache.james;
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import static org.apache.james.TestJPAConfigurationModule.JDBC_EMBEDDED_DRIVER;
import javax.inject.Singleton;
import org.apache.james.backends.jpa.JPAConfiguration;
+import org.apache.james.backends.postgres.PostgresExtension;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
@@ -34,6 +32,12 @@ import com.google.inject.Provides;
public interface TestJPAConfigurationModuleWithSqlValidation {
class NoDatabaseAuthentication extends AbstractModule {
+ private final PostgresExtension postgresExtension;
+
+ public NoDatabaseAuthentication(PostgresExtension postgresExtension) {
+ this.postgresExtension = postgresExtension;
+ }
+
@Override
protected void configure() {
}
@@ -41,68 +45,42 @@ public interface TestJPAConfigurationModuleWithSqlValidation {
@Provides
@Singleton
JPAConfiguration provideConfiguration() {
- return jpaConfigurationBuilder().build();
+ return JPAConfiguration.builder()
+ .driverName(JDBC_EMBEDDED_DRIVER)
+ .driverURL(postgresExtension.getJdbcUrl())
+ .testOnBorrow(true)
+ .validationQueryTimeoutSec(2)
+ .validationQuery(VALIDATION_SQL_QUERY)
+ .build();
}
}
class WithDatabaseAuthentication extends AbstractModule {
+ private final PostgresExtension postgresExtension;
+
+ public WithDatabaseAuthentication(PostgresExtension postgresExtension) {
+ this.postgresExtension = postgresExtension;
+ }
@Override
protected void configure() {
- setupAuthenticationOnDerby();
+
}
@Provides
@Singleton
JPAConfiguration provideConfiguration() {
- return jpaConfigurationBuilder()
- .username(DATABASE_USERNAME)
- .password(DATABASE_PASSWORD)
+ return JPAConfiguration.builder()
+ .driverName(JDBC_EMBEDDED_DRIVER)
+ .driverURL(postgresExtension.getJdbcUrl())
+ .testOnBorrow(true)
+ .validationQueryTimeoutSec(2)
+ .validationQuery(VALIDATION_SQL_QUERY)
+ .username(postgresExtension.getPostgresConfiguration().getCredential().getUsername())
+ .password(postgresExtension.getPostgresConfiguration().getCredential().getPassword())
.build();
}
-
- private void setupAuthenticationOnDerby() {
- try (Connection conn = DriverManager.getConnection(JDBC_EMBEDDED_URL, DATABASE_USERNAME, DATABASE_PASSWORD)) {
- // Setting and Confirming requireAuthentication
- setDerbyProperty(conn, "derby.connection.requireAuthentication", "true");
-
- // Setting authentication scheme and username password to Derby
- setDerbyProperty(conn, "derby.authentication.provider", "BUILTIN");
- setDerbyProperty(conn, "derby.user." + DATABASE_USERNAME + "", DATABASE_PASSWORD);
- setDerbyProperty(conn, "derby.database.propertiesOnly", "true");
-
- // Setting default connection mode to no access to restrict accesses without authentication information
- setDerbyProperty(conn, "derby.database.defaultConnectionMode", "noAccess");
- setDerbyProperty(conn, "derby.database.fullAccessUsers", DATABASE_USERNAME);
- setDerbyProperty(conn, "derby.database.propertiesOnly", "false");
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void setDerbyProperty(Connection conn, String key, String value) {
- try (CallableStatement call = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)")) {
- call.setString(1, key);
- call.setString(2, value);
- call.execute();
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
}
- String DATABASE_USERNAME = "james";
- String DATABASE_PASSWORD = "james-secret";
- String JDBC_EMBEDDED_URL = "jdbc:derby:memory:mailboxintegration;create=true";
- String JDBC_EMBEDDED_DRIVER = org.apache.derby.jdbc.EmbeddedDriver.class.getName();
String VALIDATION_SQL_QUERY = "VALUES 1";
-
- static JPAConfiguration.ReadyToBuild jpaConfigurationBuilder() {
- return JPAConfiguration.builder()
- .driverName(JDBC_EMBEDDED_DRIVER)
- .driverURL(JDBC_EMBEDDED_URL)
- .testOnBorrow(true)
- .validationQueryTimeoutSec(2)
- .validationQuery(VALIDATION_SQL_QUERY);
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org