1 | ("Test subject");↵ | | 1 | ("to@you.com");↵
|
2 | testMailClient.setMessage( "test line 1\n" +↵ | | 2 | testMailClient.setMessage( "test line 1\n" +↵
|
3 | "test line 2" );↵ | | 3 | "test line 2" );↵
|
|
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" +↵ | | |
|
23 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 22 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵
|
24 | "Cc: cc@you.com\r\n" +↵ | | 23 | "To: to@you.com\r\n" +↵
|
25 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵ | | 24 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵
|
26 | "\r\n" +↵ | | 25 | "\r\n" +↵
|
27 | "test line 1\r\n" +↵ | | 26 | "test line 1\r\n" +↵
|
28 | "test line 2\r\n" +↵ | | 27 | "test line 2\r\n" +↵
|
29 | "\r\n" +↵ | | 28 | "\r\n" +↵
|
30 | ".\r\n" +↵ | | 29 | ".\r\n" +↵
|
31 | "250\r\n" +↵ | | 30 | "250\r\n" +↵
|
32 | "QUIT\r\n" +↵ | | 31 | "QUIT\r\n" +↵
|
33 | "221\r\n";↵ | | 32 | "221\r\n";↵
|
34 | assertEquals(expectedResult.length(), result.length());↵ | | 33 | assertEquals( expectedResult.length(), result.length() );↵
|
35 | assertEquals(expectedResult, result);↵ | | 34 | assertEquals( expectedResult, result );↵
|
36 | if (testMailClient.isFailed()) {↵ | | 35 | if ( testMailClient.isFailed() ) {↵
|
37 | fail(testMailClient.getFailMessage());↵ | | 36 | fail( testMailClient.getFailMessage() );↵
|
38 | }↵ | | 37 | }↵
|
39 | }↵ | | 38 | }↵
|
|
|
40 | /**↵ | | 39 | /**↵
|
41 | * Test a MailMessage with no to or cc lines↵ | | 40 | * Test a MailMessage with empty body message↵
|
42 | */↵ | | 41 | */↵
|
43 | public void testBccOnly() {↵ | | 42 | public void testEmptyBody() {↵
|
44 | ServerThread testMailServer = new ServerThread();↵ | | 43 | ServerThread testMailServer = new ServerThread();↵
|
45 | Thread server = new Thread(testMailServer);↵ | | 44 | Thread server = new Thread(testMailServer);↵
|
46 | server.start();↵ | | 45 | server.start();↵
|
|
47 | ClientThread testMailClient = new ClientThread();↵ | | 46 | ClientThread testMailClient = new ClientThread();↵
|
|
48 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵ | | 47 | testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>");↵
|
49 | testMailClient.bcc("bcc@you.com");↵ | | 48 | testMailClient.to("to@you.com");↵
|
50 | testMailClient.setSubject("Test subject");↵ | | 49 | testMailClient.setSubject("Test subject");↵
|
51 | testMailClient.setMessage( "test line 1\n" +↵ | | 50 | testMailClient.setMessage(↵
|
52 | "test line 2" );↵ | | 51 | "");↵
|
|
53 | Thread client = new Thread(testMailClient);↵ | | 52 | Thread client = new Thread(testMailClient);↵
|
54 | client.start();↵ | | 53 | client.start();↵
|
|
55 | try {↵ | | 54 | try {↵
|
56 | server.join(60 * 1000); // 60s↵ | | 55 | server.join(60 * 1000); // 60s↵
|
57 | client.join(30 * 1000); // a further 30s↵ | | 56 | client.join(30 * 1000); // a further 30s↵
|
58 | } catch (InterruptedException ie ) {↵ | | 57 | } catch (InterruptedException ie ) {↵
|
59 | fail( "InterruptedException: " + ie );↵ | | 58 | fail( "InterruptedException: " + ie );↵
|
60 | }↵ | | 59 | }↵
|
|
61 | String result = testMailServer.getResult();↵ | | 60 | String result = testMailServer.getResult();↵
|
62 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵ | | 61 | String expectedResult = "220 test SMTP EmailTaskTest\r\n" +↵
|
63 | "HELO " + local + "\r\n" +↵ | | 62 | "HELO " + local + "\r\n" +↵
|
64 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵ | | 63 | "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" +↵
|
65 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 64 | "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" +↵
|
66 | "250\r\n" +↵ | | 65 | "250\r\n" +↵
|
67 | "RCPT TO: <bcc@you.com>\r\n" +↵ | | 66 | "RCPT TO: <to@you.com>\r\n" +↵
|
68 | "250\r\n" +↵ | | 67 | "250\r\n" +↵
|
69 | "DATA\r\n" +↵ | | 68 | "DATA\r\n" +↵
|
70 | "354\r\n" +↵ | | 69 | "354\r\n" +↵
|
71 | "Subject: Test subject\r\n" +↵ | | 70 | "Subject: Test subject\r\n" +↵
|
72 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵ | | 71 | "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" +↵
|
| | | 72 | "To: to@you.com\r\n" +↵
|
73 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵ | | 73 | "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" +↵
|
74 | "\r\n" +↵ | | 74 | "\r\n" +↵
|
75 | "test line 1\r\n" +↵ | | 75 | "↵
|
76 | "test line 2\r\n" +↵ | | 76 | \r\n" +↵
|
77 | "\r\n" +↵ | | 77 | "\r\n" +↵
|
78 | ".\r\n" +↵ | | 78 | ".\r\n" +↵
|
79 | "250\r\n" +↵ | | 79 | "250\r\n" +↵
|
80 | "QUIT\r\n" +↵ | | 80 | "QUIT\r\n" +↵
|
81 | "221\r\n";↵ | | 81 | "221\r\n";↵
|
82 | assertEquals( expectedResult.length(), result.length() );↵ | | 82 | assertEquals(expectedResult.length(), result.length());↵
|
83 | assertEquals( expectedResult, result );↵ | | 83 | assertEquals(expectedResult, result);↵
|
84 | if ( testMailClient.isFailed() ) {↵ | | 84 | if (testMailClient.isFailed()) {↵
|
85 | fail( testMailClient.getFailMessage() );↵ | | 85 | fail(testMailClient.getFailMessage());↵
|
86 | }↵ | | 86 | }↵
|
87 | | | 87 |
|