1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.net.ftp;
17
18 import java.text.DateFormatSymbols;
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22 import java.util.Locale;
23
24 import junit.framework.TestCase;
25
26 public class FTPClientConfigTest extends TestCase {
27
28
29
30
31 public void testFTPClientConfigString() {
32 FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_VMS);
33 assertEquals(FTPClientConfig.SYST_VMS, config.getServerSystemKey());
34 assertNull(config.getDefaultDateFormatStr());
35 assertNull(config.getRecentDateFormatStr());
36 assertNull(config.getShortMonthNames());
37 assertNull(config.getServerTimeZoneId());
38 assertNull(config.getServerLanguageCode());
39 }
40
41 String A = "A";
42 String B = "B";
43 String C = "C";
44 String D = "D";
45 String E = "E";
46 String F = "F";
47
48
49
50
51 public void testFTPClientConfigStringStringStringStringStringString() {
52 FTPClientConfig conf = new FTPClientConfig(A,B,C,D,E,F);
53
54 assertEquals("A", conf.getServerSystemKey());
55 assertEquals("B", conf.getDefaultDateFormatStr());
56 assertEquals("C", conf.getRecentDateFormatStr());
57 assertEquals("E", conf.getShortMonthNames());
58 assertEquals("F", conf.getServerTimeZoneId());
59 assertEquals("D", conf.getServerLanguageCode());
60 }
61
62
63 String badDelim = "jan,feb,mar,apr,may,jun,jul,aug.sep,oct,nov,dec";
64 String tooLong = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|jan";
65 String tooShort = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov";
66 String fakeLang = "abc|def|ghi|jkl|mno|pqr|stu|vwx|yza|bcd|efg|hij";
67
68 public void testSetShortMonthNames() {
69 }
70
71 public void testGetServerLanguageCode() {
72 }
73
74 public void testLookupDateFormatSymbols() {
75 DateFormatSymbols dfs1 = null;
76 DateFormatSymbols dfs2 = null;
77 DateFormatSymbols dfs3 = null;
78 DateFormatSymbols dfs4 = null;
79
80
81 try {
82 dfs1 = FTPClientConfig.lookupDateFormatSymbols("fr");
83 } catch (IllegalArgumentException e){
84 fail("french");
85 }
86
87 try {
88 dfs2 = FTPClientConfig.lookupDateFormatSymbols("sq");
89 } catch (IllegalArgumentException e){
90 fail("albanian");
91 }
92
93 try {
94 dfs3 = FTPClientConfig.lookupDateFormatSymbols("ru");
95 } catch (IllegalArgumentException e){
96 fail("unusupported.default.to.en");
97 }
98 try {
99 dfs4 = FTPClientConfig.lookupDateFormatSymbols(fakeLang);
100 } catch (IllegalArgumentException e){
101 fail("not.language.code.but.defaults");
102 }
103
104 assertEquals(dfs3,dfs4);
105
106 SimpleDateFormat sdf1 = new SimpleDateFormat("d MMM yyyy", dfs1);
107 SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs2);
108 SimpleDateFormat sdf3 = new SimpleDateFormat("MMM dd, yyyy", dfs3);
109 Date d1 = null;
110 Date d2 = null;
111 Date d3 = null;
112 try {
113 d1 = sdf1.parse("31 d\u00e9c 2004");
114 } catch (ParseException px) {
115 fail("failed.to.parse.french");
116 }
117 try {
118 d2 = sdf2.parse("dhj 31, 2004");
119 } catch (ParseException px) {
120 fail("failed.to.parse.albanian");
121 }
122 try {
123 d3 = sdf3.parse("DEC 31, 2004");
124 } catch (ParseException px) {
125 fail("failed.to.parse.'russian'");
126 }
127 assertEquals("different.parser.same.date", d1, d2);
128 assertEquals("different.parser.same.date", d1, d3);
129
130 }
131
132 public void testGetDateFormatSymbols() {
133
134 try {
135 FTPClientConfig.getDateFormatSymbols(badDelim);
136 fail("bad delimiter");
137 } catch (IllegalArgumentException e){
138
139 }
140 try {
141 FTPClientConfig.getDateFormatSymbols(tooLong);
142 fail("more than 12 months");
143 } catch (IllegalArgumentException e){
144
145 }
146 try {
147 FTPClientConfig.getDateFormatSymbols(tooShort);
148 fail("fewer than 12 months");
149 } catch (IllegalArgumentException e){
150
151 }
152 DateFormatSymbols dfs2 = null;
153 try {
154 dfs2 = FTPClientConfig.getDateFormatSymbols(fakeLang);
155 } catch (Exception e){
156 fail("rejected valid short month string");
157 }
158 SimpleDateFormat sdf1 =
159 new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
160 SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs2);
161
162 Date d1 = null;
163 Date d2 = null;
164 try {
165 d1 = sdf1.parse("dec 31, 2004");
166 } catch (ParseException px) {
167 fail("failed.to.parse.std");
168 }
169 try {
170 d2 = sdf2.parse("hij 31, 2004");
171 } catch (ParseException px) {
172 fail("failed.to.parse.weird");
173 }
174
175 assertEquals("different.parser.same.date",d1, d2);
176
177 try {
178 d2 = sdf1.parse("hij 31, 2004");
179 fail("should.have.failed.to.parse.weird");
180 } catch (ParseException px) {
181 }
182 try {
183 d2 = sdf2.parse("dec 31, 2004");
184 fail("should.have.failed.to.parse.standard");
185 } catch (ParseException px) {
186 }
187
188
189 }
190
191 }