Skip to content
Merged

Dev #300

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion microsoft-azure-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<excludePackageNames>*.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization</excludePackageNames>
<excludePackageNames>*.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.storage</excludePackageNames>
<bottom><![CDATA[<code>/**
<br/>* Copyright Microsoft Corporation
<br/>*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<head />
<body>This package contains the core classes across difference services.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<head />
<body>This package contains the blob service core class and interface,
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<head />
<body>This package contains the media service OData operation class, interface, and utility classes.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<head />
<body>This package contains the media service data transfer object classes.
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<head />
<body>This package contains the media services, interface, and associated configuration and utility classes.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,56 @@
* 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;

import static org.junit.Assert.*;

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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}