This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new b2f442a37f49 CAMEL-27771: Fix flaky MailMimeDecodeHeadersTest (#31129)
b2f442a37f49 is described below
commit b2f442a37f493cb96a3d4e049adb49faed20cdb0
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 30 22:12:48 2026 +0100
CAMEL-27771: Fix flaky MailMimeDecodeHeadersTest (#31129)
Each test method gets its own pair of GreenMail mailboxes, the POP3
consumers delete what they read, and
setupResources() clears the mailboxes before the CamelContext starts.
Before, a POP3 poll could pick up messages of the
previous test method before the test cleared the shared mailboxes.
Claude Sonnet 4.6 on behalf of gnodet.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../component/mail/MailMimeDecodeHeadersTest.java | 59 +++++++++++++++-------
1 file changed, 40 insertions(+), 19 deletions(-)
diff --git
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMimeDecodeHeadersTest.java
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMimeDecodeHeadersTest.java
index d1b170e7623f..978f1091846d 100644
---
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMimeDecodeHeadersTest.java
+++
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailMimeDecodeHeadersTest.java
@@ -29,8 +29,16 @@ import org.junit.jupiter.api.Test;
* Unit test for Mail header decoding/unfolding support.
*/
public class MailMimeDecodeHeadersTest extends CamelTestSupport {
- private static final MailboxUser plain =
Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-plain", "secret");
- private static final MailboxUser decoded =
Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-decoded", "secret");
+ // Each test method gets its own pair of mailboxes to avoid any cross-test
interference.
+ private static final MailboxUser plainLong
+ = Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-plain-long",
"secret");
+ private static final MailboxUser decodedLong
+ =
Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-decoded-long", "secret");
+ private static final MailboxUser plainNonAscii
+ =
Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-plain-nonascii", "secret");
+ private static final MailboxUser decodedNonAscii
+ =
Mailbox.getOrCreateUser("MailMimeDecodeHeadersTest-decoded-nonascii", "secret");
+
private String nonAsciiSubject = "\uD83D\uDC2A rocks!";
private String encodedNonAsciiSubject = "=?UTF-8?Q?=F0=9F=90=AA_rocks!?=";
@@ -48,20 +56,18 @@ public class MailMimeDecodeHeadersTest extends
CamelTestSupport {
@Test
public void testLongMailSubject() throws Exception {
- Mailbox.clearAll(plain, decoded);
-
// The email subject is >76 chars and will get MIME folded.
template.sendBody("direct:longSubject", "");
// When mimeDecodeHeaders=true is used, expect the received subject to
be MIME unfolded.
- MockEndpoint mockDecoded = getMockEndpoint("mock:decoded");
+ MockEndpoint mockDecoded = getMockEndpoint("mock:decodedLong");
mockDecoded.expectedMessageCount(1);
mockDecoded.expectedHeaderReceived("subject", longSubject);
mockDecoded.setResultWaitTime(10000);
mockDecoded.assertIsSatisfied();
// When mimeDecodeHeaders=false or missing, expect the received
subject to be MIME folded.
- MockEndpoint mockPlain = getMockEndpoint("mock:plain");
+ MockEndpoint mockPlain = getMockEndpoint("mock:plainLong");
mockPlain.expectedMessageCount(1);
mockPlain.expectedHeaderReceived("subject", foldedLongSubject);
mockPlain.setResultWaitTime(10000);
@@ -70,43 +76,58 @@ public class MailMimeDecodeHeadersTest extends
CamelTestSupport {
@Test
public void testNonAsciiMailSubject() throws Exception {
- Mailbox.clearAll(plain, decoded);
-
// The email subject contains non-ascii characters and will be encoded.
template.sendBody("direct:nonAsciiSubject", "");
- // When mimeDecodeHeaders=true is used, expect the received subject to
be MIME encoded.
- MockEndpoint mockDecoded = getMockEndpoint("mock:decoded");
+ // When mimeDecodeHeaders=true is used, expect the received subject to
be MIME decoded.
+ MockEndpoint mockDecoded = getMockEndpoint("mock:decodedNonAscii");
mockDecoded.expectedMessageCount(1);
mockDecoded.expectedHeaderReceived("subject", nonAsciiSubject);
mockDecoded.assertIsSatisfied();
// When mimeDecodeHeaders=false or missing, expect the received
subject to be MIME encoded.
- MockEndpoint mockPlain = getMockEndpoint("mock:plain");
+ MockEndpoint mockPlain = getMockEndpoint("mock:plainNonAscii");
mockPlain.expectedMessageCount(1);
mockPlain.expectedHeaderReceived("subject", encodedNonAsciiSubject);
mockPlain.assertIsSatisfied();
}
+ @Override
+ public void setupResources() throws Exception {
+ // Clear all mailboxes before each test so a failed surefire rerun
(rerunFailingTestsCount)
+ // that left an unconsumed message in the mailbox cannot cause a
spurious count of 2.
+ Mailbox.clearAll(plainLong, decodedLong, plainNonAscii,
decodedNonAscii);
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
+ // Routes for testLongMailSubject — dedicated mailboxes
from("direct:longSubject")
.setHeader("subject", constant(longSubject))
- .to(plain.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true",
- decoded.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true");
+ .to(plainLong.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true",
+ decodedLong.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true");
+
+ from(plainLong.uriPrefix(Protocol.pop3) +
"&initialDelay=100&delay=100&delete=true")
+ .to("mock:plainLong");
+
+ from(decodedLong.uriPrefix(Protocol.pop3)
+ +
"&initialDelay=100&delay=100&delete=true&mimeDecodeHeaders=true")
+ .to("mock:decodedLong");
+ // Routes for testNonAsciiMailSubject — dedicated mailboxes
from("direct:nonAsciiSubject")
.setHeader("subject", constant(nonAsciiSubject))
- .to(plain.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true",
- decoded.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true");
+ .to(plainNonAscii.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true",
+ decodedNonAscii.uriPrefix(Protocol.smtp) +
"&useHeaderSubject=true");
- from(plain.uriPrefix(Protocol.pop3) +
"&initialDelay=100&delay=100")
- .to("mock:plain");
+ from(plainNonAscii.uriPrefix(Protocol.pop3) +
"&initialDelay=100&delay=100&delete=true")
+ .to("mock:plainNonAscii");
- from(decoded.uriPrefix(Protocol.pop3) +
"&initialDelay=100&delay=100&mimeDecodeHeaders=true")
- .to("mock:decoded");
+ from(decodedNonAscii.uriPrefix(Protocol.pop3)
+ +
"&initialDelay=100&delay=100&delete=true&mimeDecodeHeaders=true")
+ .to("mock:decodedNonAscii");
}
};
}