01: /*
02: * Copyright 2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
18: import junit.framework.TestCase;
19:
20: import org.apache.commons.net.ftp.FTPFileEntryParser;
21:
22: public class DefaultFTPFileEntryParserFactoryTest extends TestCase {
23: public void testDefaultParserFactory() throws Exception {
24: DefaultFTPFileEntryParserFactory factory = new DefaultFTPFileEntryParserFactory();
25:
26: FTPFileEntryParser parser = factory
27: .createFileEntryParser("unix");
28: assertTrue(parser instanceof UnixFTPEntryParser);
29:
30: parser = factory.createFileEntryParser("UNIX");
31: assertTrue(parser instanceof UnixFTPEntryParser);
32:
33: parser = factory.createFileEntryParser("Unix");
34: assertTrue(parser instanceof UnixFTPEntryParser);
35:
36: parser = factory.createFileEntryParser("EnterpriseUnix");
37: assertTrue(parser instanceof UnixFTPEntryParser);
38: assertFalse(parser instanceof EnterpriseUnixFTPEntryParser);
39:
40: // works because contains the expression "Unix"
41: parser = factory.createFileEntryParser("UnixFTPEntryParser");
42: assertTrue(parser instanceof UnixFTPEntryParser);
43:
44: try {
45: parser = factory.createFileEntryParser("NT");
46: fail("Exception should have been thrown. \"NT\" is not a recognized key");
47: } catch (ParserInitializationException pie) {
48: assertNull(pie.getRootCause());
49: }
50:
51: parser = factory.createFileEntryParser("WindowsNT");
52: assertTrue(parser instanceof CompositeFileEntryParser);
53:
54: parser = factory.createFileEntryParser("ThigaVMSaMaJig");
55: assertTrue(parser instanceof VMSFTPEntryParser);
56:
57: parser = factory.createFileEntryParser("OS/2");
58: assertTrue(parser instanceof OS2FTPEntryParser);
59:
60: parser = factory.createFileEntryParser("OS/400");
61: assertTrue(parser instanceof CompositeFileEntryParser);
62:
63: try {
64: parser = factory
65: .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
72: .createFileEntryParser("org.apache.commons.net.ftp.parser.OS2FTPEntryParser");
73: assertTrue(parser instanceof OS2FTPEntryParser);
74:
75: try {
76: parser = factory
77: .createFileEntryParser("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: }
|