Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 4891 invoked from network); 29 May 2005 20:22:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 May 2005 20:22:58 -0000 Received: (qmail 68434 invoked by uid 500); 29 May 2005 20:22:54 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 68384 invoked by uid 500); 29 May 2005 20:22:53 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 68370 invoked by uid 99); 29 May 2005 20:22:53 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from smtpout03-04.mesa1.secureserver.net (HELO smtpout03-04.mesa1.secureserver.net) (64.202.165.74) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 29 May 2005 13:22:52 -0700 Received: (qmail 10522 invoked from network); 29 May 2005 20:22:49 -0000 Received: from unknown (24.13.84.182) by smtpout03-04.mesa1.secureserver.net (64.202.165.74) with ESMTP; 29 May 2005 20:22:49 -0000 Message-ID: <429A2498.9000704@javactivity.org> Date: Sun, 29 May 2005 15:22:48 -0500 From: Steve Cohen User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ant Developers List Subject: How to write a JUnit test for this new functionality? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Neeme Praks has sent me an interesting patch that allows the task to execute with a certain number of retries specified. That is, it won't fail until the specified number of retries has passed. I want to write some JUnit tests to test this patch. My idea was to simulate failure by subclassing the FTP task class (o.a.t.a.taskdefs.optional.net.FTP) within the JUnit test with a version that allows setting a numberOfFailuresToSimulate member, and a modified transferFiles() method that would, if numberOfFailuresToSimulate > 0, simply decrement this value by 1 and throw a dummy BuildException, otherwise, simply execute the regular transferFiles. This seems like a good way to test Neeme's retry handler. Then this can be tested with a build file that specifies the number of retry times, and the test can then illustrate what happens with this buildfile when numbers >, <, or == to the specified number of simulated failures occur. To wit: private static class myRetryableFTP extends FTP { private int numberOfFailuresToSimulate; int getNumberOfFailuresToSimulate() { return numberOfFailuresToSimulate; } void setNumberOfFailuresToSimulate(int numberOfFailuresToSimulate) { this.numberOfFailuresToSimulate = numberOfFailuresToSimulate; } protected int transferFiles(FTPClient ftp, FileSet fs) throws IOException, BuildException { if (this.numberOfFailuresToSimulate > 0) { this.numberOfFailuresToSimulate--; throw new BuildException("Simulated failure for testing"); } return super.transferFiles(ftp, fs); } } However, my knowledge of Ant internals is somewhat limited. How can I tell an ant project in my test code that when it sees an tag, it should delegate the performance of this task to myRetryableFTP, instead of to the standard FTP as it would normally do? Is there an example of this sort of thing within the existing Ant test suite? --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org