From c8561a20350b5fcb6587714cb212f4c62f92d0a1 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 21 Mar 2013 17:21:12 -0700 Subject: [PATCH 1/2] fix the global date parsing issue. --- .../BrokerPropertiesMapper.java | 5 + .../BrokerPropertiesMapperTest.java | 118 +++++++++++++----- 2 files changed, 89 insertions(+), 34 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java index eefbae626684..3dfa6ea80c5f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java @@ -17,6 +17,8 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.Locale; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.JsonParseException; @@ -26,7 +28,10 @@ public class BrokerPropertiesMapper { public BrokerProperties fromString(String value) throws IllegalArgumentException { + ObjectMapper mapper = new ObjectMapper(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); + mapper.setDateFormat(simpleDateFormat); try { return mapper.readValue(value.getBytes("UTF-8"), BrokerProperties.class); } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/BrokerPropertiesMapperTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/BrokerPropertiesMapperTest.java index cef5f5f3b42b..ce827d0430ec 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/BrokerPropertiesMapperTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/BrokerPropertiesMapperTest.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.services.serviceBus; @@ -18,14 +18,40 @@ import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; +import org.junit.BeforeClass; import org.junit.Test; import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerProperties; import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper; public class BrokerPropertiesMapperTest { + + private final String testBrokerPropertiesString = "{" + "\"CorrelationId\": \"corid\"," + + "\"SessionId\": \"sesid\"," + "\"DeliveryCount\": 5," + + "\"LockedUntilUtc\": \" Fri, 14 Oct 2011 12:34:56 GMT\"," + "\"LockToken\": \"loctok\"," + + "\"MessageId\": \"mesid\"," + "\"Label\": \"lab\"," + "\"ReplyTo\": \"repto\"," + + "\"SequenceNumber\": 7," + "\"TimeToLive\": 8.123," + "\"To\": \"to\"," + + "\"ScheduledEnqueueTimeUtc\": \" Sun, 06 Nov 1994 08:49:37 GMT\"," + + "\"ReplyToSessionId\": \"reptosesid\"," + "\"MessageLocation\": \"mesloc\"," + + "\"LockLocation\": \"locloc\"" + "}"; + + private static Date schedTimeUtc, lockedUntilUtc; + + @BeforeClass + public static void setup() { + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + calendar.set(1994, 10, 6, 8, 49, 37); + schedTimeUtc = calendar.getTime(); + + Calendar calendar2 = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + calendar2.set(2011, 9, 14, 12, 34, 56); + lockedUntilUtc = calendar2.getTime(); + + } + @Test public void jsonStringMapsToBrokerPropertiesObject() { // Arrange @@ -61,33 +87,8 @@ public void deserializingAllPossibleValues() { // Arrange BrokerPropertiesMapper mapper = new BrokerPropertiesMapper(); - Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - calendar.set(1994, 10, 6, 8, 49, 37); - Date schedTimeUtc = calendar.getTime(); - - Calendar calendar2 = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - calendar2.set(2011, 9, 14, 12, 34, 56); - Date lockedUntilUtc = calendar2.getTime(); - // Act - BrokerProperties properties = mapper.fromString( - "{" + - "\"CorrelationId\": \"corid\"," + - "\"SessionId\": \"sesid\"," + - "\"DeliveryCount\": 5," + - "\"LockedUntilUtc\": \" Fri, 14 Oct 2011 12:34:56 GMT\"," + - "\"LockToken\": \"loctok\"," + - "\"MessageId\": \"mesid\"," + - "\"Label\": \"lab\"," + - "\"ReplyTo\": \"repto\"," + - "\"SequenceNumber\": 7," + - "\"TimeToLive\": 8.123," + - "\"To\": \"to\"," + - "\"ScheduledEnqueueTimeUtc\": \" Sun, 06 Nov 1994 08:49:37 GMT\"," + - "\"ReplyToSessionId\": \"reptosesid\"," + - "\"MessageLocation\": \"mesloc\"," + - "\"LockLocation\": \"locloc\"" + - "}"); + BrokerProperties properties = mapper.fromString(testBrokerPropertiesString); // Assert assertNotNull(properties); @@ -124,4 +125,53 @@ public void missingDatesDeserializeAsNull() { assertNull(properties.getLockedUntilUtc()); assertNull(properties.getScheduledEnqueueTimeUtc()); } + + @Test + public void deserializeDateInKrKrLocaleCorrectly() { + // Arrange + BrokerPropertiesMapper mapper = new BrokerPropertiesMapper(); + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.KOREA); + + // Act + BrokerProperties brokerProperties = mapper.fromString(testBrokerPropertiesString); + Locale.setDefault(defaultLocale); + + // Assert + long lockedUntilDelta = brokerProperties.getLockedUntilUtc().getTime() - lockedUntilUtc.getTime(); + assertTrue(Math.abs(lockedUntilDelta) < 2000); + } + + @Test + public void deserializeDateInEnUsLocaleCorrectly() { + // Arrange + BrokerPropertiesMapper mapper = new BrokerPropertiesMapper(); + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.US); + + // Act + BrokerProperties brokerProperties = mapper.fromString(testBrokerPropertiesString); + Locale.setDefault(defaultLocale); + + // Assert + long lockedUntilDelta = brokerProperties.getLockedUntilUtc().getTime() - lockedUntilUtc.getTime(); + assertTrue(Math.abs(lockedUntilDelta) < 2000); + + } + + @Test + public void deserializeDateInZhCnLocaleCorrectly() { + // Arrange + BrokerPropertiesMapper mapper = new BrokerPropertiesMapper(); + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.CHINA); + + // Act + BrokerProperties brokerProperties = mapper.fromString(testBrokerPropertiesString); + Locale.setDefault(defaultLocale); + + // Assert + long lockedUntilDelta = brokerProperties.getLockedUntilUtc().getTime() - lockedUntilUtc.getTime(); + assertTrue(Math.abs(lockedUntilDelta) < 2000); + } } From cce6e7c661cb721e4944eaf99d76204945267f54 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 21 Mar 2013 18:12:32 -0700 Subject: [PATCH 2/2] fix the javadoc documentation issue. --- microsoft-azure-api/pom.xml | 2 +- .../com/microsoft/windowsazure/services/core/package.html | 5 +++++ .../windowsazure/services/core/storage/package.html | 5 +++++ .../services/media/entityoperations/package.html | 5 +++++ .../windowsazure/services/media/models/package.html | 5 +++++ .../com/microsoft/windowsazure/services/media/package.html | 5 +++++ 6 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/package.html create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/package.html create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/entityoperations/package.html create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/package.html create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/package.html diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 1900ba335e49..a931921be3c4 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -169,7 +169,7 @@ maven-javadoc-plugin 2.8 - *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.storage /**
* Copyright Microsoft Corporation
* diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/package.html new file mode 100644 index 000000000000..513ca5833c7a --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/package.html @@ -0,0 +1,5 @@ + + +This package contains the core classes across difference services. + + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/package.html new file mode 100644 index 000000000000..b1450b0ca78a --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/package.html @@ -0,0 +1,5 @@ + + +This package contains the blob service core class and interface, + + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/entityoperations/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/entityoperations/package.html new file mode 100644 index 000000000000..e7819f147963 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/entityoperations/package.html @@ -0,0 +1,5 @@ + + +This package contains the media service OData operation class, interface, and utility classes. + + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/package.html new file mode 100644 index 000000000000..719e4d9b595c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/package.html @@ -0,0 +1,5 @@ + + +This package contains the media service data transfer object classes. + + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/package.html new file mode 100644 index 000000000000..324cb3246c05 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/package.html @@ -0,0 +1,5 @@ + + +This package contains the media services, interface, and associated configuration and utility classes. + +