<commit_before>/*
 * Copyright 2001-2004 The Apache Software Foundation
 *
 * Licensed 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 junit.framework.TestSuite;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id: NTFTPEntryParserTest.java,v 1.10 2004/04/16 01:52:24 scohen Exp $
 */
public class NTFTPEntryParserTest extends CompositeFTPParseTestFramework
{

    private static final String [][] goodsamples = { 
    {
            "05-26-95  10:57AM               143712 $LDR$",
            "05-20-97  03:31PM                  681 .bash_history",
            "12-05-96  05:03PM       <DIR>          absoft2",
            "11-14-97  04:21PM                  953 AUDITOR3.INI",
            "05-22-97  08:08AM                  828 AUTOEXEC.BAK",
			"01-22-98  01:52PM                  795 AUTOEXEC.BAT",
			"05-13-97  01:46PM                  828 AUTOEXEC.DOS",
			"12-03-96  06:38AM                  403 AUTOTOOL.LOG",
			"12-03-96  06:38AM       <DIR>          123xyz",
			"01-20-97  03:48PM       <DIR>          bin",
	},
	{
			"-rw-r--r--   1 root     root       111325 Apr 27  2001 zxJDBC-2.0.1b1.tar.gz", 
			"-rw-r--r--   1 root     root       190144 Apr 27  2001 zxJDBC-2.0.1b1.zip",
			"-rwxr-xr-x   2 500      500           166 Nov  2  2001 73131-testtes1.afp",
			"-rw-r--r--   1 500      500           166 Nov  9  2001 73131-testtes1.AFP",
    	}
    };
    
    private static final String[][] badsamples =
        {
            {
                "05-26-1995  10:57AM               143712 $LDR$",
                "20-05-97  03:31PM                  681 .bash_history",
				"drwxr-xr-x   2 root     99           4096 Feb 23 30:01 zzplayer",
				"12-05-96  17:03         <DIR>          absoft2",
                "05-22-97  08:08                    828 AUTOEXEC.BAK",
                "     0           DIR   05-19-97   12:56  local",
                "     0           DIR   05-12-97   16:52  Maintenance Desktop",
            },
            {
                "05-26-1995  10:57AM               143712 $LDR$",
                "20-05-97  03:31PM                  681 .bash_history",
                "drwxr-xr-x   2 root     99           4096Feb 23 30:01 zzplayer",
                "12-05-96  17:03         <DIR>          absoft2",
                "05-22-97  08:08                    828 AUTOEXEC.BAK",
                "     0           DIR   05-19-97   12:56  local",
                "     0           DIR   05-12-97   16:52  Maintenance Desktop",
            }
            };

    private static final String directoryBeginningWithNumber =
    	"12-03-96  06:38AM       <DIR>          123xyz";
	

    /**
     * @see junit.framework.TestCase#TestCase(String)
     */
    public NTFTPEntryParserTest (String name)
    {
        super(name);
    }

    /**
     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings()
     */
    protected String[][] getGoodListings()
    {
        return goodsamples;
    }
    
    /**
     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings()
     */
    protected String[][] getBadListings()
    {
        return badsamples;
    }

    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
     */
    protected FTPFileEntryParser getParser()
    {
		return new CompositeFileEntryParser(new FTPFileEntryParser[]
		{
			new NTFTPEntryParser(),
			new UnixFTPEntryParser()
		});
    }
    
