mirror of https://github.com/apache/jclouds.git
'iso8601DateParseWithOptionalTZ' -> 'iso8601DateOrSecondsDateParse' in DateService
Follow-up to d57bbebe
This commit is contained in:
parent
9c82ded343
commit
eba727fef7
|
@ -52,7 +52,7 @@ public class CopyObjectHandler extends ParseSax.HandlerWithResult<ObjectMetadata
|
|||
this.currentETag = currentOrNull(currentText);
|
||||
} else if (qName.equals("LastModified")) {
|
||||
this.currentLastModified = dateParser
|
||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText));
|
||||
.iso8601DateOrSecondsDateParse(currentOrNull(currentText));
|
||||
} else if (qName.equals("CopyObjectResult")) {
|
||||
metadata = new CopyObjectResult(currentLastModified, currentETag);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<Set<Buck
|
|||
currentName = currentOrNull(currentText);
|
||||
} else if (qName.equals("CreationDate")) {
|
||||
currentCreationDate = dateParser
|
||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText));
|
||||
.iso8601DateOrSecondsDateParse(currentOrNull(currentText));
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
|
|||
builder.uri(uriBuilder(getRequest().getEndpoint()).clearQuery().appendPath(currentKey).build());
|
||||
} else if (qName.equals("LastModified")) {
|
||||
builder.lastModified(dateParser
|
||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText)));
|
||||
.iso8601DateOrSecondsDateParse(currentOrNull(currentText)));
|
||||
} else if (qName.equals("ETag")) {
|
||||
String currentETag = currentOrNull(currentText);
|
||||
builder.eTag(currentETag);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class CopyObjectHandlerTest extends BaseHandlerTest {
|
|||
|
||||
private DateService dateService;
|
||||
|
||||
private final String copyObjectXML = "<CopyObjectResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LastModified>2014-07-23T20:53:17+0000</LastModified><ETag>\"92836a3ea45a6984d1b4d23a747d46bb\"</ETag></CopyObjectResult>";
|
||||
private final String copyObjectResultWithSecondsDate = "<CopyObjectResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LastModified>2014-07-23T20:53:17+0000</LastModified><ETag>\"92836a3ea45a6984d1b4d23a747d46bb\"</ETag></CopyObjectResult>";
|
||||
|
||||
@BeforeTest
|
||||
@Override
|
||||
|
@ -64,8 +64,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"),
|
||||
|
|
|
@ -47,7 +47,7 @@ import com.google.common.collect.ImmutableList;
|
|||
@Test(groups = "unit", testName = "ListBucketHandlerTest")
|
||||
public class ListBucketHandlerTest extends BaseHandlerTest {
|
||||
public static final String listBucketWithPrefixAppsSlash = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Name>adriancole.org.jclouds.s3.amazons3testdelimiter</Name><Prefix>apps/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>apps/0</Key><LastModified>2009-05-07T18:27:08.000Z</LastModified><ETag>"c82e6a0025c31c5de5947fda62ac51ab"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/1</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"944fab2c5a9a6bacf07db5e688310d7a"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/2</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"a227b8888045c8fd159fb495214000f0"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/3</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"c9caa76c3dec53e2a192608ce73eef03"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/4</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"1ce5d0dcc6154a647ea90c7bdf82a224"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/5</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"79433524d87462ee05708a8ef894ed55"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/6</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"dd00a060b28ddca8bc5a21a49e306f67"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/7</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"8cd06eca6e819a927b07a285d750b100"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/8</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"174495094d0633b92cbe46603eee6bad"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/9</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"cd8a19b26fea8a827276df0ad11c580d"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>";
|
||||
public static final String listBucketWithTSTimeZone = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Name>adriancole.org.jclouds.s3.amazons3testdelimiter</Name><Prefix>apps/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>apps/9</Key><LastModified>2014-07-23T20:53:17+0000</LastModified><ETag>"cd8a19b26fea8a827276df0ad11c580d"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>";
|
||||
public static final String listBucketWithSecondsDate = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Name>adriancole.org.jclouds.s3.amazons3testdelimiter</Name><Prefix>apps/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>apps/9</Key><LastModified>2014-07-23T20:53:17+0000</LastModified><ETag>"cd8a19b26fea8a827276df0ad11c580d"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>";
|
||||
public static final String listBucketWithSlashDelimiterAndCommonPrefixApps = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"> <Delimiter>/</Delimiter> <CommonPrefixes><Prefix>apps/</Prefix></CommonPrefixes></ListBucketResult>";
|
||||
private DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
|
@ -139,9 +139,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"),
|
||||
|
|
|
@ -85,7 +85,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);
|
||||
|
|
|
@ -169,6 +169,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) {
|
||||
|
@ -203,18 +217,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,12 +107,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
|
||||
|
|
|
@ -127,6 +127,20 @@ public class JodaDateService implements DateService {
|
|||
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));
|
||||
|
@ -141,18 +155,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue