You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2004/02/17 06:14:02 UTC
cvs commit: jakarta-commons/net/src/test/org/apache/commons/net/ftp ListingFunctionalTest.java
brekke 2004/02/16 21:14:02
Modified: net build.xml maven.xml project.xml
Added: net/src/test/org/apache/commons/net/ftp
ListingFunctionalTest.java
Log:
Added a functional test that is data driven to check public ftp sites on the
internet. It is currently skipped on the build tests along with any test whose
name ends in *FunctionalTest.java so I added a custom goal to maven.xml to run
these functional tests.
maven test:functional
will run them. For some reason the results are printed twice, must be a bug
in maven. I also regenerated the ant build.xml to exclude *FunctionalTest.java
classes.
The test suite has a windows, unix, and a commented out vms public ftp server
which is checked. The vms one I'm having trouble with. The other's pass.
Revision Changes Path
1.21 +2 -2 jakarta-commons/net/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/net/build.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- build.xml 6 Jan 2004 04:26:12 -0000 1.20
+++ build.xml 17 Feb 2004 05:14:02 -0000 1.21
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--build.xml generated by maven from project.xml version 1.2.0-dev
- on date January 5 2004, time 2208-->
+ on date February 16 2004, time 2310-->
<project default="jar" name="commons-net" basedir=".">
<property name="defaulttargetdir" value="target">
@@ -92,7 +92,7 @@
<fileset dir="src/test">
<include name="**/*Test.java">
</include>
- <exclude name="**/TelnetClientFunctionalTest.java">
+ <exclude name="**/*FunctionalTest.java">
</exclude>
</fileset>
</batchtest>
1.2 +5 -2 jakarta-commons/net/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/net/maven.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven.xml 17 Jul 2002 08:04:50 -0000 1.1
+++ maven.xml 17 Feb 2004 05:14:02 -0000 1.2
@@ -1,5 +1,8 @@
-<project default="java:jar" xmlns:j="jelly:core">
+<project default="jar:jar" xmlns:j="jelly:core">
- <!-- we can customize the Maven build here -->
+ <goal name="test:functional">
+ <j:set var="testmatch" value="*FunctionalTest"/>
+ <attainGoal name="test:match"/>
+ </goal>
</project>
1.38 +1 -1 jakarta-commons/net/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/net/project.xml,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- project.xml 5 Jan 2004 16:17:27 -0000 1.37
+++ project.xml 17 Feb 2004 05:14:02 -0000 1.38
@@ -136,7 +136,7 @@
<include>**/*Test.java</include>
</includes>
<excludes>
- <exclude>**/TelnetClientFunctionalTest.java</exclude>
+ <exclude>**/*FunctionalTest.java</exclude>
</excludes>
</unitTest>
1.1 jakarta-commons/net/src/test/org/apache/commons/net/ftp/ListingFunctionalTest.java
Index: ListingFunctionalTest.java
===================================================================
package org.apache.commons.net.ftp;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Commons" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* A functional test suite for checking that site listings work.
* @author <a href="mailto:brekke@apache.org">Jeffrey D. Brekke</a>
* @version $Id: ListingFunctionalTest.java,v 1.1 2004/02/17 05:14:02 brekke Exp $
*/
public class ListingFunctionalTest extends TestCase
{
static final int HOSTNAME = 0;
static final int INVALID_PARSERKEY = 2;
static final int INVALID_PATH = 3;
static final int VALID_FILENAME = 4;
static final int VALID_PARSERKEY = 1;
static final int VALID_PATH = 5;
public static final Test suite()
{
String[][] testData =
{
{
"ftp.ibiblio.org", "unix", "windows",
"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!]", "XTERM.EXE;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;
}
private FTPClient client;
private String hostName;
private String invalidParserKey;
private String invalidPath;
private String validFilename;
private String validParserKey;
private String validPath;
/**
* Constructor for FTPClientTest.
*
* @param arg0
*/
public ListingFunctionalTest(String arg0,
String[] settings)
{
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];
}
/**
* @param fileList
* @param string
*
* @return
*/
private boolean findByName(List fileList,
String string)
{
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;
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
client = new FTPClient();
client.connect(hostName);
client.login("anonymous", "anonymous");
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown()
throws Exception
{
try
{
client.logout();
}
catch (IOException e)
{
e.printStackTrace();
}
if (client.isConnected())
{
client.disconnect();
}
client = null;
super.tearDown();
}
/*
* Test for FTPListParseEngine initiateListParsing()
*/
public void testInitiateListParsing()
throws IOException
{
client.changeWorkingDirectory(validPath);
FTPListParseEngine engine = client.initiateListParsing();
List files = Arrays.asList(engine.getNext(25));
assertTrue(files.toString(),
findByName(files, validFilename));
}
/*
* Test for FTPListParseEngine initiateListParsing(String, String)
*/
public void testInitiateListParsingWithPath()
throws IOException
{
FTPListParseEngine engine = client.initiateListParsing(validParserKey,
validPath);
List files = Arrays.asList(engine.getNext(25));
assertTrue(files.toString(),
findByName(files, validFilename));
}
/*
* Test for FTPListParseEngine initiateListParsing(String)
*/
public void testInitiateListParsingWithPathAndAutodetection()
throws IOException
{
FTPListParseEngine engine = client.initiateListParsing(validPath);
List files = Arrays.asList(engine.getNext(25));
assertTrue(files.toString(),
findByName(files, validFilename));
}
/*
* Test for FTPListParseEngine initiateListParsing(String)
*/
public void testInitiateListParsingWithPathAndAutodetectionButEmpty()
throws IOException
{
FTPListParseEngine engine = client.initiateListParsing(invalidPath);
assertFalse(engine.hasNext());
}
/*
* Test for FTPListParseEngine initiateListParsing(String, String)
*/
public void testInitiateListParsingWithPathAndIncorrectParser()
throws IOException
{
FTPListParseEngine engine = client.initiateListParsing(invalidParserKey,
invalidPath);
assertFalse(engine.hasNext());
}
/*
* Test for FTPFile[] listFiles(String, String)
*/
public void testListFiles()
throws IOException
{
List files = Arrays.asList(client.listFiles(validParserKey, validPath));
assertTrue(files.toString(),
findByName(files, validFilename));
}
public void testListFilesWithAutodection()
throws IOException
{
client.changeWorkingDirectory(validPath);
List files = Arrays.asList(client.listFiles());
assertTrue(files.toString(),
findByName(files, validFilename));
}
/*
* Test for FTPFile[] listFiles(String, String)
*/
public void testListFilesWithIncorrectParser()
throws IOException
{
FTPFile[] files = client.listFiles(invalidParserKey, validPath);
assertEquals(0, files.length);
}
/*
* Test for FTPFile[] listFiles(String)
*/
public void testListFilesWithPathAndAutodectionButEmpty()
throws IOException
{
FTPFile[] files = client.listFiles(invalidPath);
assertEquals(0, files.length);
}
/*
* Test for FTPFile[] listFiles(String)
*/
public void testListFilesWithPathAndAutodetection()
throws IOException
{
List files = Arrays.asList(client.listFiles(validPath));
assertTrue(files.toString(),
findByName(files, validFilename));
}
/*
* Test for String[] listNames()
*/
public void testListNames()
throws IOException
{
client.changeWorkingDirectory(validPath);
String[] names = client.listNames();
assertNotNull(names);
List lnames = Arrays.asList(names);
assertTrue(lnames.toString(),
lnames.contains(validFilename));
}
/*
* Test for String[] listNames(String)
*/
public void testListNamesWithPath()
throws IOException
{
List names = Arrays.asList(client.listNames(validPath));
assertTrue(names.toString(),
findByName(names, validFilename));
}
public void testListNamesWithPathButEmpty()
throws IOException
{
String[] names = client.listNames(invalidPath);
assertNull(names);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org