001: /**
002: *
003: * edtFTPj
004: *
005: * Copyright (C) 2005 Enterprise Distributed Technologies Ltd
006: *
007: * www.enterprisedt.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: *
023: * Bug fixes, suggestions and comments should posted on the EDT forums at
024: * http://www.enterprisedt.com/forums/index.php
025: *
026: * Change Log:
027: *
028: * $Log: TestBigTransfer.java,v $
029: * Revision 1.2 2005/07/15 17:30:06 bruceb
030: * rework of unit testing structure
031: *
032: * Revision 1.1 2005/03/18 13:42:06 bruceb
033: * tests big files
034: *
035: * Revision 1.1 2005/01/14 18:07:37 bruceb
036: * bulk test2 TestBulkTransfer.java
037: *
038: *
039: */package com.enterprisedt.net.ftp.test;
040:
041: import java.io.File;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045:
046: import com.enterprisedt.net.ftp.FTPProgressMonitor;
047: import com.enterprisedt.net.ftp.FTPTransferType;
048:
049: /**
050: * Test get'ing and put'ing of a big file
051: *
052: * @author Bruce Blackshaw
053: * @version $Revision: 1.2 $
054: */
055: public class TestBigTransfer extends FTPTestCase {
056:
057: /**
058: * Revision control id
059: */
060: public static String cvsId = "@(#)$Id: TestBigTransfer.java,v 1.2 2005/07/15 17:30:06 bruceb Exp $";
061:
062: /**
063: * Interval between reporting progress
064: */
065: private static int PROGRESS_INTERVAL = 1048575;
066:
067: /**
068: * get name of log file
069: *
070: * @return name of file to log to
071: */
072: protected String getLogName() {
073: return "TestTransferLarge.log";
074: }
075:
076: /**
077: * Test transfering a binary file
078: */
079: public void testTransferLarge() throws Exception {
080: log.debug("TransferLarge()");
081:
082: connect();
083:
084: // move to test directory
085: ftp.chdir(testdir);
086: ftp.setType(FTPTransferType.BINARY);
087:
088: ftp.setProgressMonitor(new TestProgressMonitor(),
089: PROGRESS_INTERVAL);
090:
091: bigTransfer(localBigFile);
092:
093: ftp.quit();
094: }
095:
096: /**
097: * Transfer back and forth multiple times
098: */
099: private void bigTransfer(String bigFile) throws Exception {
100:
101: ftp.put(localDataDir + bigFile, bigFile);
102:
103: ftp.get(localDataDir + bigFile + ".copy", bigFile);
104:
105: // delete remote file
106: ftp.delete(bigFile);
107:
108: // check equality of local files
109: assertIdentical(localDataDir + bigFile + ".copy", localDataDir
110: + bigFile);
111:
112: // and delete local file
113: File local = new File(localDataDir + bigFile + ".copy");
114: local.delete();
115: }
116:
117: /**
118: * Automatic test suite construction
119: *
120: * @return suite of tests for this class
121: */
122: public static Test suite() {
123: return new TestSuite(TestBigTransfer.class);
124: }
125:
126: /**
127: * Enable our class to be run, doing the
128: * tests
129: */
130: public static void main(String[] args) {
131: junit.textui.TestRunner.run(suite());
132: }
133:
134: /**
135: * As soon it receives notification of bytes transferred, it
136: * cancels the transfer
137: */
138: class TestProgressMonitor implements FTPProgressMonitor {
139:
140: /* (non-Javadoc)
141: * @see com.enterprisedt.net.ftp.FTPProgressMonitor#bytesTransferred(long)
142: */
143: public void bytesTransferred(long bytes) {
144: log.debug(bytes + " transferred");
145: }
146: }
147:
148: }
|