001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.commands;
019:
020: import junit.framework.TestCase;
021:
022: import net.sf.drftpd.master.FtpRequest;
023: import net.sf.drftpd.master.SlaveFileException;
024:
025: import org.drftpd.remotefile.LinkedRemoteFile;
026: import org.drftpd.remotefile.LinkedRemoteFileInterface;
027: import org.drftpd.remotefile.MLSTSerialize;
028: import org.drftpd.remotefile.StaticRemoteFile;
029: import org.drftpd.sections.def.SectionManager;
030:
031: import org.drftpd.tests.DummyBaseFtpConnection;
032: import org.drftpd.tests.DummyConnectionManager;
033: import org.drftpd.tests.DummyFtpConfig;
034: import org.drftpd.tests.DummyGlobalContext;
035: import org.drftpd.tests.DummyRemoteSlave;
036: import org.drftpd.tests.DummySlaveManager;
037: import org.drftpd.tests.DummyUser;
038: import org.drftpd.tests.DummyUserManager;
039:
040: import java.io.FileNotFoundException;
041: import java.io.PrintWriter;
042:
043: import java.rmi.RemoteException;
044:
045: import java.util.Collections;
046: import java.util.Iterator;
047: import java.util.List;
048:
049: /**
050: * @author mog
051: * @version $Id: PreTest.java 874 2004-12-23 17:43:28Z mog $
052: */
053: public class PreTest extends TestCase {
054: private DummyConnectionManager _cm;
055: private DummyFtpConfig _config;
056: private LinkedRemoteFile _root;
057: private List _rslave;
058:
059: public PreTest(String fName) {
060: super (fName);
061: }
062:
063: private void buildRoot() throws FileNotFoundException {
064: assertNotNull(_config);
065: _rslave = Collections.singletonList(new DummyRemoteSlave(
066: "test", null));
067: _root = new LinkedRemoteFile(_config);
068:
069: _root.addFile(new StaticRemoteFile(null, "release", "owner",
070: "group", 0));
071:
072: LinkedRemoteFileInterface masterdir = _root.getFile("release");
073: masterdir.addFile(new StaticRemoteFile(_rslave, "file1",
074: "owner", "group", 1000));
075:
076: //_section = _root.addFile(new StaticRemoteFile(null, "section",
077: // "drftpd", "drftpd", 0));
078: }
079:
080: private void checkOwnershipRecursive(LinkedRemoteFileInterface dir) {
081: for (Iterator iter = dir.getFiles().iterator(); iter.hasNext();) {
082: LinkedRemoteFileInterface file = (LinkedRemoteFileInterface) iter
083: .next();
084: assertEquals(file.getUsername(), "drftpd");
085:
086: if (file.isDirectory()) {
087: checkOwnershipRecursive(file);
088: }
089: }
090: }
091:
092: public void testOwnership() throws UnhandledCommandException,
093: FileNotFoundException, RemoteException {
094: DummyGlobalContext gctx = new DummyGlobalContext();
095:
096: _config = new DummyFtpConfig();
097: gctx.setFtpConfig(_config);
098: _config.setGlobalContext(gctx);
099:
100: buildRoot();
101: gctx.setRoot(_root);
102:
103: Pre pre = new Pre();
104: DummyBaseFtpConnection conn = new DummyBaseFtpConnection(null);
105: pre.initialize(conn, null);
106: conn.setCurrentDirectory(_root);
107: conn.setRequest(new FtpRequest("SITE PRE release section"));
108: _cm = new DummyConnectionManager();
109: _cm.setGlobalContext(gctx);
110: gctx.setConnectionManager(_cm);
111: conn.setGlobalConext(gctx);
112:
113: SectionManager sm = new SectionManager(_cm);
114: gctx.setSectionManager(sm);
115:
116: DummyUserManager um = new DummyUserManager();
117: um.setUser(new DummyUser("owner"));
118: gctx.setUserManager(um);
119:
120: DummySlaveManager slavem = null;
121:
122: try {
123: slavem = new DummySlaveManager();
124: } catch (SlaveFileException e) {
125: }
126:
127: slavem.setSlaves(Collections.EMPTY_LIST);
128: gctx.setSlaveManager(slavem);
129:
130: Reply reply;
131: reply = pre.execute(conn);
132: //MLSTSerialize.serialize(_root, new PrintWriter(System.err, true));
133: assertEquals(reply.getCode(), 200);
134: }
135: }
|