1 | ( "test line 1\n" +↵ | | 1 | ( "test line 1\n" +↵
|
2 | "test line 2" );↵ | | 2 | "test line 2" );↵
|
|
3 | Thread client = new Thread(testMailClient);↵ | | 3 | Thread client = new Thread(testMailClient);↵
|
4 | client.start();↵ | | 4 | client.start();↵
|
|
5 | try {↵ | | 5 | try {↵
|
6 | server.join(60 * 1000); // 60s↵ | | 6 | server.join(60 * 1000); // 60s↵
|
7 | client.join(30 * 1000); // a further 30s↵ | | 7 | client.join(30 * 1000); // a further 30s↵
|
8 | } catch (InterruptedException ie ) {↵ | | 8 | } catch (InterruptedException ie ) {↵
|
9 | fail( "InterruptedException: " + ie );↵ | | 9 | fail( "InterruptedException: " + ie );↵
|
10 | }↵ | | 10 | }↵
|
|
11 | String result = testMailServer.getResult();↵ | | 11 | String result = testMailServer.getResult();↵
|
12 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵ | | 12 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵
|
13 | "HELO " + local + "\r\n" +↵ | | 13 | "HELO " + local + "\r\n" +↵
|
14 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵ | | 14 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵
|
15 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 15 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵
|
16 | "250\r\n" +↵ | | 16 | "250\r\n" +↵
|
17 | "RCPT TO: <bcc@you.com>\r\n" +↵ | | 17 | "RCPT TO: <to@you.com>\r\n" +↵
|
18 | "250\r\n" +↵ | | 18 | "250\r\n" +↵
|
19 | "DATA\r\n" +↵ | | 19 | "DATA\r\n" +↵
|
20 | "354\r\n" +↵ | | 20 | "354\r\n" +↵
|
21 | "Subject: Test subject\r\n" +↵ | | |
|
22 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 21 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵
|
| | | 22 | "To: to@you.com\r\n" +↵
|
23 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵ | | 23 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵
|
24 | "\r\n" +↵ | | 24 | "\r\n" +↵
|
25 | "test line 1\r\n" +↵ | | 25 | "test line 1\r\n" +↵
|
26 | "test line 2\r\n" +↵ | | 26 | "test line 2\r\n" +↵
|
27 | "\r\n" +↵ | | 27 | "\r\n" +↵
|
28 | ".\r\n" +↵ | | 28 | ".\r\n" +↵
|
29 | "250\r\n" +↵ | | 29 | "250\r\n" +↵
|
30 | "QUIT\r\n" +↵ | | 30 | "QUIT\r\n" +↵
|
31 | "221\r\n";↵ | | 31 | "221\r\n";↵
|
32 | assertEquals( expectedResult.length(), result.length() );↵ | | 32 | assertEquals( expectedResult.length(), result.length() );↵
|
33 | assertEquals( expectedResult, result );↵ | | 33 | assertEquals( expectedResult, result );↵
|
34 | if ( testMailClient.isFailed() ) {↵ | | 34 | if ( testMailClient.isFailed() ) {↵
|
35 | fail( testMailClient.getFailMessage() );↵ | | 35 | fail( testMailClient.getFailMessage() );↵
|
36 | }↵ | | 36 | }↵
|
37 | }↵ | | 37 | }↵
|
|
|
38 | /**↵ | | 38 | /**↵
|
39 | * Test a MailMessage with no subject line↵ | | 39 | * Test a MailMessage with ↵
|
40 | * Subject is an optional field (RFC 822 s4.1)↵ | | 40 | empty body message↵
|
41 | */↵ | | 41 | */↵
|
42 | public void testNoSubject() {↵ | | 42 | public void testEmptyBody() {↵
|
43 | ServerThread testMailServer = new ServerThread();↵ | | 43 | ServerThread testMailServer = new ServerThread();↵
|
44 | Thread server = new Thread(testMailServer);↵ | | 44 | Thread server = new Thread(testMailServer);↵
|
45 | server.start();↵ | | 45 | server.start();↵
|
|
46 | ClientThread testMailClient = new ClientThread();↵ | | 46 | ClientThread testMailClient = new ClientThread();↵
|
|
47 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵ | | 47 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵
|
48 | testMailClient.to("to@you.com");↵ | | 48 | testMailClient.to("to@you.com");↵
|
49 | testMailClient.setMessage( "test line 1\n" +↵ | | 49 | testMailClient.set↵
|
50 | "test line 2" ) | | 50 | Subject("Test subject")
|