    /**
     * Method suite.
     *
     * @return TestSuite
     */
    public static TestSuite suite()
    {
        return(new TestSuite(NTFTPEntryParserTest.class));
    }
    
    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
     */
    public void testParseFieldsOnDirectory() throws Exception
    {
        FTPFile dir = getParser().parseFTPEntry("12-05-96  05:03PM       <DIR>          absoft2");
        assertNotNull("Could not parse entry.", dir);
        assertEquals("Thu Dec 05 17:03:00 1996", 
                     df.format(dir.getTimestamp().getTime()));
        assertTrue("Should have been a directory.", 
                   dir.isDirectory());
        assertEquals("absoft2", dir.getName());
        assertEquals(0, dir.getSize());       
    }

    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
     */
    public void testParseFieldsOnFile() throws Exception
    {
        FTPFile f = getParser().parseFTPEntry("05-22-97  12:08AM                  828 AUTOEXEC.BAK");
        assertNotNull("Could not parse entry.", f);<commit_msg>added test code to test problem in bug 28406 PR: 28406<commit_after>/*
 * Copyright 2001-2004 The Apache Software Foundation
 *
 * Licensed 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 junit.framework.TestSuite;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id: NTFTPEntryParserTest.java,v 1.11 2004/04/16 02:08:00 scohen Exp $
 */
public class NTFTPEntryParserTest extends CompositeFTPParseTestFramework
{

    private static final String [][] goodsamples = { 
    {
            "05-26-95  10:57AM               143712 $LDR$",
            "05-20-97  03:31PM                  681 .bash_history",
            "12-05-96  05:03PM       <DIR>          absoft2",
            "11-14-97  04:21PM                  953 AUDITOR3.INI",
            "05-22-97  08:08AM                  828 AUTOEXEC.BAK",
			"01-22-98  01:52PM                  795 AUTOEXEC.BAT",
			"05-13-97  01:46PM                  828 AUTOEXEC.DOS",
			"12-03-96  06:38AM                  403 AUTOTOOL.LOG",
			"12-03-96  06:38AM       <DIR>          123xyz",
			"01-20-97  03:48PM       <DIR>          bin",
	},
	{
			"-rw-r--r--   1 root     root       111325 Apr 27  2001 zxJDBC-2.0.1b1.tar.gz", 
			"-rw-r--r--   1 root     root       190144 Apr 27  2001 zxJDBC-2.0.1b1.zip",
			"-rwxr-xr-x   2 500      500           166 Nov  2  2001 73131-testtes1.afp",
			"-rw-r--r--   1 500      500           166 Nov  9  2001 73131-testtes1.AFP",
    	}
    };
    
    private static final String[][] badsamples =
        {
            {
                "05-26-1995  10:57AM               143712 $LDR$",
                "20-05-97  03:31PM                  681 .bash_history",
				"drwxr-xr-x   2 root     99           4096 Feb 23 30:01 zzplayer",
				"12-05-96  17:03         <DIR>          absoft2",
                "05-22-97  08:08                    828 AUTOEXEC.BAK",
                "     0           DIR   05-19-97   12:56  local",
                "     0           DIR   05-12-97   16:52  Maintenance Desktop",
            },
            {
                "05-26-1995  10:57AM               143712 $LDR$",
                "20-05-97  03:31PM                  681 .bash_history",
                "drwxr-xr-x   2 root     99           4096Feb 23 30:01 zzplayer",
                "12-05-96  17:03         <DIR>          absoft2",
                "05-22-97  08:08                    828 AUTOEXEC.BAK",
                "     0           DIR   05-19-97   12:56  local",
                "     0           DIR   05-12-97   16:52  Maintenance Desktop",
            }
            };

    private static final String directoryBeginningWithNumber =
    	"12-03-96  06:38AM       <DIR>          123xyz";
	

    /**
     * @see junit.framework.TestCase#TestCase(String)
     */
    public NTFTPEntryParserTest (String name)
    {
        super(name);
    }

    /**
     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings()
     */
    protected String[][] getGoodListings()
    {
        return goodsamples;
    }
    
    /**
     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings()
     */
    protected String[][] getBadListings()
    {
        return badsamples;
    }

    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
     */
    protected FTPFileEntryParser getParser()
    {
		return new CompositeFileEntryParser(new FTPFileEntryParser[]
		{
			new NTFTPEntryParser(),
			new UnixFTPEntryParser()
		});
    }
    
    /**
     * Method suite.
     *
     * @return TestSuite
     */
    public static TestSuite suite()
    {
        return(new TestSuite(NTFTPEntryParserTest.class));
    }
    
    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
     */
    public void testParseFieldsOnDirectory() throws Exception
    {
        FTPFile dir = getParser().parseFTPEntry("12-05-96  05:03PM       <DIR>          absoft2");
        assertNotNull("Could not parse entry.", dir);
        assertEquals("Thu Dec 05 17:03:00 1996", 
                     df.format(dir.getTimestamp().getTime()));
        assertTrue("Should have been a directory.", 
                   dir.isDirectory());
        assertEquals("absoft2", dir.getName());
        assertEquals(0, dir.getSize());
        
        dir = getParser().parseFTPEntry("12-03-96  06:38AM       <DIR>          123456");
        assertNotNull("Could not parse entry.", dir);
        assertTrue("Should have been a directory.", 
        		dir.isDirectory());
        assertEquals("123456", dir.getName());
        assertEquals(0, dir.getSize());
        
    }

    /**
     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
     */
    public void testParseFieldsOnFile() throws Exception
    {
        FTPFile f = getParser().parseFTPEntry("05-22-97  12:08AM                  828 AUTOEXEC.BAK");
        assertNotNull("Could not parse entry.", f);
{'fraction_non_alphanumeric': 0.11368653421633554, 'fraction_numerical': 0.08857615894039735, 'mean_word_length': 1.683366238894373, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5034725', 'n_tokens_mistral': 4080, 'n_tokens_neox': 3381, 'n_words': 771}