Skip to content

Support SQS messages with Type Binary and Number #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class SQSMessagingClientConstants {
*/
public static final String STRING = "String";

public static final String BINARY = "Binary";

public static final String NUMBER = "Number";

public static final String INT = "Number.int";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ private static String getType(Object value) throws JMSException {
private static Object getObjectValue(String value, String type) throws JMSException {
if (INT.equals(type)) {
return Integer.valueOf(value);
} else if (STRING.equals(type) || NUMBER.equals(type) || BINARY.equals(type)) {
return value;
} else if (LONG.equals(type)) {
return Long.valueOf(value);
} else if (BOOLEAN.equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SQSMessageTest {
final String myString = "myString";
final String myCustomString = "myCustomString";
final String myNumber = "myNumber";
final String myBinary = "myBinary";

@Before
public void setup() {
Expand All @@ -79,6 +80,7 @@ public void testProperty() throws JMSException {
message.setByteProperty("myByteProperty", (byte) 'a');
message.setStringProperty("myString", "StringValue");
message.setStringProperty("myNumber", "500");
message.setStringProperty("myBinary", "binarydata");

Assert.assertTrue(message.propertyExists("myTrueBoolean"));
Assert.assertEquals(message.getObjectProperty("myTrueBoolean"), true);
Expand Down Expand Up @@ -125,6 +127,10 @@ public void testProperty() throws JMSException {
Assert.assertEquals(message.getDoubleProperty("myNumber"), 500d);
Assert.assertEquals(message.getIntProperty("myNumber"), 500);

Assert.assertTrue(message.propertyExists("myBinary"));
Assert.assertEquals(message.getObjectProperty("myBinary"), "binarydata");
Assert.assertEquals(message.getStringProperty("myBinary"), "binarydata");

// Validate property names
Set<String> propertyNamesSet = new HashSet<String>(Arrays.asList(
"myTrueBoolean",
Expand All @@ -136,6 +142,7 @@ public void testProperty() throws JMSException {
"myShort",
"myByteProperty",
"myNumber",
"myBinary",
"myString"));

Enumeration<String > propertyNames = message.getPropertyNames();
Expand All @@ -156,6 +163,7 @@ public void testProperty() throws JMSException {
Assert.assertFalse(message.propertyExists("myByteProperty"));
Assert.assertFalse(message.propertyExists("myString"));
Assert.assertFalse(message.propertyExists("myNumber"));
Assert.assertFalse(message.propertyExists("myBinary"));

propertyNames = message.getPropertyNames();
assertFalse(propertyNames.hasMoreElements());
Expand Down Expand Up @@ -335,6 +343,10 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
.withDataType(SQSMessagingClientConstants.NUMBER)
.withStringValue("500"));

messageAttributes.put(myBinary, new MessageAttributeValue()
.withDataType(SQSMessagingClientConstants.BINARY)
.withStringValue("binarydata"));

com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message()
.withMessageAttributes(messageAttributes)
.withAttributes(systemAttributes)
Expand Down Expand Up @@ -392,6 +404,9 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
Assert.assertEquals(message.getFloatProperty(myNumber), 500f);
Assert.assertEquals(message.getDoubleProperty(myNumber), 500d);

Assert.assertTrue(message.propertyExists(myBinary));
Assert.assertEquals(message.getObjectProperty(myBinary), "binarydata");
Assert.assertEquals(message.getStringProperty(myBinary), "binarydata");

// Validate property names
Set<String> propertyNamesSet = new HashSet<String>(Arrays.asList(
Expand All @@ -406,6 +421,7 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
myString,
myCustomString,
myNumber,
myBinary,
JMSX_DELIVERY_COUNT));

Enumeration<String > propertyNames = message.getPropertyNames();
Expand All @@ -426,6 +442,7 @@ public void testSQSMessageAttributeToProperty() throws JMSException {
Assert.assertFalse(message.propertyExists("myByteProperty"));
Assert.assertFalse(message.propertyExists("myString"));
Assert.assertFalse(message.propertyExists("myNumber"));
Assert.assertFalse(message.propertyExists("myBinary"));

propertyNames = message.getPropertyNames();
assertFalse(propertyNames.hasMoreElements());
Expand Down