Methods Summary |
---|
public void | addCleanup(java.io.File file)
cleanUpList.add( file );
|
private void | compareFiles(java.io.File src, java.io.File dest)
FilesMatch match = new FilesMatch();
match.setFile1( src );
match.setFile2( dest );
assertTrue( "Assert files are equal.", match.eval() );
|
private Scp | createTask()
Scp scp = new Scp();
Project p = new Project();
p.init();
scp.setProject( p );
if( knownHosts != null ) {
scp.setKnownhosts( knownHosts );
} else {
scp.setTrust( true );
}
scp.setPort( port );
return scp;
|
private java.io.File | createTemporaryFile()
File uploadFile;
uploadFile = File.createTempFile( "scp", "test", tempDir );
FileWriter writer = new FileWriter( uploadFile );
writer.write("Can you hear me now?\n");
writer.close();
addCleanup( uploadFile );
return uploadFile;
|
protected void | setUp()
cleanUpList.clear();
|
protected void | tearDown()
for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) {
File file = (File) i.next();
file.delete();
}
|
public void | testMultiUploadAndDownload()
List uploadList = new ArrayList();
for( int i = 0; i < 5; i++ ) {
uploadList.add( createTemporaryFile() );
}
Scp scp = createTask();
FilenameSelector selector = new FilenameSelector();
selector.setName( "scp*" );
FileSet fileset = new FileSet();
fileset.setDir( tempDir );
fileset.addFilename( selector );
scp.addFileset( fileset );
scp.setTodir( sshHostUri );
scp.execute();
File multi = new File( tempDir, "multi" );
multi.mkdir();
addCleanup( multi );
Scp scp2 = createTask();
scp2.setFile( sshHostUri + "/scp*" );
scp2.setTodir( multi.getPath() );
scp2.execute();
FilesMatch match = new FilesMatch();
for( Iterator i = uploadList.iterator(); i.hasNext(); ) {
File f = (File)i.next();
match.setFile1( f );
File f2 = new File( multi, f.getName() );
match.setFile2( f2 );
assertTrue("Assert file '" + f.getPath() + "' and file '" +
f2.getPath() + "'", match.eval() );
}
|
public void | testSingleFileUploadAndDownload()
File uploadFile = createTemporaryFile();
Scp scpTask = createTask();
scpTask.setFile( uploadFile.getPath() );
scpTask.setTodir( sshHostUri );
scpTask.execute();
File testFile = new File( tempDir.getPath() + File.separator +
"download-testSingleFileUploadAndDownload.test" );
addCleanup( testFile );
assertTrue( "Assert that the testFile does not exist.",
!testFile.exists() );
scpTask.setFile( sshHostUri + "/" + uploadFile.getName() );
scpTask.setTodir( testFile.getPath() );
scpTask.execute();
assertTrue( "Assert that the testFile exists.", testFile.exists() );
compareFiles( uploadFile, testFile );
|