commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neeme Praks <ne...@apache.org>
Subject Re: [net] [ftp] [patch] FTPTimestampParserImplTest.java and FTPClientConfigTest.java
Date Tue, 05 Apr 2005 14:33:08 GMT
ok, these new patches make the failures go away in a bit cleaner manner, 
by manipulating the default locale setting.

Also, I noticed that your java sources are in some strange encoding. If 
I open those tests that use french letters in my Eclipse and save them 
then they become corrupt and will fail.
My configuration assumes that all source files are in UTF8 and I think 
that should be the most reasonable assumption, no?

Rgds,
Neeme

Steve Cohen wrote:

> Okay, now that I understand the problem in general terms, can you 
> please provide stack traces or other information indicating where in 
> the code failures are happening? Your patches provide me with a 
> possible fix, but I need to understand fully the problem. Also if you 
> could tell me the locale and other jvm properties that would help.
>
>
> I think there may be other, more standard fixes that I can apply, but 
> I need to understand the problem fully. It would probably be better, 
> if possible, if could provide a setUp() routine that puts the JVM into 
> the same locale-state anywhere that yours is in by default.
>
> I will be non-responsive for several days, but will look at this when 
> I return later in the week.
>
> Steve
>
>
> Neeme Praks wrote:
>
>>
>> Two patches to make the FTP timestamp parsing tests pass also on 
>> non-english systems.
>> I'm not sure if this is the best way to fix those issues, though.
>>
>> Rgds,
>> Neeme
>>
>>
>> ------------------------------------------------------------------------
>>
>> Index: FTPTimestampParserImplTest.java
>> ===================================================================
>> --- FTPTimestampParserImplTest.java (revision 159615)
>> +++ FTPTimestampParserImplTest.java (working copy)
>> @@ -15,6 +15,7 @@
>> */
>> package org.apache.commons.net.ftp.parser;
>>
>> +import java.text.DateFormatSymbols;
>> import java.text.ParseException;
>> import java.text.SimpleDateFormat;
>> import java.util.Calendar;
>> @@ -73,8 +74,19 @@
>>
>> FTPTimestampParserImpl parser = new FTPTimestampParserImpl();
>>
>> + // assume we are FTPing a server in Chicago, two hours ahead of + 
>> // L. A.
>> + FTPClientConfig config = + new 
>> FTPClientConfig(FTPClientConfig.SYST_UNIX);
>> + config.setDefaultDateFormatStr(FTPTimestampParser.DEFAULT_SDF);
>> + config.setRecentDateFormatStr(FTPTimestampParser.DEFAULT_RECENT_SDF);
>> + // 2 hours difference
>> + config.setServerTimeZoneId("America/Chicago");
>> + parser.configure(config);
>> + + SimpleDateFormat sdf = - new 
>> SimpleDateFormat(parser.getRecentDateFormatString());
>> + new SimpleDateFormat(parser.getRecentDateFormatString(), 
>> parser.getRecentDateFormat().getDateFormatSymbols());
>> // assume we're in the US Pacific Time Zone
>> TimeZone tzla = TimeZone.getTimeZone("America/Los_Angeles");
>> sdf.setTimeZone(tzla);
>> @@ -84,17 +96,6 @@
>> String fmtTimePlusThreeHours = sdf.format(threeHoursFromNow);
>>
>>
>> - // assume we are FTPing a server in Chicago, two hours ahead of - 
>> // L. A.
>> - FTPClientConfig config = - new 
>> FTPClientConfig(FTPClientConfig.SYST_UNIX);
>> - config.setDefaultDateFormatStr(FTPTimestampParser.DEFAULT_SDF);
>> - config.setRecentDateFormatStr(FTPTimestampParser.DEFAULT_RECENT_SDF);
>> - // 2 hours difference
>> - config.setServerTimeZoneId("America/Chicago");
>> - parser.configure(config);
>> -
>> -
>> try {
>> Calendar parsed = parser.parseTimestamp(fmtTimePlusOneHour);
>> // the only difference should be the two hours
>> @@ -103,7 +104,7 @@
>> (long)TWO_HOURS_OF_MILLISECONDS, cal.getTime().getTime() - 
>> parsed.getTime().getTime());
>> } catch (ParseException e){
>> - fail("Unable to parse");
>> + fail("Unable to parse " + fmtTimePlusOneHour);
>> }
>>
>> //but if the file's timestamp is THREE hours ahead of now, that 
>> should @@ -123,13 +124,18 @@
>>
>> public void testParser() {
>> FTPTimestampParserImpl parser = new FTPTimestampParserImpl();
>> + Calendar cal = Calendar.getInstance();
>> + cal.set(Calendar.YEAR, 2002);
>> + cal.set(Calendar.MONTH, 1);
>> + cal.set(Calendar.DAY_OF_MONTH, 22);
>> + SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy");
>> try {
>> - parser.parseTimestamp("feb 22 2002");
>> + parser.parseTimestamp(sdf.format(cal.getTime()));
>> } catch (ParseException e) {
>> fail("failed.to.parse.default");
>> }
>> try {
>> - parser.parseTimestamp("f�v 22 2002");
>> + parser.parseTimestamp("f�v 22 2002");
>> fail("should.have.failed.to.parse.default");
>> } catch (ParseException e) {
>> // this is the success case
>> @@ -140,14 +146,17 @@
>> config.setRecentDateFormatStr("d MMM HH:mm");
>> config.setServerLanguageCode("fr");
>> parser.configure(config);
>> + DateFormatSymbols dfs = FTPClientConfig.lookupDateFormatSymbols("fr");
>> + sdf = new SimpleDateFormat("MMM d yyyy", dfs);
>> try {
>> - parser.parseTimestamp("d�c 22 2002");
>> + parser.parseTimestamp(sdf.format(cal.getTime()));
>> fail("incorrect.field.order");
>> } catch (ParseException e) {
>> // this is the success case
>> }
>> + sdf = new SimpleDateFormat("d MMM yyyy", dfs);
>> try {
>> - parser.parseTimestamp("22 d�c 2002");
>> + parser.parseTimestamp(sdf.format(cal.getTime()));
>> } catch (ParseException e) {
>> fail("failed.to.parse.french");
>> }
>> @@ -159,27 +168,28 @@
>> // this is the success case
>> }
>> try {
>> - parser.parseTimestamp("29 f�v 2002");
>> + parser.parseTimestamp("29 f�v 2002");
>> fail("nonexistent.date");
>> } catch (ParseException e) {
>> // this is the success case
>> }
>>
>> try {
>> - parser.parseTimestamp("22 ao� 30:02");
>> + parser.parseTimestamp("22 ao� 30:02");
>> fail("bad.hour");
>> } catch (ParseException e) {
>> // this is the success case
>> }
>>
>> try {
>> - parser.parseTimestamp("22 ao� 20:74");
>> + parser.parseTimestamp("22 ao� 20:74");
>> fail("bad.minute");
>> } catch (ParseException e) {
>> // this is the success case
>> }
>> + sdf = new SimpleDateFormat("d MMM HH:mm", dfs);
>> try {
>> - parser.parseTimestamp("28 ao� 20:02");
>> + parser.parseTimestamp(sdf.format(cal.getTime()));
>> } catch (ParseException e) {
>> fail("failed.to.parse.french.recent");
>> }
>>
>>
>> ------------------------------------------------------------------------
>>
>> Index: FTPClientConfigTest.java
>> ===================================================================
>> --- FTPClientConfigTest.java (revision 159615)
>> +++ FTPClientConfigTest.java (working copy)
>> @@ -67,6 +67,7 @@
>> String tooLong = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|jan";
>> String tooShort = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov";
>> String fakeLang = "abc|def|ghi|jkl|mno|pqr|stu|vwx|yza|bcd|efg|hij";
>> + String standard = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
>>
>> public void testSetShortMonthNames() {
>> }
>> @@ -153,12 +154,18 @@
>> // should have failed
>> }
>> DateFormatSymbols dfs = null;
>> + DateFormatSymbols dfs2 = null;
>> try {
>> dfs = FTPClientConfig.getDateFormatSymbols(fakeLang);
>> } catch (Exception e){
>> fail("rejected valid short month string");
>> }
>> - SimpleDateFormat sdf1 = new SimpleDateFormat("MMM dd, yyyy");
>> + try {
>> + dfs2 = FTPClientConfig.getDateFormatSymbols(standard);
>> + } catch (Exception e){
>> + fail("rejected valid short month string");
>> + }
>> + SimpleDateFormat sdf1 = new SimpleDateFormat("MMM dd, yyyy", dfs2);
>> SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs);
>> Date d1 = null;
>> @@ -166,7 +173,7 @@
>> try {
>> d1 = sdf1.parse("dec 31, 2004");
>> } catch (ParseException px) {
>> - fail("failed.to.parse.std");
>> + fail("failed.to.parse.std " + px);
>> }
>> try {
>> d2 = sdf2.parse("hij 31, 2004");
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>

Mime
View raw message