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

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

commit 4eed0dfa827e6c3752482a423ab33bc39cd92a88
Author: duc <dt...@linagora.com>
AuthorDate: Wed Jan 8 22:32:57 2020 +0700

    [Refactoring] Migrate to Junit 5 JwtFilterIntegrationTest
---
 .../rabbitmq/RabbitMQJwtFilterIntegrationTest.java | 40 ++++++++++++++--------
 .../memory/MemoryJwtFilterIntegrationTest.java     | 28 ++++++++-------
 .../integration/JwtFilterIntegrationTest.java      | 35 +++++++------------
 3 files changed, 54 insertions(+), 49 deletions(-)

diff --git 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQJwtFilterIntegrationTest.java
 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQJwtFilterIntegrationTest.java
index 77a1e38..8a4f7b0 100644
--- 
a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQJwtFilterIntegrationTest.java
+++ 
b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQJwtFilterIntegrationTest.java
@@ -19,27 +19,37 @@
 
 package org.apache.james.webadmin.integration.rabbitmq;
 
-import org.apache.james.CassandraRabbitMQAwsS3JmapTestRule;
-import org.apache.james.DockerCassandraRule;
+import org.apache.james.CassandraExtension;
+import org.apache.james.CassandraRabbitMQJamesServerMain;
+import org.apache.james.DockerElasticSearchExtension;
 import org.apache.james.GuiceJamesServer;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
 import org.apache.james.jwt.JwtConfiguration;
+import org.apache.james.modules.AwsS3BlobStoreExtension;
+import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.authentication.AuthenticationFilter;
 import org.apache.james.webadmin.authentication.JwtFilter;
 import org.apache.james.webadmin.integration.JwtFilterIntegrationTest;
