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