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 rc...@apache.org on 2020/01/15 07:46:20 UTC
[james-project] 01/15: [Refactoring] Migrate to Junit 5
WebAdminServerIntegrationTest
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 677b28a69df33d158c56233097be85b8903000ac
Author: duc <dt...@linagora.com>
AuthorDate: Wed Jan 8 22:21:50 2020 +0700
[Refactoring] Migrate to Junit 5 WebAdminServerIntegrationTest
---
.../RabbitMQWebAdminServerIntegrationTest.java | 53 ++++++++++++---------
.../MemoryWebAdminServerIntegrationTest.java | 24 ++++++----
.../integration/WebAdminServerIntegrationTest.java | 55 +++++++++-------------
3 files changed, 68 insertions(+), 64 deletions(-)
diff --git a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
index 65c1423..4924364 100644
--- a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/rabbitmq/RabbitMQWebAdminServerIntegrationTest.java
@@ -28,11 +28,18 @@ import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
-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.backends.cassandra.versions.CassandraSchemaVersionManager;
import org.apache.james.junit.categories.BasicFeature;
+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.integration.WebAdminServerIntegrationTest;
import org.apache.james.webadmin.routes.AliasRoutes;
import org.apache.james.webadmin.routes.CassandraMappingsRoutes;
@@ -41,32 +48,36 @@ import org.apache.james.webadmin.swagger.routes.SwaggerRoutes;
import org.awaitility.Awaitility;
import org.awaitility.Duration;
import org.eclipse.jetty.http.HttpStatus;
-import org.junit.Rule;
-import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import io.restassured.http.ContentType;
@Category(BasicFeature.class)
-public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegrationTest {
+class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegrationTest {
+
+ private static final int LIMIT_TO_10_MESSAGES = 10;
+
+ @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(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+ .build();
private static final String VERSION = "/cassandra/version";
private static final String VERSION_LATEST = VERSION + "/latest";
private static final String UPGRADE_VERSION = VERSION + "/upgrade";
private static final String UPGRADE_TO_LATEST_VERSION = UPGRADE_VERSION + "/latest";
- @Rule
- public DockerCassandraRule cassandra = new DockerCassandraRule();
- @Rule
- public CassandraRabbitMQAwsS3JmapTestRule jamesTestRule = CassandraRabbitMQAwsS3JmapTestRule.defaultTestRule();
-
- @Override
- protected GuiceJamesServer createJamesServer() throws Exception {
- return jamesTestRule.jmapServer(cassandra.getModule());
- }
-
@Test
- public void getCurrentVersionShouldReturnNullForCurrentVersionAsBeginning() {
+ void getCurrentVersionShouldReturnNullForCurrentVersionAsBeginning() {
when()
.get(VERSION)
.then()
@@ -76,7 +87,7 @@ public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegra
}
@Test
- public void getLatestVersionShouldReturnTheConfiguredLatestVersion() {
+ void getLatestVersionShouldReturnTheConfiguredLatestVersion() {
when()
.get(VERSION_LATEST)
.then()
@@ -86,7 +97,7 @@ public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegra
}
@Test
- public void postShouldDoMigrationAndUpdateCurrentVersion() {
+ void postShouldDoMigrationAndUpdateCurrentVersion() {
String taskId = with()
.body(String.valueOf(CassandraSchemaVersionManager.MAX_VERSION.getValue()))
.post(UPGRADE_VERSION)
@@ -111,7 +122,7 @@ public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegra
}
@Test
- public void postShouldDoMigrationAndUpdateToTheLatestVersion() {
+ void postShouldDoMigrationAndUpdateToTheLatestVersion() {
String taskId = with().post(UPGRADE_TO_LATEST_VERSION)
.jsonPath()
.get("taskId");
@@ -130,7 +141,7 @@ public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegra
}
@Test
- public void cassandraMappingsEndpointShouldKeepDataConsistencyWhenDataValid() {
+ void cassandraMappingsEndpointShouldKeepDataConsistencyWhenDataValid() {
with()
.put(AliasRoutes.ROOT_PATH + SEPARATOR + USERNAME + "/sources/" + ALIAS_1);
with()
@@ -159,7 +170,7 @@ public class RabbitMQWebAdminServerIntegrationTest extends WebAdminServerIntegra
@Test
- public void getSwaggerShouldContainDistributedEndpoints() {
+ void getSwaggerShouldContainDistributedEndpoints() {
when()
.get(SwaggerRoutes.SWAGGER_ENDPOINT)
.then()
diff --git a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryWebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryWebAdminServerIntegrationTest.java
index 119bec7..6876e7a 100644
--- a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryWebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/memory/MemoryWebAdminServerIntegrationTest.java
@@ -20,19 +20,23 @@
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.modules.TestJMAPServerModule;
import org.apache.james.webadmin.WebAdminConfiguration;
import org.apache.james.webadmin.integration.WebAdminServerIntegrationTest;
-import org.junit.Rule;
+import org.junit.jupiter.api.extension.RegisterExtension;
-public class MemoryWebAdminServerIntegrationTest extends WebAdminServerIntegrationTest {
+class MemoryWebAdminServerIntegrationTest extends WebAdminServerIntegrationTest {
- @Rule
- public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+ private static final int LIMIT_TO_10_MESSAGES = 10;
- @Override
- protected GuiceJamesServer createJamesServer() throws Exception {
- return memoryJmap.jmapServer(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)))
+ .build();
}
\ No newline at end of file
diff --git a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index 5da8f67..547aa2a 100644
--- a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -49,9 +49,8 @@ import org.apache.james.webadmin.routes.UserMailboxesRoutes;
import org.apache.james.webadmin.routes.UserRoutes;
import org.apache.james.webadmin.swagger.routes.SwaggerRoutes;
import org.eclipse.jetty.http.HttpStatus;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import io.restassured.RestAssured;
@@ -69,13 +68,10 @@ public abstract class WebAdminServerIntegrationTest {
protected static final String ALIAS_1 = "alias1@" + DOMAIN;
protected static final String ALIAS_2 = "alias2@" + DOMAIN;
- private GuiceJamesServer guiceJamesServer;
private DataProbe dataProbe;
- @Before
- public void setUp() throws Exception {
- guiceJamesServer = createJamesServer();
- guiceJamesServer.start();
+ @BeforeEach
+ void setUp(GuiceJamesServer guiceJamesServer) throws Exception {
dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
dataProbe.addDomain(DOMAIN);
WebAdminGuiceProbe webAdminGuiceProbe = guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
@@ -84,15 +80,8 @@ public abstract class WebAdminServerIntegrationTest {
.build();
}
- @After
- public void tearDown() {
- guiceJamesServer.stop();
- }
-
- protected abstract GuiceJamesServer createJamesServer() throws Exception;
-
@Test
- public void postShouldAddTheGivenDomain() throws Exception {
+ void postShouldAddTheGivenDomain() throws Exception {
when()
.put(SPECIFIC_DOMAIN)
.then()
@@ -102,7 +91,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void mailQueueRoutesShouldBeExposed() {
+ void mailQueueRoutesShouldBeExposed() {
when()
.get(MailQueueRoutes.BASE_URL)
.then()
@@ -110,7 +99,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void healthCheckShouldReturn200WhenCalledRepeatedly() {
+ void healthCheckShouldReturn200WhenCalledRepeatedly() {
given().get(HealthCheckRoutes.HEALTHCHECK);
given().get(HealthCheckRoutes.HEALTHCHECK);
given().get(HealthCheckRoutes.HEALTHCHECK);
@@ -124,7 +113,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void mailRepositoriesRoutesShouldBeExposed() {
+ void mailRepositoriesRoutesShouldBeExposed() {
when()
.get(MailRepositoriesRoutes.MAIL_REPOSITORIES)
.then()
@@ -136,7 +125,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void gettingANonExistingMailRepositoryShouldNotCreateIt() {
+ void gettingANonExistingMailRepositoryShouldNotCreateIt() {
given()
.get(MailRepositoriesRoutes.MAIL_REPOSITORIES + "file%3A%2F%2Fvar%2Fmail%2Fcustom");
@@ -151,7 +140,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void deleteShouldRemoveTheGivenDomain() throws Exception {
+ void deleteShouldRemoveTheGivenDomain() throws Exception {
when()
.delete(SPECIFIC_DOMAIN)
.then()
@@ -161,7 +150,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void postShouldAddTheUser() throws Exception {
+ void postShouldAddTheUser() throws Exception {
given()
.body("{\"password\":\"password\"}")
.when()
@@ -173,7 +162,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void deleteShouldRemoveTheUser() throws Exception {
+ void deleteShouldRemoveTheUser() throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
given()
@@ -187,7 +176,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void getUsersShouldDisplayUsers() throws Exception {
+ void getUsersShouldDisplayUsers() throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
when()
@@ -199,7 +188,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void putMailboxShouldAddAMailbox() throws Exception {
+ void putMailboxShouldAddAMailbox(GuiceJamesServer guiceJamesServer) throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
when()
@@ -211,7 +200,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void deleteMailboxShouldRemoveAMailbox() throws Exception {
+ void deleteMailboxShouldRemoveAMailbox(GuiceJamesServer guiceJamesServer) throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
guiceJamesServer.getProbe(MailboxProbeImpl.class).createMailbox("#private", USERNAME, MAILBOX);
@@ -224,7 +213,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void addressGroupsEndpointShouldHandleRequests() throws Exception {
+ void addressGroupsEndpointShouldHandleRequests() throws Exception {
with()
.put(GroupsRoutes.ROOT_PATH + SEPARATOR + GROUP + SEPARATOR + USERNAME);
with()
@@ -242,7 +231,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void addressForwardsEndpointShouldListForwardAddresses() throws Exception {
+ void addressForwardsEndpointShouldListForwardAddresses() throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
dataProbe.addUser(USERNAME_2, "anyPassword");
@@ -263,7 +252,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void addressAliasesEndpointShouldListAliasesAddresses() {
+ void addressAliasesEndpointShouldListAliasesAddresses() {
with()
.put(AliasRoutes.ROOT_PATH + SEPARATOR + USERNAME + "/sources/" + ALIAS_1);
with()
@@ -281,7 +270,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void getSwaggerShouldReturnJsonDataForSwagger() {
+ void getSwaggerShouldReturnJsonDataForSwagger() {
when()
.get(SwaggerRoutes.SWAGGER_ENDPOINT)
.then()
@@ -303,7 +292,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void validateHealthChecksShouldReturnOk() {
+ void validateHealthChecksShouldReturnOk() {
when()
.get(HealthCheckRoutes.HEALTHCHECK)
.then()
@@ -311,7 +300,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void jmapTasksShouldBeExposed() {
+ void jmapTasksShouldBeExposed() {
String taskId = with()
.queryParam("task", "recomputeFastViewProjectionItems")
.post("/mailboxes")
@@ -328,7 +317,7 @@ public abstract class WebAdminServerIntegrationTest {
}
@Test
- public void jmapUserTasksShouldBeExposed() throws Exception {
+ void jmapUserTasksShouldBeExposed() throws Exception {
dataProbe.addUser(USERNAME, "anyPassword");
String taskId = with()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org