You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2019/02/15 13:30:41 UTC
[james-project] 06/07: JAMES-2651 JPAEntityManagerModule supports
username password
This is an automated email from the ASF dual-hosted git repository.
rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3a4fe51d0a716e004974790c8a5ae59de958b49c
Author: tran tien duc <dt...@linagora.com>
AuthorDate: Fri Jan 25 15:32:32 2019 +0700
JAMES-2651 JPAEntityManagerModule supports username password
---
server/container/guice/jpa-common-guice/pom.xml | 10 ++
.../james/modules/data/JPAConfiguration.java | 142 ++++++++++++++----
.../james/modules/data/JPAEntityManagerModule.java | 21 ++-
...estJPAConfigurationModuleWithSqlValidation.java | 80 ++++++++--
.../james/modules/data/JPAConfigurationTest.java | 163 +++++++++++++++++++++
...ithAuthenticatedDatabaseSqlValidationTest.java} | 10 +-
...tabaseAuthenticaticationSqlValidationTest.java} | 10 +-
.../james/JPAJamesServerWithSqlValidationTest.java | 10 +-
8 files changed, 370 insertions(+), 76 deletions(-)
diff --git a/server/container/guice/jpa-common-guice/pom.xml b/server/container/guice/jpa-common-guice/pom.xml
index ab82416..5372b1e 100644
--- a/server/container/guice/jpa-common-guice/pom.xml
+++ b/server/container/guice/jpa-common-guice/pom.xml
@@ -51,6 +51,16 @@
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAConfiguration.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAConfiguration.java
index 89e07fd..46f7309 100644
--- a/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAConfiguration.java
+++ b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAConfiguration.java
@@ -18,67 +18,142 @@
****************************************************************/
package org.apache.james.modules.data;
-import org.apache.james.backends.jpa.JPAConstants;
+import static org.apache.james.modules.data.JPAConfiguration.Credential.NO_CREDENTIAL;
+import static org.apache.james.modules.data.JPAConfiguration.ReadyToBuild.NO_TEST_ON_BORROW;
+import static org.apache.james.modules.data.JPAConfiguration.ReadyToBuild.NO_VALIDATION_QUERY;
+import static org.apache.james.modules.data.JPAConfiguration.ReadyToBuild.NO_VALIDATION_QUERY_TIMEOUT_SEC;
+
+import java.util.Optional;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
public class JPAConfiguration {
- public static Builder builder() {
- return new Builder();
+ public static class Credential {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Credential.class);
+ static final Optional<Credential> NO_CREDENTIAL = Optional.empty();
+
+ public static Optional<Credential> of(String username, String password) {
+ if (StringUtils.isBlank(username) && StringUtils.isBlank(password)) {
+ LOGGER.debug("username and password are blank, returns no credential by default");
+ return NO_CREDENTIAL;
+ }
+
+ return Optional.of(new Credential(username, password));
+ }
+
+ private final String username;
+ private final String password;
+
+ private Credential(String username, String password) {
+ Preconditions.checkArgument(StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password),
+ "username and password for connecting to database can't be blank");
+ this.username = username;
+ this.password = password;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
}
- public static class Builder {
- private String driverName;
- private String driverURL;
- private boolean testOnBorrow;
- private int validationQueryTimeoutSec = JPAConstants.VALIDATION_NO_TIMEOUT;
- private String validationQuery;
+ @FunctionalInterface
+ public interface RequireDriverName {
+ RequireDriverURL driverName(String driverName);
+ }
+
+ @FunctionalInterface
+ public interface RequireDriverURL {
+ ReadyToBuild driverURL(String driverUrl);
+ }
+ public static class ReadyToBuild {
+ static final Optional<Boolean> NO_TEST_ON_BORROW = Optional.empty();
+ static final Optional<Integer> NO_VALIDATION_QUERY_TIMEOUT_SEC = Optional.empty();
+ static final Optional<String> NO_VALIDATION_QUERY = Optional.empty();
- public Builder driverName(String driverName) {
+ private final String driverName;
+ private final String driverURL;
+
+ private Optional<Credential> credential;
+ private Optional<Boolean> testOnBorrow;
+ private Optional<Integer> validationQueryTimeoutSec;
+ private Optional<String> validationQuery;
+
+
+ private ReadyToBuild(String driverName, String driverURL, Optional<Credential> credential,
+ Optional<Boolean> testOnBorrow, Optional<Integer> validationQueryTimeoutSec,
+ Optional<String> validationQuery) {
this.driverName = driverName;
- return this;
+ this.driverURL = driverURL;
+ this.credential = credential;
+ this.testOnBorrow = testOnBorrow;
+ this.validationQueryTimeoutSec = validationQueryTimeoutSec;
+ this.validationQuery = validationQuery;
}
- public Builder driverURL(String driverURL) {
- this.driverURL = driverURL;
- return this;
+ public JPAConfiguration build() {
+ return new JPAConfiguration(driverName, driverURL, credential, testOnBorrow, validationQueryTimeoutSec, validationQuery);
}
- public Builder testOnBorrow(boolean testOnBorrow) {
- this.testOnBorrow = testOnBorrow;
- return this;
+ public RequirePassword username(String username) {
+ return password -> new ReadyToBuild(driverName, driverURL, Credential.of(username, password),
+ testOnBorrow, validationQueryTimeoutSec, validationQuery);
}
- public Builder validationQueryTimeoutSec(int validationQueryTimeoutSec) {
- this.validationQueryTimeoutSec = validationQueryTimeoutSec;
+ public ReadyToBuild testOnBorrow(Boolean testOnBorrow) {
+ this.testOnBorrow = Optional.ofNullable(testOnBorrow);
return this;
}
- public Builder validationQuery(String validationQuery) {
- this.validationQuery = validationQuery;
+ public ReadyToBuild validationQueryTimeoutSec(Integer validationQueryTimeoutSec) {
+ this.validationQueryTimeoutSec = Optional.ofNullable(validationQueryTimeoutSec);
return this;
}
- public JPAConfiguration build() {
- Preconditions.checkNotNull(driverName);
- Preconditions.checkNotNull(driverURL);
- return new JPAConfiguration(driverName, driverURL, testOnBorrow, validationQueryTimeoutSec, validationQuery);
+ public ReadyToBuild validationQuery(String validationQuery) {
+ this.validationQuery = Optional.ofNullable(validationQuery);
+ return this;
}
}
+ @FunctionalInterface
+ public interface RequirePassword {
+ ReadyToBuild password(String password);
+ }
+
+ public static RequireDriverName builder() {
+ return driverName -> driverURL -> new ReadyToBuild(driverName, driverURL, NO_CREDENTIAL, NO_TEST_ON_BORROW,
+ NO_VALIDATION_QUERY_TIMEOUT_SEC, NO_VALIDATION_QUERY);
+ }
+
private final String driverName;
private final String driverURL;
- private final boolean testOnBorrow;
- private final int validationQueryTimeoutSec;
- private final String validationQuery;
+ private final Optional<Boolean> testOnBorrow;
+ private final Optional<Integer> validationQueryTimeoutSec;
+ private final Optional<Credential> credential;
+ private final Optional<String> validationQuery;
@VisibleForTesting
- JPAConfiguration(String driverName, String driverURL, boolean testOnBorrow, int validationQueryTimeoutSec, String validationQuery) {
+ JPAConfiguration(String driverName, String driverURL, Optional<Credential> credential, Optional<Boolean> testOnBorrow,
+ Optional<Integer> validationQueryTimeoutSec, Optional<String> validationQuery) {
+ Preconditions.checkNotNull(driverName, "driverName cannot be null");
+ Preconditions.checkNotNull(driverURL, "driverURL cannot be null");
+ validationQueryTimeoutSec.ifPresent(timeoutInSec ->
+ Preconditions.checkArgument(timeoutInSec > 0, "validationQueryTimeoutSec is required to be greater than 0"));
+
this.driverName = driverName;
this.driverURL = driverURL;
+ this.credential = credential;
this.testOnBorrow = testOnBorrow;
this.validationQueryTimeoutSec = validationQueryTimeoutSec;
this.validationQuery = validationQuery;
@@ -92,16 +167,19 @@ public class JPAConfiguration {
return driverURL;
}
- public boolean isTestOnBorrow() {
+ public Optional<Boolean> isTestOnBorrow() {
return testOnBorrow;
}
- public int getValidationQueryTimeoutSec() {
+ public Optional<Integer> getValidationQueryTimeoutSec() {
return validationQueryTimeoutSec;
}
- public String getValidationQuery() {
+ public Optional<String> getValidationQuery() {
return validationQuery;
}
+ public Optional<Credential> getCredential() {
+ return credential;
+ }
}
diff --git a/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAEntityManagerModule.java b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAEntityManagerModule.java
index c9fb943..eda24ef 100644
--- a/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAEntityManagerModule.java
+++ b/server/container/guice/jpa-common-guice/src/main/java/org/apache/james/modules/data/JPAEntityManagerModule.java
@@ -29,7 +29,6 @@ import javax.persistence.Persistence;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.backends.jpa.JPAConstants;
import org.apache.james.utils.PropertiesProvider;
import com.google.common.base.Joiner;
@@ -49,15 +48,19 @@ public class JPAEntityManagerModule extends AbstractModule {
properties.put("openjpa.ConnectionDriverName", jpaConfiguration.getDriverName());
properties.put("openjpa.ConnectionURL", jpaConfiguration.getDriverURL());
+ jpaConfiguration.getCredential()
+ .ifPresent(credential -> {
+ properties.put("openjpa.ConnectionUserName", credential.getUsername());
+ properties.put("openjpa.ConnectionPassword", credential.getPassword());
+ });
List<String> connectionFactoryProperties = new ArrayList<>();
connectionFactoryProperties.add("TestOnBorrow=" + jpaConfiguration.isTestOnBorrow());
- if (jpaConfiguration.getValidationQueryTimeoutSec() > 0) {
- connectionFactoryProperties.add("ValidationTimeout=" + jpaConfiguration.getValidationQueryTimeoutSec() * 1000);
- }
- if (jpaConfiguration.getValidationQuery() != null) {
- connectionFactoryProperties.add("ValidationSQL='" + jpaConfiguration.getValidationQuery() + "'");
- }
+ jpaConfiguration.getValidationQueryTimeoutSec()
+ .ifPresent(timeoutSecond -> connectionFactoryProperties.add("ValidationTimeout=" + timeoutSecond * 1000));
+ jpaConfiguration.getValidationQuery()
+ .ifPresent(validationQuery -> connectionFactoryProperties.add("ValidationSQL='" + validationQuery + "'"));
+
properties.put("openjpa.ConnectionFactoryProperties", Joiner.on(", ").join(connectionFactoryProperties));
return Persistence.createEntityManagerFactory("Global", properties);
@@ -71,8 +74,10 @@ public class JPAEntityManagerModule extends AbstractModule {
.driverName(dataSource.getString("database.driverClassName"))
.driverURL(dataSource.getString("database.url"))
.testOnBorrow(dataSource.getBoolean("datasource.testOnBorrow", false))
- .validationQueryTimeoutSec(dataSource.getInt("datasource.validationQueryTimeoutSec", JPAConstants.VALIDATION_NO_TIMEOUT))
+ .validationQueryTimeoutSec(dataSource.getInteger("datasource.validationQueryTimeoutSec", null))
.validationQuery(dataSource.getString("datasource.validationQuery", null))
+ .username(dataSource.getString("database.username"))
+ .password(dataSource.getString("database.password"))
.build();
}
}
diff --git a/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java b/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
index 4fdb623..9013fef 100644
--- a/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
+++ b/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/TestJPAConfigurationModuleWithSqlValidation.java
@@ -19,6 +19,11 @@
package org.apache.james;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
import javax.inject.Singleton;
import org.apache.james.modules.data.JPAConfiguration;
@@ -26,25 +31,78 @@ import org.apache.james.modules.data.JPAConfiguration;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
-public class TestJPAConfigurationModuleWithSqlValidation extends AbstractModule {
+public interface TestJPAConfigurationModuleWithSqlValidation {
+
+ class NoDatabaseAuthentication extends AbstractModule {
+ @Override
+ protected void configure() {
+ }
+
+ @Provides
+ @Singleton
+ JPAConfiguration provideConfiguration() {
+ return jpaConfigurationBuilder().build();
+ }
+ }
+
+ class WithDatabaseAuthentication extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ setupAuthenticationOnDerby();
+ }
- 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 static final String VALIDATION_SQL_QUERY = "VALUES 1";
+ @Provides
+ @Singleton
+ JPAConfiguration provideConfiguration() {
+ return jpaConfigurationBuilder()
+ .username(DATABASE_USERNAME)
+ .password(DATABASE_PASSWORD)
+ .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");
- @Override
- protected void configure() {
+ // 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);
+ }
+ }
}
- @Provides
- @Singleton
- JPAConfiguration provideConfiguration() {
+ 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)
- .build();
+ .validationQuery(VALIDATION_SQL_QUERY);
}
}
diff --git a/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/modules/data/JPAConfigurationTest.java b/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/modules/data/JPAConfigurationTest.java
new file mode 100644
index 0000000..967d252
--- /dev/null
+++ b/server/container/guice/jpa-common-guice/src/test/java/org/apache/james/modules/data/JPAConfigurationTest.java
@@ -0,0 +1,163 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.modules.data;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+
+class JPAConfigurationTest {
+
+ private static final String DRIVER_NAME = "driverName";
+ private static final String DRIVER_URL = "driverUrl";
+ private static final boolean TEST_ON_BORROW = true;
+ private static final String VALIDATION_QUERY = "validationQuery";
+ private static final int VALIDATION_TIMEOUT_SEC = 1;
+ private static final String USER_NAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String EMPTY_STRING = "";
+
+ @Test
+ void buildShouldReturnCorrespondingProperties() {
+ JPAConfiguration configuration = JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .testOnBorrow(TEST_ON_BORROW)
+ .validationQuery(VALIDATION_QUERY)
+ .validationQueryTimeoutSec(VALIDATION_TIMEOUT_SEC)
+ .username(USER_NAME)
+ .password(PASSWORD)
+ .build();
+
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(configuration.getDriverName()).isEqualTo(DRIVER_NAME);
+ softly.assertThat(configuration.getDriverURL()).isEqualTo(DRIVER_URL);
+ softly.assertThat(configuration.isTestOnBorrow()).contains(TEST_ON_BORROW);
+ softly.assertThat(configuration.getValidationQuery()).contains(VALIDATION_QUERY);
+ softly.assertThat(configuration.getValidationQueryTimeoutSec()).contains(VALIDATION_TIMEOUT_SEC);
+ softly.assertThat(configuration.getCredential()).hasValueSatisfying(credential -> {
+ softly.assertThat(credential.getPassword()).isEqualTo(PASSWORD);
+ softly.assertThat(credential.getUsername()).isEqualTo(USER_NAME);
+ });
+ });
+ }
+
+ @Test
+ void buildShouldReturnEmptyOptionalPropertiesWhenNotSpecified() {
+ JPAConfiguration configuration = JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .build();
+
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(configuration.getDriverName()).isEqualTo(DRIVER_NAME);
+ softly.assertThat(configuration.getDriverURL()).isEqualTo(DRIVER_URL);
+
+ softly.assertThat(configuration.isTestOnBorrow()).isEmpty();
+ softly.assertThat(configuration.getValidationQuery()).isEmpty();
+ softly.assertThat(configuration.getValidationQueryTimeoutSec()).isEmpty();
+ softly.assertThat(configuration.getCredential()).isEmpty();
+ });
+ }
+
+ @Test
+ void buildShouldThrowWhenValidationQueryTimeoutSecIsZero() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .validationQueryTimeoutSec(0)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("validationQueryTimeoutSec is required to be greater than 0");
+ }
+
+ @Test
+ void buildShouldThrowWhenValidationQueryTimeoutSecIsNegative() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .validationQueryTimeoutSec(-1)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("validationQueryTimeoutSec is required to be greater than 0");
+ }
+
+ @Test
+ void buildShouldThrowWhenPasswordIsNull() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .username(USER_NAME)
+ .password(null)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("username and password for connecting to database can't be blank");
+ }
+
+ @Test
+ void buildShouldThrowWhenPasswordIsEmpty() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .username(USER_NAME)
+ .password(EMPTY_STRING)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("username and password for connecting to database can't be blank");
+ }
+
+ @Test
+ void buildShouldThrowWhenUsernameIsNull() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .username(null)
+ .password(PASSWORD)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("username and password for connecting to database can't be blank");
+ }
+
+ @Test
+ void buildShouldThrowWhenUsernameIsEmpty() {
+ assertThatThrownBy(() -> JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .username(EMPTY_STRING)
+ .password(PASSWORD)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("username and password for connecting to database can't be blank");
+ }
+
+ @Test
+ void buildShouldReturnEmptyOptionalCredentialWhenPassingNullValues() {
+ JPAConfiguration configuration = JPAConfiguration.builder()
+ .driverName(DRIVER_NAME)
+ .driverURL(DRIVER_URL)
+ .username(null)
+ .password(null)
+ .build();
+
+ assertThat(configuration.getCredential()).isEmpty();
+ }
+}
\ No newline at end of file
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
similarity index 82%
copy from server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
copy to server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
index 85132d5..863d22d 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
@@ -19,20 +19,14 @@
package org.apache.james;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.RegisterExtension;
-class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
+class JPAJamesServerWithAuthenticatedDatabaseSqlValidationTest extends JPAJamesServerWithSqlValidationTest {
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
.server(configuration -> GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_MODULE_AGGREGATE)
- .overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE))
+ .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.WithDatabaseAuthentication(), DOMAIN_LIST_CONFIGURATION_MODULE))
.build();
-
- @Override
- @Disabled("Failing to create the domain: duplicate with test in JPAJamesServerTest")
- void jpaGuiceServerShouldUpdateQuota(GuiceJamesServer jamesServer) {
- }
}
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
similarity index 82%
copy from server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
copy to server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
index 85132d5..4f1b4c1 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
@@ -19,20 +19,14 @@
package org.apache.james;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.RegisterExtension;
-class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
+class JPAJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest extends JPAJamesServerWithSqlValidationTest {
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
.server(configuration -> GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_MODULE_AGGREGATE)
- .overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE))
+ .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.NoDatabaseAuthentication(), DOMAIN_LIST_CONFIGURATION_MODULE))
.build();
-
- @Override
- @Disabled("Failing to create the domain: duplicate with test in JPAJamesServerTest")
- void jpaGuiceServerShouldUpdateQuota(GuiceJamesServer jamesServer) {
- }
}
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
index 85132d5..4a0e1f5 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
@@ -20,16 +20,8 @@
package org.apache.james;
import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.extension.RegisterExtension;
-class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
-
- @RegisterExtension
- static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder()
- .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
- .combineWith(JPAJamesServerMain.JPA_MODULE_AGGREGATE)
- .overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE))
- .build();
+abstract class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
@Override
@Disabled("Failing to create the domain: duplicate with test in JPAJamesServerTest")
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org