alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons Net example source code file (CompositeFTPParseTestFramework.java)

This example Commons Net source code file (CompositeFTPParseTestFramework.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons Net tags/keywords

compositeftpparsetestframework, exception, failed, failed, ftpfile, ftpfile, ftpfileentryparser, ftpfileentryparser, ftpparsetestframework, override, should, string, string

The Commons Net CompositeFTPParseTestFramework.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.net.ftp.parser;

import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;

/**
 * @author <a href="mario@ops.co.at">MarioIvankovits
 * @version $Id: CompositeFTPParseTestFramework.java 155429 2005-02-26 13:13:04Z dirkv $
 */
public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
{
    /**
     * @see junit.framework.TestCase#TestCase(String)
     */
    public CompositeFTPParseTestFramework(String name)
    {
        super(name);
    }

    /**
     * @see FTPParseTestFramework#getGoodListing()
     */
    @Override
    protected String[] getGoodListing()
    {
        return (getGoodListings()[0]);
    }

    /**
     * Method getBadListing.
     * Implementors must provide multiple listing that contains failures and
     * must force the composite parser to switch the FtpEntryParser
     *
     * @return String[]
     */
    protected abstract String[][] getBadListings();

    /**
     * Method getGoodListing.
     * Implementors must provide multiple listing that passes and
     * must force the composite parser to switch the FtpEntryParser
     *
     * @return String[]
     */
    protected abstract String[][] getGoodListings();

    /**
     * @see FTPParseTestFramework#getBadListing()
     */
    @Override
    protected String[] getBadListing()
    {
        return (getBadListings()[0]);
    }

    /* (non-Javadoc)
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
     */
    public void testConsistentListing() throws Exception
    {
        String goodsamples[][] = getGoodListings();

        for (int i = 0; i < goodsamples.length; i++)
        {
            FTPFileEntryParser parser = getParser();
            for (int j = 0; j < goodsamples[i].length; j++)
            {
                String test = goodsamples[i][j];
                FTPFile f = parser.parseFTPEntry(test);
                assertNotNull("Failed to parse " + test,
                        f);

                doAdditionalGoodTests(test, f);
            }
        }
    }

    /* (non-Javadoc)
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
     */
    @Override
    public void testBadListing() throws Exception
    {
        String badsamples[][] = getBadListings();

        for (int i = 0; i < badsamples.length; i++)
        {
            FTPFileEntryParser parser = getParser();
            for (int j = 0; j < badsamples[i].length; j++)
            {
                String test = badsamples[i][j];
                FTPFile f = parser.parseFTPEntry(test);
                assertNull("Should have Failed to parse " + test,
                        nullFileOrNullDate(f));

                doAdditionalBadTests(test, f);
            }
        }
    }

    // even though all these listings are good using one parser
    // or the other, this tests that a parser that has succeeded
    // on one format will fail if another format is substituted.
    public void testInconsistentListing() throws Exception
    {
        String goodsamples[][] = getGoodListings();

        FTPFileEntryParser parser = getParser();

        for (int i = 0; i < goodsamples.length; i++)
        {
            String test = goodsamples[i][0];
            FTPFile f = parser.parseFTPEntry(test);

            switch (i)
            {
            case 0:
                assertNotNull("Failed to parse " + test, f);
                break;
            case 1:
                assertNull("Should have failed to parse " + test, f);
                break;
            }
        }
    }
}

Other Commons Net examples (source code examples)

Here is a short list of links related to this Commons Net CompositeFTPParseTestFramework.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.