1 16 package org.apache.commons.net.ftp.parser; 17 import junit.framework.TestCase; 18 19 import org.apache.commons.net.ftp.FTPFileEntryParser; 20 21 22 public class DefaultFTPFileEntryParserFactoryTest extends TestCase 23 { 24 public void testDefaultParserFactory() throws Exception { 25 DefaultFTPFileEntryParserFactory factory = 26 new DefaultFTPFileEntryParserFactory(); 27 28 FTPFileEntryParser parser = factory.createFileEntryParser("unix"); 29 assertTrue(parser instanceof UnixFTPEntryParser); 30 31 parser = factory.createFileEntryParser("UNIX"); 32 assertTrue(parser instanceof UnixFTPEntryParser); 33 34 parser = factory.createFileEntryParser("Unix"); 35 assertTrue(parser instanceof UnixFTPEntryParser); 36 37 parser = factory.createFileEntryParser("EnterpriseUnix"); 38 assertTrue(parser instanceof UnixFTPEntryParser); 39 assertFalse(parser instanceof EnterpriseUnixFTPEntryParser); 40 41 parser = factory.createFileEntryParser("UnixFTPEntryParser"); 43 assertTrue(parser instanceof UnixFTPEntryParser); 44 45 try { 46 parser = factory.createFileEntryParser("NT"); 47 fail("Exception should have been thrown. \"NT\" is not a recognized key"); 48 } catch (ParserInitializationException pie) { 49 assertNull(pie.getRootCause()); 50 } 51 52 parser = factory.createFileEntryParser("WindowsNT"); 53 assertTrue(parser instanceof CompositeFileEntryParser); 54 55 parser = factory.createFileEntryParser("ThigaVMSaMaJig"); 56 assertTrue(parser instanceof VMSFTPEntryParser); 57 58 parser = factory.createFileEntryParser("OS/2"); 59 assertTrue(parser instanceof OS2FTPEntryParser); 60 61 parser = factory.createFileEntryParser("OS/400"); 62 assertTrue(parser instanceof CompositeFileEntryParser); 63 64 try { 65 parser = factory.createFileEntryParser("OS2FTPFileEntryParser"); 66 fail("Exception should have been thrown. \"OS2FTPFileEntryParser\" is not a recognized key"); 67 } catch (ParserInitializationException pie) { 68 assertNull(pie.getRootCause()); 69 } 70 71 parser = factory.createFileEntryParser( 72 "org.apache.commons.net.ftp.parser.OS2FTPEntryParser"); 73 assertTrue(parser instanceof OS2FTPEntryParser); 74 75 try { 76 parser = factory.createFileEntryParser( 77 "org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory"); 78 fail("Exception should have been thrown. \"DefaultFTPFileEntryParserFactory\" does not implement FTPFileEntryParser"); 79 } catch (ParserInitializationException pie) { 80 Throwable root = pie.getRootCause(); 81 assertTrue(root instanceof ClassCastException ); 82 } 83 } 84 } 85 86 | Popular Tags |