-import org.junit.Rule;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class RabbitMQJwtFilterIntegrationTest extends JwtFilterIntegrationTest 
{
+class RabbitMQJwtFilterIntegrationTest extends JwtFilterIntegrationTest {
 
-    @Rule
-    public DockerCassandraRule cassandra = new DockerCassandraRule();
-    
-    @Rule
-    public CassandraRabbitMQAwsS3JmapTestRule jamesTestRule = 
CassandraRabbitMQAwsS3JmapTestRule.defaultTestRule();
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-    @Override
-    protected GuiceJamesServer createJamesServer(JwtConfiguration 
jwtConfiguration) throws Exception {
-        return jamesTestRule.jmapServer(cassandra.getModule())
-            .overrideWith(binder -> 
binder.bind(AuthenticationFilter.class).to(JwtFilter.class),
-                binder -> 
binder.bind(JwtConfiguration.class).toInstance(jwtConfiguration));
-    }
+    @RegisterExtension
+    static JamesServerExtension testExtension = new JamesServerBuilder()
+        .extension(new DockerElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .extension(new AwsS3BlobStoreExtension())
+        .extension(new RabbitMQExtension())
+        .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(CassandraRabbitMQJamesServerMain.MODULES)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> 
binder.bind(AuthenticationFilter.class).to(JwtFilter.class))
+            .overrideWith(binder -> 
binder.bind(JwtConfiguration.class).toInstance(jwtConfiguration()))
+            .overrideWith(binder -> 
binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+        .build();
 }
diff --git 
a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryJwtFilterIntegrationTest.java
 
b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryJwtFilterIntegrationTest.java
index 44dbbe9..d2c4c00 100644
--- 
a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryJwtFilterIntegrationTest.java
+++ 
b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryJwtFilterIntegrationTest.java
@@ -20,24 +20,28 @@
 package org.apache.james.webadmin.integration.memory;
 
 import org.apache.james.GuiceJamesServer;
-import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.MemoryJamesServerMain;
 import org.apache.james.jwt.JwtConfiguration;
+import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.authentication.AuthenticationFilter;
 import org.apache.james.webadmin.authentication.JwtFilter;
 import org.apache.james.webadmin.integration.JwtFilterIntegrationTest;
-import org.junit.Rule;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class MemoryJwtFilterIntegrationTest extends JwtFilterIntegrationTest {
+class MemoryJwtFilterIntegrationTest extends JwtFilterIntegrationTest {
 
-    @Rule
-    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    private static final int LIMIT_TO_10_MESSAGES = 10;
 
-    @Override
-    protected GuiceJamesServer createJamesServer(JwtConfiguration 
jwtConfiguration) throws Exception {
-        return memoryJmap.jmapServer(
-            binder -> 
binder.bind(AuthenticationFilter.class).to(JwtFilter.class),
-            binder -> 
binder.bind(JwtConfiguration.class).toInstance(jwtConfiguration),
-            binder -> 
binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
-    }
+    @RegisterExtension
+    static JamesServerExtension jamesServerExtension = new JamesServerBuilder()
+        .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
+            
.combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> 
binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION))
+            .overrideWith(binder -> 
binder.bind(AuthenticationFilter.class).to(JwtFilter.class))
+            .overrideWith(binder -> 
binder.bind(JwtConfiguration.class).toInstance(jwtConfiguration())))
+        .build();
 }
diff --git 
a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
 
b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
index 5b1d1d1..6d47d28 100644
--- 
a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
+++ 
b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/JwtFilterIntegrationTest.java
@@ -34,15 +34,19 @@ import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.routes.DomainsRoutes;
 import org.eclipse.jetty.http.HttpStatus;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import io.restassured.RestAssured;
 
 public abstract class JwtFilterIntegrationTest {
 
+    protected static JwtConfiguration jwtConfiguration() {
+        return new JwtConfiguration(
+            
Optional.of(ClassLoaderUtils.getSystemResourceAsString("jwt_publickey")));
+    }
+
     private static final String DOMAIN = "domain";
     private static final String SPECIFIC_DOMAIN = DomainsRoutes.DOMAINS + 
SEPARATOR + DOMAIN;
     private static final String VALID_TOKEN_ADMIN_TRUE = 
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbkBvcGVuL" +
@@ -56,33 +60,20 @@ public abstract class JwtFilterIntegrationTest {
         
"xtedOK2JnQZn7t9sUzSrcyjWverm7gZkPptkIVoS8TsEeMMME5vFXe_nqkEG69q3kuBUm_33tbR5oNS0ZGZKlG9r41lHBjyf9J1xN4UYV8n866d"
 +
         "a7RPPCzshIWUtO0q9T2umWTnp-6OnOdBCkndrZmRR6pPxsD5YL0_77Wq8KT_5__fGA";
 
-    private GuiceJamesServer guiceJamesServer;
     private DataProbeImpl dataProbe;
-    private WebAdminGuiceProbe webAdminGuiceProbe;
 
-    @Before
-    public void setUp() throws Exception {
-        JwtConfiguration jwtConfiguration = new JwtConfiguration(
-            
Optional.of(ClassLoaderUtils.getSystemResourceAsString("jwt_publickey")));
-
-        guiceJamesServer = createJamesServer(jwtConfiguration);
-        guiceJamesServer.start();
+    @BeforeEach
+    void setUp(GuiceJamesServer guiceJamesServer) {
         dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
-        webAdminGuiceProbe = 
guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
+        WebAdminGuiceProbe webAdminGuiceProbe = 
guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
 
         RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminGuiceProbe.getWebAdminPort()).build();
     }
 
-    @After
-    public void tearDown() {
-        guiceJamesServer.stop();
-    }
-
-    protected abstract GuiceJamesServer createJamesServer(JwtConfiguration 
jwtConfiguration) throws Exception;
 
     @Category(BasicFeature.class)
     @Test
-    public void jwtAuthenticationShouldWork() throws Exception {
+    void jwtAuthenticationShouldWork() throws Exception {
         given()
             .header("Authorization", "Bearer " + VALID_TOKEN_ADMIN_TRUE)
         .when()
@@ -95,7 +86,7 @@ public abstract class JwtFilterIntegrationTest {
     }
 
     @Test
-    public void jwtShouldRejectNonAdminRequests() throws Exception {
+    void jwtShouldRejectNonAdminRequests() throws Exception {
         given()
             .header("Authorization", "Bearer " + VALID_TOKEN_ADMIN_FALSE)
         .when()
@@ -108,7 +99,7 @@ public abstract class JwtFilterIntegrationTest {
     }
 
     @Test
-    public void jwtShouldRejectInvalidRequests() throws Exception {
+    void jwtShouldRejectInvalidRequests() throws Exception {
         given()
             .header("Authorization", "Bearer invalid")
         .when()


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to