FileDocCategorySizeDatePackage
ListingFunctionalTest.javaAPI DocApache Commons NET 1.4.1 API9455Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.ftp

ListingFunctionalTest

public class ListingFunctionalTest extends TestCase
A functional test suite for checking that site listings work.
author
Jeffrey D. Brekke
version
$Id: ListingFunctionalTest.java 167953 2005-05-03 18:29:42Z dfs $

Fields Summary
static final int
HOSTNAME
static final int
INVALID_PARSERKEY
static final int
INVALID_PATH
static final int
VALID_FILENAME
static final int
VALID_PARSERKEY
static final int
VALID_PATH
private FTPClient
client
private String
hostName
private String
invalidParserKey
private String
invalidPath
private String
validFilename
private String
validParserKey
private String
validPath
Constructors Summary
public ListingFunctionalTest(String arg0, String[] settings)
Constructor for FTPClientTest.

param
arg0

        super(arg0);
        invalidParserKey = settings[INVALID_PARSERKEY];
        validParserKey = settings[VALID_PARSERKEY];
        invalidPath = settings[INVALID_PATH];
        validFilename = settings[VALID_FILENAME];
        validPath = settings[VALID_PATH];
        hostName = settings[HOSTNAME];
    
Methods Summary
private booleanfindByName(java.util.List fileList, java.lang.String string)

param
fileList
param
string
return

        boolean found = false;
        Iterator iter = fileList.iterator();

        while (iter.hasNext() && !found)
        {
            Object element = iter.next();

            if (element instanceof FTPFile)
            {
                FTPFile file = (FTPFile) element;

                found = file.getName().equals(string);
            }
            else
            {
                String filename = (String) element;

                found = filename.endsWith(string);
            }
        }

        return found;
    
protected voidsetUp()

        super.setUp();
        client = new FTPClient();
        client.connect(hostName);
        client.login("anonymous", "anonymous");
        client.enterLocalPassiveMode();
    
public static final junit.framework.Testsuite()


        
    
        String[][] testData =
            {
                {
                    "ftp.ibiblio.org", "unix", "vms",
                    "HA!", "javaio.jar",
                    "pub/languages/java/javafaq"
                },
                {
                    "ftp.wacom.com", "windows", "VMS", "HA!",
                    "wacom97.zip", "pub\\ftp\\drivers"
                },
                {
                    "h71000.www7.hp.com", "vms", "windows",
                    "[.HA!]", "ACLOCAL.M4;1",

                    "[.FREEWARE50.XTERM]"
                }
            };
        Class clasz = ListingFunctionalTest.class;
        Method[] methods = clasz.getDeclaredMethods();
        TestSuite allSuites = new TestSuite("FTP Listing Functional Test Suite");

        for (int i = 0; i < testData.length; i++)
        {
            TestSuite suite = new TestSuite(testData[i][VALID_PARSERKEY]);

            for (int j = 0; j < methods.length; j++)
            {
                Method method = methods[j];

                if (method.getName().startsWith("test"))
                {
                    suite.addTest(new ListingFunctionalTest(
                                                            method.getName(),
                                                            testData[i]));
                }
            }

            allSuites.addTest(suite);
        }

        return allSuites;
    
protected voidtearDown()

        try
        {
            client.logout();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        if (client.isConnected())
        {
            client.disconnect();
        }

        client = null;
        super.tearDown();
    
public voidtestInitiateListParsing()

        client.changeWorkingDirectory(validPath);

        FTPListParseEngine engine = client.initiateListParsing();
        List files = Arrays.asList(engine.getNext(25));

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestInitiateListParsingWithPath()

        FTPListParseEngine engine = client.initiateListParsing(validParserKey,
                                                               validPath);
        List files = Arrays.asList(engine.getNext(25));

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestInitiateListParsingWithPathAndAutodetection()

        FTPListParseEngine engine = client.initiateListParsing(validPath);
        List files = Arrays.asList(engine.getNext(25));

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestInitiateListParsingWithPathAndAutodetectionButEmpty()

        FTPListParseEngine engine = client.initiateListParsing(invalidPath);

        assertFalse(engine.hasNext());
    
public voidtestInitiateListParsingWithPathAndIncorrectParser()

        FTPListParseEngine engine = client.initiateListParsing(invalidParserKey,
                                                               invalidPath);

        assertFalse(engine.hasNext());
    
public voidtestListFiles()

        FTPClientConfig config = new FTPClientConfig(validParserKey);
        client.configure(config);
        List files = Arrays.asList(client.listFiles(validPath));

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestListFilesWithAutodection()

        client.changeWorkingDirectory(validPath);

        List files = Arrays.asList(client.listFiles());

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestListFilesWithIncorrectParser()

        FTPClientConfig config = new FTPClientConfig(invalidParserKey);
        client.configure(config);

        FTPFile[] files = client.listFiles(validPath);

        assertEquals(0, files.length);
    
public voidtestListFilesWithPathAndAutodectionButEmpty()

        FTPFile[] files = client.listFiles(invalidPath);

        assertEquals(0, files.length);
    
public voidtestListFilesWithPathAndAutodetection()

        List files = Arrays.asList(client.listFiles(validPath));

        assertTrue(files.toString(),
                   findByName(files, validFilename));
    
public voidtestListNames()

        client.changeWorkingDirectory(validPath);

        String[] names = client.listNames();

        assertNotNull(names);

        List lnames = Arrays.asList(names);

        assertTrue(lnames.toString(),
                   lnames.contains(validFilename));
    
public voidtestListNamesWithPath()

        List names = Arrays.asList(client.listNames(validPath));

        assertTrue(names.toString(),
                   findByName(names, validFilename));
    
public voidtestListNamesWithPathButEmpty()

        String[] names = client.listNames(invalidPath);

        assertNull(names);