01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.drftpd.commands;
19:
20: import junit.framework.TestCase;
21:
22: import net.sf.drftpd.master.FtpRequest;
23:
24: import org.apache.log4j.BasicConfigurator;
25:
26: import org.drftpd.tests.DummyBaseFtpConnection;
27: import org.drftpd.tests.DummyGlobalContext;
28: import org.drftpd.tests.DummyUser;
29: import org.drftpd.tests.DummyUserManager;
30: import org.drftpd.usermanager.User;
31:
32: import java.util.ArrayList;
33:
34: /**
35: * @author mog
36: * @version $Id$
37: */
38: public class UserManagementTest extends TestCase {
39: public void testGAdmin() throws ReplyException,
40: ImproperUsageException {
41: DummyUserManager um = new DummyUserManager();
42: DummyUser u = new DummyUser("dummy", um);
43: u.toggleGroup("gadmin");
44: um.setUser(u);
45:
46: ArrayList<User> allUsers = new ArrayList<User>();
47: allUsers.add(u);
48:
49: DummyBaseFtpConnection conn = new DummyBaseFtpConnection(null);
50: DummyGlobalContext gctx = new DummyGlobalContext();
51: gctx.setUserManager(um);
52: conn.setGlobalConext(gctx);
53: conn.setUser(u.getName());
54: u.getKeyedMap().setObject(UserManagement.GROUPSLOTS,
55: ((short) 1));
56: u.setGroup("group");
57:
58: UserManagement cmdmgr = (UserManagement) new UserManagement()
59: .initialize(conn, null);
60:
61: {
62: FtpRequest req = new FtpRequest(
63: "site adduser testadd1 testpass1 *@*");
64: conn.setRequest(req);
65:
66: Reply r = cmdmgr.execute(conn);
67: assertEquals(r.toString(), r.getCode(), 200);
68: }
69:
70: {
71: FtpRequest req = new FtpRequest(
72: "site adduser testadd2 testpass2 *@*");
73: conn.setRequest(req);
74:
75: Reply r = cmdmgr.execute(conn);
76: assertEquals(r.toString(), r.getMessage(),
77: "Sorry, no more open slots available");
78: }
79: }
80:
81: protected void setUp() throws Exception {
82: BasicConfigurator.configure();
83: }
84:
85: protected void tearDown() throws Exception {
86: super.tearDown();
87: }
88: }
|