1 | ("Test subject");↵ | | 1 | ("Test subject");↵
|
2 | testMailClient.setMessage( "test line 1\n" +↵ | | 2 | testMailClient.setMessage(↵
|
3 | "test line 2" );↵ | | 3 | "");↵
|
|
4 | Thread client = new Thread(testMailClient);↵ | | 4 | Thread client = new Thread(testMailClient);↵
|
5 | client.start();↵ | | 5 | client.start();↵
|
|
6 | try {↵ | | 6 | try {↵
|
7 | server.join(60 * 1000); // 60s↵ | | 7 | server.join(60 * 1000); // 60s↵
|
8 | client.join(30 * 1000); // a further 30s↵ | | 8 | client.join(30 * 1000); // a further 30s↵
|
9 | } catch (InterruptedException ie ) {↵ | | 9 | } catch (InterruptedException ie ) {↵
|
10 | fail( "InterruptedException: " + ie );↵ | | 10 | fail( "InterruptedException: " + ie );↵
|
11 | }↵ | | 11 | }↵
|
|
12 | String result = testMailServer.getResult();↵ | | 12 | String result = testMailServer.getResult();↵
|
13 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵ | | 13 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵
|
14 | "HELO " + local + "\r\n" +↵ | | 14 | "HELO " + local + "\r\n" +↵
|
15 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵ | | 15 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵
|
16 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 16 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵
|
17 | "250\r\n" +↵ | | 17 | "250\r\n" +↵
|
18 | "RCPT TO: <cc@you.com>\r\n" +↵ | | 18 | "RCPT TO: <to@you.com>\r\n" +↵
|
19 | "250\r\n" +↵ | | 19 | "250\r\n" +↵
|
20 | "DATA\r\n" +↵ | | 20 | "DATA\r\n" +↵
|
21 | "354\r\n" +↵ | | 21 | "354\r\n" +↵
|
22 | "Subject: Test subject\r\n" +↵ | | 22 | "Subject: Test subject\r\n" +↵
|
23 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 23 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵
|
24 | "Cc: cc@you.com\r\n" +↵ | | 24 | "To: to@you.com\r\n" +↵
|
25 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵ | | 25 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵
|
26 | "\r\n" +↵ | | 26 | "\r\n" +↵
|
27 | "test line 1\r\n" +↵ | | 27 | "↵
|
28 | "test line 2\r\n" +↵ | | 28 | \r\n" +↵
|
29 | "\r\n" +↵ | | 29 | "\r\n" +↵
|
30 | ".\r\n" +↵ | | 30 | ".\r\n" +↵
|
31 | "250\r\n" +↵ | | 31 | "250\r\n" +↵
|
32 | "QUIT\r\n" +↵ | | 32 | "QUIT\r\n" +↵
|
33 | "221\r\n";↵ | | 33 | "221\r\n";↵
|
34 | assertEquals(expectedResult.length(), result.length());↵ | | 34 | assertEquals(expectedResult.length(), result.length());↵
|
35 | assertEquals(expectedResult, result);↵ | | 35 | assertEquals(expectedResult, result);↵
|
36 | if (testMailClient.isFailed()) {↵ | | 36 | if (testMailClient.isFailed()) {↵
|
37 | fail(testMailClient.getFailMessage());↵ | | 37 | fail(testMailClient.getFailMessage());↵
|
38 | }↵ | | 38 | }↵
|
39 | }↵ | | 39 | }↵
|
|
|
40 | /**↵ | | 40 | /**↵
|
41 | * Test a MailMessage with no to or cc lines↵ | | 41 | * Test a MailMessage with US-ASCII character set↵
|
| | | 42 | * The next four testcase can be kinda hard to debug as Ant will often↵
|
| | | 43 | * print the junit failure in US-ASCII.↵
|
42 | */↵ | | 44 | */↵
|
43 | public void testBccOnly() {↵ | | 45 | public void testAsciiCharset() {↵
|
|
44 | ServerThread testMailServer = new ServerThread();↵ | | 46 | ServerThread testMailServer = new ServerThread();↵
|
45 | Thread server = new Thread(testMailServer);↵ | | 47 | Thread server = new Thread(testMailServer);↵
|
46 | server.start();↵ | | 48 | server.start();↵
|
|
47 | ClientThread testMailClient = new ClientThread();↵ | | 49 | ClientThread testMailClient = new ClientThread();↵
|
|
48 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵ | | 50 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵
|
49 | testMailClient.bcc("bcc@you.com");↵ | | 51 | testMailClient.to("Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>");↵
|
50 | testMailClient.setSubject("Test subject");↵ | | 52 | testMailClient.setSubject("Test subject");↵
|
51 | testMailClient.setMessage( "test line 1\n" +↵ | | 53 | testMailClient.setMessage(↵
|
52 | "test line 2" );↵ | | 54 | "");↵
|
|
53 | Thread client = new Thread(testMailClient);↵ | | 55 | Thread client = new Thread(testMailClient);↵
|
54 | client.start();↵ | | 56 | client.start();↵
|
|
55 | try {↵ | | 57 | try {↵
|
56 | server.join(60 * 1000); // 60s↵ | | 58 | server.join(60 * 1000); // 60s↵
|
57 | client.join(30 * 1000); // a further 30s↵ | | 59 | client.join(30 * 1000); // a further 30s↵
|
58 | } catch (InterruptedException ie ) {↵ | | 60 | } catch (InterruptedException ie ) {↵
|
59 | fail( "InterruptedException: " + ie );↵ | | 61 | fail("InterruptedException: " + ie);↵
|
60 | }↵ | | 62 | }↵
|
|
61 | String result = testMailServer.getResult();↵ | | 63 | String result = testMailServer.getResult();↵
|
62 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵ | | 64 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵
|
63 | "HELO " + local + "\r\n" +↵ | | 65 | "HELO " + local + "\r\n" +↵
|
64 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵ | | 66 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵
|
65 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 67 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵
|
66 | "250\r\n" +↵ | | 68 | "250\r\n" +↵
|
67 | "RCPT TO: <bcc@you.com>\r\n" +↵ | | 69 | "RCPT TO: <abuse@mail-abuse.org>\r\n" +↵
|
68 | "250\r\n" +↵ | | 70 | "250\r\n" +↵
|
69 | "DATA\r\n" +↵ | | 71 | "DATA\r\n" +↵
|
70 | "354\r\n" +↵ | | 72 | "354\r\n" +↵
|
71 | "Subject: Test subject\r\n" +↵ | | 73 | "Subject: Test subject\r\n" +↵
|
72 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 74 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵
|
| | | 75 | "To: Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>\r\n" +↵
|
73 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵ | | 76 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵
|
74 | "\r\n" +↵ | | 77 | "\r\n" +↵
|
75 | "test line 1\r\n" +↵ | | 78 | "↵
|
76 | "test line 2\r\n" +↵ | | 79 | \r\n" +↵
|
77 | "\r\n" +↵ | | 80 | "\r\n" +↵
|
78 | ".\r\n" +↵ | | 81 | ".\r\n" +↵
|
79 | "250\r\n" +↵ | | 82 | "250\r\n" +↵
|
80 | "QUIT\r\n" +↵ | | 83 | "QUIT\r\n" +↵
|
81 | "221\r\n" | | 84 | "221\r\n"
|