Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/main/java/com/rabbitmq/jms/client/RMQMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ public void setJMSMessageID(String id) throws JMSException {
*/
@Override
public long getJMSTimestamp() throws JMSException {
return this.getLongProperty(JMS_MESSAGE_TIMESTAMP);
Object timestamp = this.getObjectProperty(JMS_MESSAGE_TIMESTAMP);
if (timestamp == null) {
return 0L;
} else {
return convertToLong(timestamp);
}
}

/**
Expand Down Expand Up @@ -496,7 +501,10 @@ else if (o instanceof String) {
*/
@Override
public long getLongProperty(String name) throws JMSException {
Object o = this.getObjectProperty(name);
return convertToLong(this.getObjectProperty(name));
}

private static long convertToLong(Object o) throws JMSException {
if (o == null)
throw new NumberFormatException("Null is not a valid long");
else if (o instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright (c) 2013-2020 VMware, Inc. or its affiliates. All rights reserved. */
package com.rabbitmq.integration.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -22,6 +23,7 @@
import javax.jms.Session;
import javax.jms.TextMessage;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import com.rabbitmq.client.AMQP;
Expand Down Expand Up @@ -187,6 +189,7 @@ public void testSendFromAmqpAndReceiveBytesMessage() throws Exception {

assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertEquals("42", message.getStringProperty("DummyProp"), "Numeric property not transferred");
assertThat(message.getJMSTimestamp()).isZero();
}

@Test
Expand Down Expand Up @@ -238,6 +241,7 @@ public void testSendFromAmqpAndReceiveTextMessage() throws Exception {

assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertEquals("42", message.getStringProperty("DummyProp"), "Numeric property not transferred");
assertThat(message.getJMSTimestamp()).isZero();
}

@Test
Expand Down Expand Up @@ -274,6 +278,7 @@ public void testSendFromJmsAndReceiveJmsTextMessage() throws Exception {
assertNotNull(message, "No message received");
assertEquals(MESSAGE, message.getText(), "Payload doesn't match");
assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertThat(message.getJMSTimestamp()).isGreaterThan(0);
}

}