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

commit e74e0f6eeeab19b7f1c12bf7a7d7883709b7ce34
Author: Benoit TELLIER <[email protected]>
AuthorDate: Fri Nov 10 13:40:58 2023 +0100

    JAMES-2586 PostgresExtension: favor factory methods to constructor
---
 .../postgres/ConnectionThreadSafetyTest.java       |  2 +-
 .../james/backends/postgres/PostgresExtension.java | 28 ++++++++++++----------
 .../backends/postgres/PostgresExtensionTest.java   |  2 +-
 .../postgres/PostgresTableManagerTest.java         |  2 +-
 .../SimpleJamesPostgresConnectionFactoryTest.java  |  2 +-
 .../mailbox/postgres/JPAMailboxManagerTest.java    |  2 +-
 .../postgres/JpaMailboxManagerStressTest.java      |  2 +-
 .../postgres/PostgresSubscriptionManagerTest.java  |  2 +-
 .../task/JPARecomputeCurrentQuotasServiceTest.java |  2 +-
 ...gresSubscriptionMapperRowLevelSecurityTest.java |  2 +-
 .../user/PostgresSubscriptionMapperTest.java       |  2 +-
 .../apache/james/JamesCapabilitiesServerTest.java  |  2 +-
 .../org/apache/james/PostgresJamesServerTest.java  |  2 +-
 ...WithAuthenticatedDatabaseSqlValidationTest.java |  2 +-
 ...atabaseAuthenticaticationSqlValidationTest.java |  2 +-
 .../james/PostgresWithLDAPJamesServerTest.java     |  2 +-
 16 files changed, 30 insertions(+), 28 deletions(-)

diff --git 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
index 20eedcee4d..80b927a5a2 100644
--- 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
+++ 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
@@ -57,7 +57,7 @@ public class ConnectionThreadSafetyTest {
         ");";
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     private static PostgresqlConnection postgresqlConnection;
     private static SimpleJamesPostgresConnectionFactory 
jamesPostgresConnectionFactory;
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 086080b84f..682fc49696 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
@@ -36,29 +36,31 @@ import io.r2dbc.spi.ConnectionFactory;
 import reactor.core.publisher.Mono;
 
 public class PostgresExtension implements GuiceModuleTestExtension {
+    private static final boolean ROW_LEVEL_SECURITY_ENABLED = true;
+
+    public static PostgresExtension withRowLevelSecurity(PostgresModule 
module) {
+        return new PostgresExtension(module, ROW_LEVEL_SECURITY_ENABLED);
+    }
+
+    public static PostgresExtension withoutRowLevelSecurity(PostgresModule 
module) {
+        return new PostgresExtension(module, !ROW_LEVEL_SECURITY_ENABLED);
+    }
+
+    public static PostgresExtension empty() {
+        return withoutRowLevelSecurity(PostgresModule.EMPTY_MODULE);
+    }
+
     private final PostgresModule postgresModule;
     private final boolean rlsEnabled;
     private PostgresConfiguration postgresConfiguration;
     private PostgresExecutor postgresExecutor;
     private PostgresqlConnectionFactory connectionFactory;
 
-    public PostgresExtension(PostgresModule postgresModule, boolean 
rlsEnabled) {
+    private PostgresExtension(PostgresModule postgresModule, boolean 
rlsEnabled) {
         this.postgresModule = postgresModule;
         this.rlsEnabled = rlsEnabled;
     }
 
-    public PostgresExtension(PostgresModule postgresModule) {
-        this(postgresModule, false);
-    }
-
-    public PostgresExtension(boolean rlsEnabled) {
-        this(PostgresModule.EMPTY_MODULE, rlsEnabled);
-    }
-
-    public PostgresExtension() {
-        this(false);
-    }
-
     @Override
     public void beforeAll(ExtensionContext extensionContext) throws Exception {
         if (!DockerPostgresSingleton.SINGLETON.isRunning()) {
diff --git 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
index f1593fef21..406ba4b6bc 100644
--- 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
+++ 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
@@ -59,7 +59,7 @@ class PostgresExtensionTest {
         .build();
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(POSTGRES_MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(POSTGRES_MODULE);
 
     @Test
     void postgresExtensionShouldProvisionTablesAndIndexes() {
diff --git 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
index 2805c62930..c7d98cb915 100644
--- 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
+++ 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
@@ -39,7 +39,7 @@ import reactor.core.publisher.Mono;
 class PostgresTableManagerTest {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     Function<PostgresModule, PostgresTableManager> tableManagerFactory =
         module -> new PostgresTableManager(new 
PostgresExecutor(postgresExtension.getConnection()), module, true);
diff --git 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
index 962599473f..cfe457db34 100644
--- 
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
+++ 
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
@@ -46,7 +46,7 @@ import reactor.core.publisher.Mono;
 
 public class SimpleJamesPostgresConnectionFactoryTest extends 
JamesPostgresConnectionFactoryTest {
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     private PostgresqlConnection postgresqlConnection;
     private SimpleJamesPostgresConnectionFactory 
jamesPostgresConnectionFactory;
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
index b6f2db2243..53871f68f8 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
@@ -43,7 +43,7 @@ class JPAMailboxManagerTest extends 
MailboxManagerTest<OpenJPAMailboxManager> {
     }
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
index 8f2b2b8e52..2abd96da33 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 class JpaMailboxManagerStressTest implements 
MailboxManagerStressContract<OpenJPAMailboxManager> {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
index 83b9074aa9..39343b7b1a 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
@@ -42,7 +42,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 class PostgresSubscriptionManagerTest implements SubscriptionManagerContract {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
 
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
index 41032b719e..10a76bae46 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
@@ -58,7 +58,7 @@ import com.google.common.collect.ImmutableSet;
 class JPARecomputeCurrentQuotasServiceTest implements 
RecomputeCurrentQuotasServiceContract {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final DomainList NO_DOMAIN_LIST = null;
 
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
index 7f6618933c..9505cd473e 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
@@ -40,7 +40,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class PostgresSubscriptionMapperRowLevelSecurityTest {
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE, true);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     private SubscriptionMapperFactory subscriptionMapperFactory;
 
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
index ac693c9c99..5d05795398 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 public class PostgresSubscriptionMapperTest extends SubscriptionMapperTest {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new 
PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     @Override
     protected SubscriptionMapper createSubscriptionMapper() {
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 f73e46c337..16568dc900 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
@@ -51,7 +51,7 @@ class JamesCapabilitiesServerTest {
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModule())
             .overrideWith(binder -> 
binder.bind(MailboxManager.class).toInstance(mailboxManager())))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .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 a17e8560f7..52654ba7b6 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
@@ -50,7 +50,7 @@ class PostgresJamesServerTest implements 
JamesServerConcreteContract {
             .build())
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModule()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .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 2f005078e0..55fd090c49 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
@@ -35,7 +35,7 @@ class 
PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest extends Post
             .build())
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new 
TestJPAConfigurationModuleWithSqlValidation.WithDatabaseAuthentication()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .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 19fb866d24..44f9620748 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
@@ -34,7 +34,7 @@ class 
PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest exten
             .build())
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new 
TestJPAConfigurationModuleWithSqlValidation.NoDatabaseAuthentication()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .build();
 }
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 66e4b6fb88..6bc0e02a95 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
@@ -45,7 +45,7 @@ class PostgresWithLDAPJamesServerTest {
             .overrideWith(new TestJPAConfigurationModule()))
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .extension(new LdapTestExtension())
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .build();
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to