This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0f97a259f605e339b669bf5a49072dbdd20f6a63
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Oct 4 10:30:02 2019 +0700

    JAMES-2904 Clear some unecessary cassandra components in tests
---
 .../init/configuration/ClusterConfiguration.java   | 10 ++--
 .../james/backends/cassandra/DockerCassandra.java  |  2 +-
 .../DockerCassandraAuthenticatedSingleton.java     | 30 ------------
 .../AuthenticatedCassandraJamesServerTest.java     | 14 +++---
 .../james/CassandraAuthenticationExtension.java    | 45 +++++++++++++++---
 .../james/CassandraBadAuthenticationExtension.java | 54 ----------------------
 6 files changed, 52 insertions(+), 103 deletions(-)

diff --git 
a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
 
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
index 82c4afb..d310627 100644
--- 
a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
+++ 
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
@@ -163,11 +163,15 @@ public class ClusterConfiguration {
             return password(Optional.of(password));
         }
 
-        public Builder useSsl(boolean useSsl) {
-            this.useSsl = Optional.of(useSsl);
+        public Builder useSsl(Optional<Boolean> useSsl) {
+            this.useSsl = useSsl;
             return this;
         }
 
+        public Builder useSsl(boolean useSsl) {
+            return useSsl(Optional.of(useSsl));
+        }
+
         public Builder useSsl() {
             return useSsl(true);
         }
@@ -236,7 +240,7 @@ public class ClusterConfiguration {
             .poolingOptions(readPoolingOptions(configuration))
             
.readTimeoutMillis(Optional.ofNullable(configuration.getInteger(READ_TIMEOUT_MILLIS,
 null)))
             
.connectTimeoutMillis(Optional.ofNullable(configuration.getInteger(CONNECT_TIMEOUT_MILLIS,
 null)))
-            .useSsl(configuration.getBoolean(CASSANDRA_SSL, false))
+            
.useSsl(Optional.ofNullable(configuration.getBoolean(CASSANDRA_SSL, null)))
             
.username(Optional.ofNullable(configuration.getString(CASSANDRA_USER, null)))
             
.password(Optional.ofNullable(configuration.getString(CASSANDRA_PASSWORD, 
null)))
             .build();
diff --git 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
index 99dce87..7adf502 100644
--- 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
+++ 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
@@ -36,7 +36,7 @@ public class DockerCassandra {
     private static final Logger logger = 
LoggerFactory.getLogger(DockerCassandra.class);
 
     @FunctionalInterface
-    interface AdditionalDockerFileStep {
+    public interface AdditionalDockerFileStep {
         AdditionalDockerFileStep IDENTITY = builder -> builder;
 
         DockerfileBuilder applyStep(DockerfileBuilder builder);
diff --git 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandraAuthenticatedSingleton.java
 
b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandraAuthenticatedSingleton.java
deleted file mode 100644
index e16f639..0000000
--- 
a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandraAuthenticatedSingleton.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/****************************************************************
- * 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.backends.cassandra;
-
-public class DockerCassandraAuthenticatedSingleton {
-    public static final DockerCassandra singleton = new 
DockerCassandra("cassandra_3_11_3_auth",
-        dockerfileBuilder -> dockerfileBuilder
-            .run("echo 'authenticator: PasswordAuthenticator' >> 
/etc/cassandra/cassandra.yaml"));
-
-    static {
-        singleton.start();
-    }
-}
diff --git 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
index 130f4c9..48a450c 100644
--- 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
+++ 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
@@ -21,11 +21,8 @@ package org.apache.james;
 
 import static 
org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 import static 
org.apache.james.JamesServerContract.DOMAIN_LIST_CONFIGURATION_MODULE;
-import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.commons.lang3.NotImplementedException;
-import 
org.apache.james.backends.cassandra.DockerCassandraAuthenticatedSingleton;
 import 
org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
@@ -34,7 +31,6 @@ import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
-import com.datastax.driver.core.exceptions.AuthenticationException;
 import com.google.inject.CreationException;
 
 class AuthenticatedCassandraJamesServerTest {
@@ -45,7 +41,7 @@ class AuthenticatedCassandraJamesServerTest {
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
             .extension(new DockerElasticSearchExtension())
-            .extension(new CassandraAuthenticationExtension())
+            .extension(CassandraAuthenticationExtension.withValidCredentials())
             .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
                 .overrideWith(binder -> 
binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
@@ -56,10 +52,12 @@ class AuthenticatedCassandraJamesServerTest {
 
     @Nested
     class SslTest {
+        private final CassandraExtension cassandraExtension = new 
CassandraExtension();
+
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
             .extension(new DockerElasticSearchExtension())
-            .extension(new CassandraExtension())
+            .extension(cassandraExtension)
             .disableAutoStart()
             .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
@@ -68,7 +66,7 @@ class AuthenticatedCassandraJamesServerTest {
                 .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE))
             .overrideServerModule(binder -> 
binder.bind(ClusterConfiguration.class)
                 .toInstance(ClusterConfiguration.builder()
-                    
.host(DockerCassandraAuthenticatedSingleton.singleton.getHost())
+                    .host(cassandraExtension.getCassandra().getHost())
                     .keyspace("testing")
                     .replicationFactor(1)
                     .maxRetry(1)
@@ -90,7 +88,7 @@ class AuthenticatedCassandraJamesServerTest {
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
             .extension(new DockerElasticSearchExtension())
-            .extension(new CassandraBadAuthenticationExtension())
+            
.extension(CassandraAuthenticationExtension.withInvalidCredentials())
             .disableAutoStart()
             .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
index 7528d6c..e0578be 100644
--- 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
+++ 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
@@ -19,7 +19,7 @@
 
 package org.apache.james;
 
-import 
org.apache.james.backends.cassandra.DockerCassandraAuthenticatedSingleton;
+import org.apache.james.backends.cassandra.DockerCassandra;
 import 
org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
 import org.apache.james.server.CassandraTruncateTableTask;
 import org.junit.jupiter.api.extension.ExtensionContext;
@@ -29,23 +29,54 @@ import com.google.inject.multibindings.Multibinder;
 import com.google.inject.util.Modules;
 
 public class CassandraAuthenticationExtension implements 
GuiceModuleTestExtension {
+    private static final String VALID_PASSWORD = "cassandra";
+    private static final String INVALID_PASSWORD = "bad";
+    private static final DockerCassandra authenticatedCassandra = new 
DockerCassandra("cassandra_3_11_3_auth",
+        dockerfileBuilder -> dockerfileBuilder
+            .run("echo 'authenticator: PasswordAuthenticator' >> 
/etc/cassandra/cassandra.yaml"));
+
+    static {
+        authenticatedCassandra.start();
+    }
+
+    public static CassandraAuthenticationExtension withValidCredentials() {
+        return new 
CassandraAuthenticationExtension(ClusterConfiguration.builder()
+            .password(VALID_PASSWORD)
+            .maxRetry(20)
+            .minDelay(5000));
+    }
+
+    public static CassandraAuthenticationExtension withInvalidCredentials() {
+        return new 
CassandraAuthenticationExtension(ClusterConfiguration.builder()
+            .password(INVALID_PASSWORD)
+            .maxRetry(1)
+            .minDelay(100));
+    }
+
+    private final ClusterConfiguration.Builder configurationBuilder;
+
+    private CassandraAuthenticationExtension(ClusterConfiguration.Builder 
configurationBuilder) {
+        this.configurationBuilder = configurationBuilder;
+    }
 
     @Override
     public void beforeAll(ExtensionContext extensionContext) {
-        DockerCassandraAuthenticatedSingleton.singleton.start();
+        authenticatedCassandra.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        authenticatedCassandra.stop();
     }
 
     @Override
     public Module getModule() {
         return Modules.combine((binder) -> 
binder.bind(ClusterConfiguration.class)
-                .toInstance(ClusterConfiguration.builder()
-                    
.host(DockerCassandraAuthenticatedSingleton.singleton.getHost())
+                .toInstance(configurationBuilder
+                    .host(authenticatedCassandra.getHost())
                     .keyspace("testing")
                     .username("cassandra")
-                    .password("cassandra")
                     .replicationFactor(1)
-                    .maxRetry(20)
-                    .minDelay(5000)
                     .build()),
             binder -> Multibinder.newSetBinder(binder, 
CleanupTasksPerformer.CleanupTask.class)
                 .addBinding()
diff --git 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraBadAuthenticationExtension.java
 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraBadAuthenticationExtension.java
deleted file mode 100644
index a001393..0000000
--- 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraBadAuthenticationExtension.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************
- * 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;
-
-import 
org.apache.james.backends.cassandra.DockerCassandraAuthenticatedSingleton;
-import 
org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
-import org.apache.james.server.CassandraTruncateTableTask;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-import com.google.inject.Module;
-import com.google.inject.multibindings.Multibinder;
-import com.google.inject.util.Modules;
-
-public class CassandraBadAuthenticationExtension implements 
GuiceModuleTestExtension {
-
-    @Override
-    public void beforeAll(ExtensionContext extensionContext) {
-        DockerCassandraAuthenticatedSingleton.singleton.start();
-    }
-
-    @Override
-    public Module getModule() {
-        return Modules.combine((binder) -> 
binder.bind(ClusterConfiguration.class)
-                .toInstance(ClusterConfiguration.builder()
-                    
.host(DockerCassandraAuthenticatedSingleton.singleton.getHost())
-                    .keyspace("testing")
-                    .username("cassandra")
-                    .password("bad")
-                    .replicationFactor(1)
-                    .maxRetry(1)
-                    .minDelay(100)
-                    .build()),
-            binder -> Multibinder.newSetBinder(binder, 
CleanupTasksPerformer.CleanupTask.class)
-                .addBinding()
-                .to(CassandraTruncateTableTask.class));
-    }
-}


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

Reply via email to