KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > slaveselection > filter > MinfreespaceFilterTest


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 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.slaveselection.filter;
19
20 import java.util.Arrays JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27 import net.sf.drftpd.Bytes;
28 import net.sf.drftpd.NoAvailableSlaveException;
29 import net.sf.drftpd.ObjectNotFoundException;
30 import net.sf.drftpd.master.RemoteSlave;
31 import net.sf.drftpd.slave.SlaveStatus;
32 import net.sf.drftpd.slave.Transfer;
33
34 /**
35  * @author mog
36  * @version $Id: MinfreespaceFilterTest.java,v 1.5 2004/03/04 01:41:27 zubov Exp $
37  */

38 public class MinfreespaceFilterTest extends TestCase {
39     public static class RemoteSlaveTesting extends RemoteSlave {
40         private SlaveStatus _status;
41
42         public RemoteSlaveTesting(String JavaDoc name, Collection JavaDoc masks, SlaveStatus status) {
43             super(name, masks);
44             _status = status;
45         }
46         
47         public SlaveStatus getStatus() {
48             return _status;
49         }
50     }
51
52     public MinfreespaceFilterTest(String JavaDoc fName) {
53         super(fName);
54     }
55     
56     public static TestSuite suite() {
57         return new TestSuite(MinfreespaceFilterTest.class);
58     }
59     
60     public void testSimple() throws ObjectNotFoundException, NoAvailableSlaveException {
61         Properties JavaDoc p = new Properties JavaDoc();
62         p.put("1.multiplier", "1");
63         p.put("1.minfreespace", "100MB");
64
65         SlaveStatus s = new SlaveStatus(Bytes.parseBytes("50MB"), Bytes.parseBytes("100GB"), 0, 0, 0, 0, 0,0);
66         RemoteSlave rslaves[] =
67             { new RemoteSlaveTesting("slave1", Collections.EMPTY_LIST, s)};
68         ScoreChart sc = new ScoreChart(Arrays.asList(rslaves));
69
70
71         Filter f = new MinfreespaceFilter(null, 1, p);
72         f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, null);
73
74         assertEquals(Bytes.parseBytes("-50MB"), sc.getSlaveScore(rslaves[0]).getScore());
75     }
76 }
77
Popular Tags