This is an automated email from the ASF dual-hosted git repository. hqtran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f459d10e66a294af8e6a850d6b994235c981deff Author: vttran <[email protected]> AuthorDate: Thu Jan 15 13:52:37 2026 +0700 TEST: Module jpa-smtp-app : fix junit 4 incompatible --- server/apps/jpa-smtp-app/pom.xml | 10 +++++++ .../java/org/apache/james/JPAJamesServerTest.java | 31 +++++++++------------ .../james/mariadb/JPAMariaDBJamesServerTest.java | 32 ++++++++++------------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/server/apps/jpa-smtp-app/pom.xml b/server/apps/jpa-smtp-app/pom.xml index 34edd06c54..bc85b84bf0 100644 --- a/server/apps/jpa-smtp-app/pom.xml +++ b/server/apps/jpa-smtp-app/pom.xml @@ -182,12 +182,22 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>junit-jupiter</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.testcontainers</groupId> <artifactId>mariadb</artifactId> <version>${testcontainers.modules.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/server/apps/jpa-smtp-app/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/apps/jpa-smtp-app/src/test/java/org/apache/james/JPAJamesServerTest.java index 9517b48f20..b435945616 100644 --- a/server/apps/jpa-smtp-app/src/test/java/org/apache/james/JPAJamesServerTest.java +++ b/server/apps/jpa-smtp-app/src/test/java/org/apache/james/JPAJamesServerTest.java @@ -27,6 +27,7 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import jakarta.persistence.EntityManagerFactory; @@ -37,28 +38,22 @@ import org.apache.james.mailrepository.jpa.model.JPAUrl; import org.apache.james.modules.protocols.SmtpGuiceProbe; import org.apache.james.rrt.jpa.model.JPARecipientRewrite; import org.apache.james.user.jpa.model.JPAUser; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class JPAJamesServerTest { private GuiceJamesServer server; private SocketChannel socketChannel; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public Path tempDir; - @After - public void teardown() { - server.stop(); - } - - private org.apache.james.GuiceJamesServer createJamesServer() throws IOException { + private org.apache.james.GuiceJamesServer createJamesServer() { JPAJamesConfiguration configuration = JPAJamesConfiguration.builder() - .workingDirectory(temporaryFolder.newFolder()) + .workingDirectory(tempDir.toFile()) .configurationFromClasspath() .usersRepository(DEFAULT) .build(); @@ -70,16 +65,16 @@ public class JPAJamesServerTest { .toInstance(JpaTestCluster.create(JPAUser.class, JPADomain.class, JPARecipientRewrite.class, JPAUrl.class, JPAMail.class) .getEntityManagerFactory())); } - - @Before + + @BeforeEach public void setup() throws Exception { server = createJamesServer(); socketChannel = SocketChannel.open(); server.start(); } - @After - public void tearDown() throws Exception { + @AfterEach + public void tearDown() { server.stop(); } diff --git a/server/apps/jpa-smtp-app/src/test/java/org/apache/james/mariadb/JPAMariaDBJamesServerTest.java b/server/apps/jpa-smtp-app/src/test/java/org/apache/james/mariadb/JPAMariaDBJamesServerTest.java index 50df95b804..9682fd5c2a 100644 --- a/server/apps/jpa-smtp-app/src/test/java/org/apache/james/mariadb/JPAMariaDBJamesServerTest.java +++ b/server/apps/jpa-smtp-app/src/test/java/org/apache/james/mariadb/JPAMariaDBJamesServerTest.java @@ -27,44 +27,47 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import org.apache.james.GuiceJamesServer; import org.apache.james.JPAJamesConfiguration; import org.apache.james.JPAJamesServerMain; import org.apache.james.modules.protocols.SmtpGuiceProbe; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.testcontainers.containers.MariaDBContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +@Testcontainers public class JPAMariaDBJamesServerTest { private GuiceJamesServer server; private SocketChannel socketChannel; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public Path tempDir; - @Rule + @Container public MariaDBContainer<?> mariaDB = new MariaDBContainer<>(); - @Before + @BeforeEach public void setup() throws Exception { server = createJamesServer(mariaDB.getJdbcUrl()); socketChannel = SocketChannel.open(); server.start(); } - @After + @AfterEach public void teardown() { server.stop(); } - private org.apache.james.GuiceJamesServer createJamesServer(String mariaDBUrl) throws IOException { + private org.apache.james.GuiceJamesServer createJamesServer(String mariaDBUrl) { JPAJamesConfiguration configuration = JPAJamesConfiguration.builder() - .workingDirectory(temporaryFolder.newFolder()) + .workingDirectory(tempDir.toFile()) .usersRepository(DEFAULT) .configurationFromClasspath() .build(); @@ -73,11 +76,6 @@ public class JPAMariaDBJamesServerTest { .overrideWith(new TestJPAMariaDBConfigurationModule(mariaDBUrl)); } - @After - public void tearDown() throws Exception { - server.stop(); - } - @Test public void connectSMTPServerShouldSendShabangOnConnect() throws Exception { socketChannel.connect(new InetSocketAddress("127.0.0.1", server.getProbe(SmtpGuiceProbe.class).getSmtpPort().getValue())); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
