1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.mpt.ant;
21
22 import junit.framework.TestCase;
23
24 import org.apache.james.mpt.DiscardProtocol;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.types.resources.Union;
27
28 public class TestAddUser extends TestCase {
29
30 private static final int PORT = 10001;
31
32 DiscardProtocol fakeServer;
33
34 DiscardProtocol.Record record;
35
36 MailProtocolTestTask subject;
37
38 protected void setUp() throws Exception {
39 super.setUp();
40 fakeServer = new DiscardProtocol(PORT);
41 fakeServer.start();
42 record = fakeServer.recordNext();
43
44 subject = new MailProtocolTestTask();
45 subject.setHost("127.0.0.1");
46 subject.setPort(PORT+1);
47 subject.add(new Union());
48 subject.setProject(new Project());
49 }
50
51 protected void tearDown() throws Exception {
52 super.tearDown();
53 fakeServer.stop();
54 }
55
56 public void testShouldExecuteScriptAgainstPort() throws Exception {
57 MailProtocolTestTask.AddUser user = subject.createAddUser();
58 user.setPort(PORT);
59 user.setPasswd("PASSWORD");
60 user.setUser("USER");
61 final String script = "This script adds a user";
62 user.addText("C: " + script);
63 subject.execute();
64 assertEquals(script + "\r\n", record.complete());
65 }
66 }