From 4bf266be50dd4119b01da9834a86900c140a4820 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Sat, 13 May 2017 10:05:50 -0400 Subject: [PATCH] Test Mail Server Add CC: and BCC: Headers Allow assertions of proper population in tests. Also set Github tab size to 4. Fix BODYSTRUCTURE metadata to match actual body (1 line, 5 octets). Fix RFC822.SIZE to match actual message. --- .editorconfig | 11 ++++++ .../mail/ImapMailReceiverTests.java | 19 ++++++----- .../integration/mail/config/Pop3Tests.java | 6 +++- .../integration/test/mail/TestMailServer.java | 34 +++++++++++++------ 4 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..26c1be0945 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root=true + +[*.java] +indent_style = tab +indent_size = 4 +continuation_indent_size = 8 + +[*.xml] +indent_style = tab +indent_size = 4 +continuation_indent_size = 8 diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java index 1900e9e184..98eb01ea4c 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.verify; import java.io.IOException; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Properties; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -218,14 +219,15 @@ public class ImapMailReceiverTests { else { org.springframework.messaging.Message received = channel.receive(10000); assertNotNull(received); - assertNotNull(received.getHeaders().get(MailHeaders.RAW_HEADERS)); - assertThat((String) received.getHeaders().get(MailHeaders.CONTENT_TYPE), - equalTo("TEXT/PLAIN; charset=ISO-8859-1")); - assertThat((String) received.getHeaders().get(MessageHeaders.CONTENT_TYPE), - equalTo("TEXT/PLAIN; charset=ISO-8859-1")); - assertThat((String) received.getHeaders().get(MailHeaders.FROM), equalTo("Bar ")); - assertThat(((String[]) received.getHeaders().get(MailHeaders.TO))[0], equalTo("Foo ")); - assertThat((String) received.getHeaders().get(MailHeaders.SUBJECT), equalTo("Test Email")); + MessageHeaders headers = received.getHeaders(); + assertNotNull(headers.get(MailHeaders.RAW_HEADERS)); + assertThat(headers.get(MailHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1")); + assertThat(headers.get(MessageHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1")); + assertThat(headers.get(MailHeaders.FROM), equalTo("Bar ")); + assertThat((headers.get(MailHeaders.TO, String[].class))[0], equalTo("Foo ")); + assertThat(Arrays.toString(headers.get(MailHeaders.CC, String[].class)), equalTo("[a@b, c@d]")); + assertThat(Arrays.toString(headers.get(MailHeaders.BCC, String[].class)), equalTo("[e@f, g@h]")); + assertThat(headers.get(MailHeaders.SUBJECT), equalTo("Test Email")); if (simple) { assertThat(received.getPayload(), equalTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n")); } @@ -448,7 +450,6 @@ public class ImapMailReceiverTests { verify(receiver, times(0)).deleteMessages((Message[]) Mockito.any()); } - @SuppressWarnings("resource") @Test @Ignore public void testMessageHistory() throws Exception { diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/Pop3Tests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/Pop3Tests.java index 1ce0100872..56eddc64b8 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/Pop3Tests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/Pop3Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Arrays; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -65,6 +67,8 @@ public class Pop3Tests { assertNotNull(message); MessageHeaders headers = message.getHeaders(); assertEquals("Foo ", headers.get(MailHeaders.TO, String[].class)[0]); + assertEquals("[a@b, c@d]", Arrays.toString(headers.get(MailHeaders.CC, String[].class))); + assertEquals("[e@f, g@h]", Arrays.toString(headers.get(MailHeaders.BCC, String[].class))); assertEquals("Bar ", headers.get(MailHeaders.FROM)); assertEquals("Test Email", headers.get(MailHeaders.SUBJECT)); assertEquals("foo\r\n\r\n", message.getPayload()); diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java index 5b44b2c0d2..8b23d3221e 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -289,21 +289,28 @@ public class TestMailServer { assertions.add("searchWithUserFlag"); } else if (line.contains("FETCH 1 (ENVELOPE")) { - write("* 1 FETCH (RFC822.SIZE 6909 INTERNALDATE \"27-May-2013 09:45:41 +0000\" " + write("* 1 FETCH (RFC822.SIZE " + + MESSAGE.length() + + " INTERNALDATE \"27-May-2013 09:45:41 +0000\" " + "FLAGS (\\Seen) " + "ENVELOPE (\"Mon, 27 May 2013 15:14:49 +0530\" " - + "\"Test Email\" ((\"Bar\" NIL \"bar\" \"baz\")) " - + "((\"Bar\" NIL \"bar\" \"baz\")) " - + "((\"Bar\" NIL \"bar\" \"baz\")) " - + "((\"Foo\" NIL \"foo\" \"bar\")) NIL NIL " - + "\"<4DA0A7E4.3010506@baz.net>\" " - + "\"\") " - + "BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))"); + + "\"Test Email\" " + + "((\"Bar\" NIL \"bar\" \"baz\")) " // From + + "((\"Bar\" NIL \"bar\" \"baz\")) " // Sender + + "((\"Bar\" NIL \"bar\" \"baz\")) " // Reply To + + "((\"Foo\" NIL \"foo\" \"bar\")) " // To + + "((NIL NIL \"a\" \"b\") (NIL NIL \"c\" \"d\")) " // cc + + "((NIL NIL \"e\" \"f\") (NIL NIL \"g\" \"h\")) " // bcc + + "\"<4DA0A7E4.3010506@baz.net>\" " // In reply to + + "\"\") " // msgid + + "BODYSTRUCTURE " + + "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))"); write(tag + "OK FETCH completed"); } else if (line.contains("FETCH 2 (BODYSTRUCTURE)")) { write("* 2 FETCH " + - "BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))"); + "BODYSTRUCTURE " + + "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))"); write(tag + "OK FETCH completed"); } else if (line.contains("STORE 1 +FLAGS (\\Flagged)")) { @@ -446,7 +453,12 @@ public class TestMailServer { public static final String BODY = "foo\r\n"; public static final String MESSAGE = - "To: Foo \r\nFrom: Bar \r\nSubject: Test Email\r\n\r\n" + BODY; + "To: Foo \r\n" + + "cc: a@b, c@d\r\n" + + "bcc: e@f, g@h\r\n" + + "From: Bar \r\n" + + "Subject: Test Email\r\n" + + "\r\n" + BODY; protected final Socket socket;