mirror of https://github.com/apache/jclouds.git
'iso8601DateParseWithOptionalTZ' -> 'iso8601DateOrSecondsDateParse' in DateService
Follow-up to d57bbebe
This commit is contained in:
parent
8ce9f79fde
commit
229fdd70cb
|
@ -53,7 +53,7 @@ public class CopyObjectHandler extends ParseSax.HandlerWithResult<ObjectMetadata
|
||||||
this.currentETag = currentOrNull(currentText);
|
this.currentETag = currentOrNull(currentText);
|
||||||
} else if (qName.equals("LastModified")) {
|
} else if (qName.equals("LastModified")) {
|
||||||
this.currentLastModified = dateParser
|
this.currentLastModified = dateParser
|
||||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText));
|
.iso8601DateOrSecondsDateParse(currentOrNull(currentText));
|
||||||
} else if (qName.equals("CopyObjectResult")) {
|
} else if (qName.equals("CopyObjectResult")) {
|
||||||
metadata = new CopyObjectResult(currentLastModified, currentETag);
|
metadata = new CopyObjectResult(currentLastModified, currentETag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<Set<Buck
|
||||||
currentName = currentOrNull(currentText);
|
currentName = currentOrNull(currentText);
|
||||||
} else if (qName.equals("CreationDate")) {
|
} else if (qName.equals("CreationDate")) {
|
||||||
currentCreationDate = dateParser
|
currentCreationDate = dateParser
|
||||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText));
|
.iso8601DateOrSecondsDateParse(currentOrNull(currentText));
|
||||||
}
|
}
|
||||||
currentText = new StringBuilder();
|
currentText = new StringBuilder();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
|
||||||
builder.uri(uriBuilder(getRequest().getEndpoint()).clearQuery().appendPath(currentKey).build());
|
builder.uri(uriBuilder(getRequest().getEndpoint()).clearQuery().appendPath(currentKey).build());
|
||||||
} else if (qName.equals("LastModified")) {
|
} else if (qName.equals("LastModified")) {
|
||||||
builder.lastModified(dateParser
|
builder.lastModified(dateParser
|
||||||
.iso8601DateParseWithOptionalTZ(currentOrNull(currentText)));
|
.iso8601DateOrSecondsDateParse(currentOrNull(currentText)));
|
||||||
} else if (qName.equals("ETag")) {
|
} else if (qName.equals("ETag")) {
|
||||||
String currentETag = currentOrNull(currentText);
|
String currentETag = currentOrNull(currentText);
|
||||||
builder.eTag(currentETag);
|
builder.eTag(currentETag);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class CopyObjectHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
private DateService dateService;
|
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
|
@BeforeTest
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,8 +66,8 @@ public class CopyObjectHandlerTest extends BaseHandlerTest {
|
||||||
* Verifies that the parser doesn't barf if the timestamp in the copy object
|
* Verifies that the parser doesn't barf if the timestamp in the copy object
|
||||||
* xml has time zone designators.
|
* xml has time zone designators.
|
||||||
*/
|
*/
|
||||||
public void testTimeStampWithTZ() {
|
public void testApplyInputStreamWithSecondsDate() {
|
||||||
InputStream is = Strings2.toInputStream(copyObjectXML);
|
InputStream is = Strings2.toInputStream(copyObjectResultWithSecondsDate);
|
||||||
ObjectMetadata expected = new CopyObjectResult(
|
ObjectMetadata expected = new CopyObjectResult(
|
||||||
new SimpleDateFormatDateService()
|
new SimpleDateFormatDateService()
|
||||||
.iso8601SecondsDateParse("2014-07-23T20:53:17+0000"),
|
.iso8601SecondsDateParse("2014-07-23T20:53:17+0000"),
|
||||||
|
|
|
@ -49,7 +49,7 @@ import com.google.common.collect.ImmutableList;
|
||||||
@Test(groups = "unit", testName = "ListBucketHandlerTest")
|
@Test(groups = "unit", testName = "ListBucketHandlerTest")
|
||||||
public class ListBucketHandlerTest extends BaseHandlerTest {
|
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 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>";
|
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();
|
private DateService dateService = new SimpleDateFormatDateService();
|
||||||
|
|
||||||
|
@ -141,9 +141,9 @@ public class ListBucketHandlerTest extends BaseHandlerTest {
|
||||||
* list bucket response has time zone designators in it.
|
* list bucket response has time zone designators in it.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testListMyBucketsWithTZ() {
|
public void testListMyBucketsWithSecondsDate() {
|
||||||
ListBucketResponse bucket = createParser().parse(
|
ListBucketResponse bucket = createParser().parse(
|
||||||
Strings2.toInputStream(listBucketWithTSTimeZone));
|
Strings2.toInputStream(listBucketWithSecondsDate));
|
||||||
ObjectMetadata expected = new CopyObjectResult(
|
ObjectMetadata expected = new CopyObjectResult(
|
||||||
new SimpleDateFormatDateService()
|
new SimpleDateFormatDateService()
|
||||||
.iso8601SecondsDateParse("2014-07-23T20:53:17+0000"),
|
.iso8601SecondsDateParse("2014-07-23T20:53:17+0000"),
|
||||||
|
|
|
@ -88,7 +88,7 @@ public interface DateService {
|
||||||
* @return the Date object of the parsed string.
|
* @return the Date object of the parsed string.
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
Date iso8601DateParseWithOptionalTZ(String toParse)
|
Date iso8601DateOrSecondsDateParse(String toParse)
|
||||||
throws IllegalArgumentException;
|
throws IllegalArgumentException;
|
||||||
|
|
||||||
String rfc1123DateFormat(Date date);
|
String rfc1123DateFormat(Date date);
|
||||||
|
|
|
@ -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
|
@Override
|
||||||
public String iso8601SecondsDateFormat(Date date) {
|
public String iso8601SecondsDateFormat(Date date) {
|
||||||
synchronized (iso8601SecondsSimpleDateFormat) {
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,12 +110,19 @@ public class DateServiceTest extends PerformanceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIso8601OptionalTZDateParse() {
|
public void testIso8601DateOrSecondsDateParse() {
|
||||||
Date dsDate = dateService
|
Date dsDate = dateService
|
||||||
.iso8601DateParseWithOptionalTZ(testData[0].iso8601SecondsDateString);
|
.iso8601DateOrSecondsDateParse(testData[0].iso8601DateString);
|
||||||
Date secondsDate = dateService
|
assertEquals(dsDate, testData[0].date);
|
||||||
.iso8601SecondsDateParse(testData[0].iso8601SecondsDateString);
|
|
||||||
assertEquals(dsDate, secondsDate);
|
Date dsSecondsDate = dateService
|
||||||
|
.iso8601DateOrSecondsDateParse(testData[0].iso8601SecondsDateString);
|
||||||
|
assertEquals(dsSecondsDate, testData[0].date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testIso8601DateOrSecondsDateParseIllegal() {
|
||||||
|
dateService.iso8601DateOrSecondsDateParse("-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -132,6 +132,20 @@ public class JodaDateService implements DateService {
|
||||||
return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate();
|
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
|
@Override
|
||||||
public final String rfc1123DateFormat(Date dateTime) {
|
public final String rfc1123DateFormat(Date dateTime) {
|
||||||
return rfc1123DateFormat.print(new DateTime(dateTime));
|
return rfc1123DateFormat.print(new DateTime(dateTime));
|
||||||
|
@ -146,18 +160,4 @@ public class JodaDateService implements DateService {
|
||||||
public final Date rfc1123DateParse(String toParse) {
|
public final Date rfc1123DateParse(String toParse) {
|
||||||
return rfc1123DateFormat.parseDateTime(toParse).toDate();
|
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