KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > net > ftp > parser > DefaultFTPFileEntryParserFactoryTest


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc {
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         // works because contains the expression "Unix"
42
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 JavaDoc root = pie.getRootCause();
81             assertTrue(root instanceof ClassCastException JavaDoc);
82         }
83     }
84 }
85
86
Popular Tags