1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
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 }