mirror of https://github.com/apache/activemq.git
Return null from getBytes if no value present.
This commit is contained in:
parent
ad57cc6fcb
commit
6e038d5ffd
|
@ -494,6 +494,10 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
||||||
public byte[] getBytes(String name) throws JMSException {
|
public byte[] getBytes(String name) throws JMSException {
|
||||||
initializeReading();
|
initializeReading();
|
||||||
Object value = map.get(name);
|
Object value = map.get(name);
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (value instanceof byte[]) {
|
if (value instanceof byte[]) {
|
||||||
return (byte[])value;
|
return (byte[])value;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,8 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.command;
|
package org.apache.activemq.command;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -28,45 +33,20 @@ import javax.jms.MessageFormatException;
|
||||||
import javax.jms.MessageNotReadableException;
|
import javax.jms.MessageNotReadableException;
|
||||||
import javax.jms.MessageNotWriteableException;
|
import javax.jms.MessageNotWriteableException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Test the MapMessage implementation for spec compliance.
|
||||||
*/
|
*/
|
||||||
public class ActiveMQMapMessageTest extends TestCase {
|
public class ActiveMQMapMessageTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQMapMessageTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQMapMessageTest.class);
|
||||||
|
|
||||||
private String name = "testName";
|
private final String name = "testName";
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for ActiveMQMapMessageTest.
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public ActiveMQMapMessageTest(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
junit.textui.TestRunner.run(ActiveMQMapMessageTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see TestCase#setUp()
|
|
||||||
*/
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see TestCase#tearDown()
|
|
||||||
*/
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testBytesConversion() throws JMSException, IOException {
|
public void testBytesConversion() throws JMSException, IOException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setBoolean("boolean", true);
|
msg.setBoolean("boolean", true);
|
||||||
|
@ -84,7 +64,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
// Test with a 1Meg String
|
// Test with a 1Meg String
|
||||||
StringBuffer bigSB = new StringBuffer(1024 * 1024);
|
StringBuffer bigSB = new StringBuffer(1024 * 1024);
|
||||||
for (int i = 0; i < 1024 * 1024; i++) {
|
for (int i = 0; i < 1024 * 1024; i++) {
|
||||||
bigSB.append((char)'a' + i % 26);
|
bigSB.append('a' + i % 26);
|
||||||
}
|
}
|
||||||
String bigString = bigSB.toString();
|
String bigString = bigSB.toString();
|
||||||
|
|
||||||
|
@ -106,6 +86,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
assertEquals(msg.getString("bigString"), bigString);
|
assertEquals(msg.getString("bigString"), bigString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testGetBoolean() throws JMSException {
|
public void testGetBoolean() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setBoolean(name, true);
|
msg.setBoolean(name, true);
|
||||||
|
@ -119,6 +100,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
assertTrue(msg.getBoolean(name));
|
assertTrue(msg.getBoolean(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testGetByte() throws JMSException {
|
public void testGetByte() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setByte(this.name, (byte) 1);
|
msg.setByte(this.name, (byte) 1);
|
||||||
|
@ -126,108 +108,85 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
assertTrue(msg.getByte(this.name) == (byte) 1);
|
assertTrue(msg.getByte(this.name) == (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetShort() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetShort() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setShort(this.name, (short) 1);
|
msg.setShort(this.name, (short) 1);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getShort(this.name) == (short) 1);
|
assertTrue(msg.getShort(this.name) == (short) 1);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetChar() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetChar() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setChar(this.name, 'a');
|
msg.setChar(this.name, 'a');
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getChar(this.name) == 'a');
|
assertTrue(msg.getChar(this.name) == 'a');
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetInt() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetInt() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setInt(this.name, 1);
|
msg.setInt(this.name, 1);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getInt(this.name) == 1);
|
assertTrue(msg.getInt(this.name) == 1);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetLong() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetLong() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setLong(this.name, 1);
|
msg.setLong(this.name, 1);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getLong(this.name) == 1);
|
assertTrue(msg.getLong(this.name) == 1);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFloat() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetFloat() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setFloat(this.name, 1.5f);
|
msg.setFloat(this.name, 1.5f);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getFloat(this.name) == 1.5f);
|
assertTrue(msg.getFloat(this.name) == 1.5f);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetDouble() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetDouble() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
msg.setDouble(this.name, 1.5);
|
msg.setDouble(this.name, 1.5);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertTrue(msg.getDouble(this.name) == 1.5);
|
assertTrue(msg.getDouble(this.name) == 1.5);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetString() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetString() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
String str = "test";
|
String str = "test";
|
||||||
msg.setString(this.name, str);
|
msg.setString(this.name, str);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
assertEquals(msg.getString(this.name), str);
|
assertEquals(msg.getString(this.name), str);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetBytes() {
|
@Test(timeout = 10000)
|
||||||
|
public void testGetBytes() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
try {
|
|
||||||
byte[] bytes1 = new byte[3];
|
byte[] bytes1 = new byte[3];
|
||||||
byte[] bytes2 = new byte[2];
|
byte[] bytes2 = new byte[2];
|
||||||
|
|
||||||
System.arraycopy(bytes1, 0, bytes2, 0, 2);
|
System.arraycopy(bytes1, 0, bytes2, 0, 2);
|
||||||
msg.setBytes(this.name, bytes1);
|
msg.setBytes(this.name, bytes1);
|
||||||
msg.setBytes(this.name + "2", bytes1, 0, 2);
|
msg.setBytes(this.name + "2", bytes1, 0, 2);
|
||||||
msg = (ActiveMQMapMessage) msg.copy();
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
|
|
||||||
assertTrue(Arrays.equals(msg.getBytes(this.name), bytes1));
|
assertTrue(Arrays.equals(msg.getBytes(this.name), bytes1));
|
||||||
assertEquals(msg.getBytes(this.name + "2").length, bytes2.length);
|
assertEquals(msg.getBytes(this.name + "2").length, bytes2.length);
|
||||||
} catch (JMSException jmsEx) {
|
|
||||||
jmsEx.printStackTrace();
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
|
public void testGetBytesWithNullValue() throws JMSException {
|
||||||
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
|
assertNull(msg.getBytes(this.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testGetObject() throws JMSException {
|
public void testGetObject() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
Boolean booleanValue = Boolean.TRUE;
|
Boolean booleanValue = Boolean.TRUE;
|
||||||
|
@ -300,6 +259,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testGetMapNames() throws JMSException {
|
public void testGetMapNames() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setBoolean("boolean", true);
|
msg.setBoolean("boolean", true);
|
||||||
|
@ -335,6 +295,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
assertTrue(mapNamesList.contains("string"));
|
assertTrue(mapNamesList.contains("string"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testItemExists() throws JMSException {
|
public void testItemExists() throws JMSException {
|
||||||
ActiveMQMapMessage mapMessage = new ActiveMQMapMessage();
|
ActiveMQMapMessage mapMessage = new ActiveMQMapMessage();
|
||||||
|
|
||||||
|
@ -346,6 +307,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
assertFalse(mapMessage.itemExists("doesntExist"));
|
assertFalse(mapMessage.itemExists("doesntExist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testClearBody() throws JMSException {
|
public void testClearBody() throws JMSException {
|
||||||
ActiveMQMapMessage mapMessage = new ActiveMQMapMessage();
|
ActiveMQMapMessage mapMessage = new ActiveMQMapMessage();
|
||||||
mapMessage.setString("String", "String");
|
mapMessage.setString("String", "String");
|
||||||
|
@ -363,6 +325,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
mapMessage.getString("String");
|
mapMessage.getString("String");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testReadOnlyBody() throws JMSException {
|
public void testReadOnlyBody() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setBoolean("boolean", true);
|
msg.setBoolean("boolean", true);
|
||||||
|
@ -457,6 +420,7 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
public void testWriteOnlyBody() throws JMSException {
|
public void testWriteOnlyBody() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
msg.setReadOnlyBody(false);
|
msg.setReadOnlyBody(false);
|
||||||
|
@ -488,5 +452,4 @@ public class ActiveMQMapMessageTest extends TestCase {
|
||||||
msg.getShort("short");
|
msg.getShort("short");
|
||||||
msg.getString("string");
|
msg.getString("string");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue