diff --git a/apis/s3/src/main/java/org/jclouds/s3/xml/CopyObjectHandler.java b/apis/s3/src/main/java/org/jclouds/s3/xml/CopyObjectHandler.java index c9bcf31cc6..02e4c86a1a 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/xml/CopyObjectHandler.java +++ b/apis/s3/src/main/java/org/jclouds/s3/xml/CopyObjectHandler.java @@ -53,7 +53,7 @@ public class CopyObjectHandler extends ParseSax.HandlerWithResult2014-07-23T20:53:17+0000\"92836a3ea45a6984d1b4d23a747d46bb\""; + private final String copyObjectResultWithSecondsDate = "2014-07-23T20:53:17+0000\"92836a3ea45a6984d1b4d23a747d46bb\""; @BeforeTest @Override @@ -66,8 +66,8 @@ public class CopyObjectHandlerTest extends BaseHandlerTest { * Verifies that the parser doesn't barf if the timestamp in the copy object * xml has time zone designators. */ - public void testTimeStampWithTZ() { - InputStream is = Strings2.toInputStream(copyObjectXML); + public void testApplyInputStreamWithSecondsDate() { + InputStream is = Strings2.toInputStream(copyObjectResultWithSecondsDate); ObjectMetadata expected = new CopyObjectResult( new SimpleDateFormatDateService() .iso8601SecondsDateParse("2014-07-23T20:53:17+0000"), diff --git a/apis/s3/src/test/java/org/jclouds/s3/xml/ListBucketHandlerTest.java b/apis/s3/src/test/java/org/jclouds/s3/xml/ListBucketHandlerTest.java index 7b77e28d65..231d397877 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/xml/ListBucketHandlerTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/xml/ListBucketHandlerTest.java @@ -49,7 +49,7 @@ import com.google.common.collect.ImmutableList; @Test(groups = "unit", testName = "ListBucketHandlerTest") public class ListBucketHandlerTest extends BaseHandlerTest { public static final String listBucketWithPrefixAppsSlash = "adriancole.org.jclouds.s3.amazons3testdelimiterapps/1000falseapps/02009-05-07T18:27:08.000Z"c82e6a0025c31c5de5947fda62ac51ab"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/12009-05-07T18:27:09.000Z"944fab2c5a9a6bacf07db5e688310d7a"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/22009-05-07T18:27:09.000Z"a227b8888045c8fd159fb495214000f0"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/32009-05-07T18:27:09.000Z"c9caa76c3dec53e2a192608ce73eef03"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/42009-05-07T18:27:09.000Z"1ce5d0dcc6154a647ea90c7bdf82a224"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/52009-05-07T18:27:09.000Z"79433524d87462ee05708a8ef894ed55"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/62009-05-07T18:27:10.000Z"dd00a060b28ddca8bc5a21a49e306f67"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/72009-05-07T18:27:10.000Z"8cd06eca6e819a927b07a285d750b100"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/82009-05-07T18:27:10.000Z"174495094d0633b92cbe46603eee6bad"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/92009-05-07T18:27:10.000Z"cd8a19b26fea8a827276df0ad11c580d"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; - public static final String listBucketWithTSTimeZone = "adriancole.org.jclouds.s3.amazons3testdelimiterapps/1000falseapps/92014-07-23T20:53:17+0000"cd8a19b26fea8a827276df0ad11c580d"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; + public static final String listBucketWithSecondsDate = "adriancole.org.jclouds.s3.amazons3testdelimiterapps/1000falseapps/92014-07-23T20:53:17+0000"cd8a19b26fea8a827276df0ad11c580d"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; public static final String listBucketWithSlashDelimiterAndCommonPrefixApps = " / apps/"; private DateService dateService = new SimpleDateFormatDateService(); @@ -141,9 +141,9 @@ public class ListBucketHandlerTest extends BaseHandlerTest { * list bucket response has time zone designators in it. */ @Test - public void testListMyBucketsWithTZ() { + public void testListMyBucketsWithSecondsDate() { ListBucketResponse bucket = createParser().parse( - Strings2.toInputStream(listBucketWithTSTimeZone)); + Strings2.toInputStream(listBucketWithSecondsDate)); ObjectMetadata expected = new CopyObjectResult( new SimpleDateFormatDateService() .iso8601SecondsDateParse("2014-07-23T20:53:17+0000"), diff --git a/core/src/main/java/org/jclouds/date/DateService.java b/core/src/main/java/org/jclouds/date/DateService.java index 7d5b3bd6d3..a03a7a6067 100644 --- a/core/src/main/java/org/jclouds/date/DateService.java +++ b/core/src/main/java/org/jclouds/date/DateService.java @@ -88,7 +88,7 @@ public interface DateService { * @return the Date object of the parsed string. * @throws IllegalArgumentException */ - Date iso8601DateParseWithOptionalTZ(String toParse) + Date iso8601DateOrSecondsDateParse(String toParse) throws IllegalArgumentException; String rfc1123DateFormat(Date date); diff --git a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java index e3ce9130d8..b4e141f881 100644 --- a/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java +++ b/core/src/main/java/org/jclouds/date/internal/SimpleDateFormatDateService.java @@ -172,6 +172,20 @@ public class SimpleDateFormatDateService implements DateService { } } + @Override + public Date iso8601DateOrSecondsDateParse(String toParse) + throws IllegalArgumentException { + try { + return iso8601DateParse(toParse); + } catch (IllegalArgumentException orig) { + try { + return iso8601SecondsDateParse(toParse); + } catch (IllegalArgumentException ignored) { + throw orig; + } + } + } + @Override public String iso8601SecondsDateFormat(Date date) { synchronized (iso8601SecondsSimpleDateFormat) { @@ -206,18 +220,4 @@ public class SimpleDateFormatDateService implements DateService { } } } - - @Override - public Date iso8601DateParseWithOptionalTZ(String toParse) - throws IllegalArgumentException { - try { - return iso8601DateParse(toParse); - } catch (IllegalArgumentException orig) { - try { - return iso8601SecondsDateParse(toParse); - } catch (IllegalArgumentException ie) { - throw orig; - } - } - } } diff --git a/core/src/test/java/org/jclouds/date/DateServiceTest.java b/core/src/test/java/org/jclouds/date/DateServiceTest.java index e8c61a3441..e450784e8e 100644 --- a/core/src/test/java/org/jclouds/date/DateServiceTest.java +++ b/core/src/test/java/org/jclouds/date/DateServiceTest.java @@ -110,12 +110,19 @@ public class DateServiceTest extends PerformanceTest { } @Test - public void testIso8601OptionalTZDateParse() { + public void testIso8601DateOrSecondsDateParse() { Date dsDate = dateService - .iso8601DateParseWithOptionalTZ(testData[0].iso8601SecondsDateString); - Date secondsDate = dateService - .iso8601SecondsDateParse(testData[0].iso8601SecondsDateString); - assertEquals(dsDate, secondsDate); + .iso8601DateOrSecondsDateParse(testData[0].iso8601DateString); + assertEquals(dsDate, testData[0].date); + + Date dsSecondsDate = dateService + .iso8601DateOrSecondsDateParse(testData[0].iso8601SecondsDateString); + assertEquals(dsSecondsDate, testData[0].date); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testIso8601DateOrSecondsDateParseIllegal() { + dateService.iso8601DateOrSecondsDateParse("-1"); } @Test diff --git a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java index 7bb151987f..5e34424ac2 100644 --- a/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java +++ b/drivers/joda/src/main/java/org/jclouds/date/joda/JodaDateService.java @@ -131,7 +131,21 @@ public class JodaDateService implements DateService { toParse = adjustTz(toParse); return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate(); } - + + @Override + public Date iso8601DateOrSecondsDateParse(String toParse) + throws IllegalArgumentException { + try { + return iso8601DateParse(toParse); + } catch (IllegalArgumentException orig) { + try { + return iso8601SecondsDateParse(toParse); + } catch (IllegalArgumentException ignored) { + throw orig; + } + } + } + @Override public final String rfc1123DateFormat(Date dateTime) { return rfc1123DateFormat.print(new DateTime(dateTime)); @@ -146,18 +160,4 @@ public class JodaDateService implements DateService { public final Date rfc1123DateParse(String toParse) { return rfc1123DateFormat.parseDateTime(toParse).toDate(); } - - @Override - public Date iso8601DateParseWithOptionalTZ(String toParse) - throws IllegalArgumentException { - try { - return iso8601DateParse(toParse); - } catch (IllegalArgumentException orig) { - try { - return iso8601SecondsDateParse(toParse); - } catch (IllegalArgumentException ie) { - throw orig; - } - } - } }