summaryrefslogtreecommitdiff
path: root/java/client/src
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2006-12-12 17:51:51 +0000
committerMartin Ritchie <ritchiem@apache.org>2006-12-12 17:51:51 +0000
commit853cf049a66ed4fa727bd2c7c46e0beabeb33a33 (patch)
tree37fdacf14af9a3073cdc8f99b777327b826b8833 /java/client/src
parentb10ee442673d6d9c8abb46bd7a0606364930130d (diff)
downloadqpid-python-853cf049a66ed4fa727bd2c7c46e0beabeb33a33.tar.gz
QPID-164
JMSMapMessage.java - fixed incorrect exceptions and return values. Data now sent as a Bytes message. MapMessageTest.java - updated to be more through with the testing of the returned message EncodingUtils.java - added unsignedIntegerLength() FieldTableFactory.java - removed specific PropertyFieldTable reference PropertyFieldTable.java - fixed encoding issues that were causing BufferOverflow errors. PropertyFieldTableTest.java - added test to ensure that the encoding size is correct for ALL types. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@486254 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java177
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessageFactory.java2
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java1128
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java14
4 files changed, 1176 insertions, 145 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
index 5282dce4c9..85d434e4eb 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessage.java
@@ -21,16 +21,21 @@
package org.apache.qpid.client.message;
import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
import org.apache.qpid.framing.PropertyFieldTable;
import org.apache.qpid.framing.FieldTableFactory;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.EncodingUtils;
import org.apache.qpid.AMQException;
+import org.apache.log4j.Logger;
import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
import java.util.Enumeration;
-public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessage
+public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessage
{
+ private static final Logger _logger = Logger.getLogger(JMSMapMessage.class);
+
public static final String MIME_TYPE = "jms/map-message";
@@ -38,48 +43,38 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
JMSMapMessage() throws JMSException
{
- this(null, null);
+ this(null);
}
- JMSMapMessage(ByteBuffer data, String encoding) throws JMSException
+ JMSMapMessage(ByteBuffer data) throws JMSException
{
super(data); // this instantiates a content header
- getJmsContentHeaderProperties().setContentType(MIME_TYPE);
- getJmsContentHeaderProperties().setEncoding(encoding);
_map = new PropertyFieldTable();
}
- JMSMapMessage(long deliveryTag, BasicContentHeaderProperties contentHeader, ByteBuffer data)
+ JMSMapMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data)
throws AMQException
{
- super(deliveryTag, contentHeader, data);
- contentHeader.setContentType(MIME_TYPE);
+ super(messageNbr, contentHeader, data);
- try
- {
- _map = FieldTableFactory.newFieldTable(getText());
- }
- catch (JMSException e)
+ if (data != null)
{
- throw new AMQException(e.getMessage(), e);
- }
- }
- // AbstractJMSMessage Interface
+ long tableSize = EncodingUtils.readInteger(_data);
+ _map = (PropertyFieldTable) FieldTableFactory.newFieldTable(_data, tableSize);
- public void clearBodyImpl() throws JMSException
- {
- if (_data != null)
+ }
+ else
{
- _data.release();
+ _map = (PropertyFieldTable) FieldTableFactory.newFieldTable();
}
- _data = null;
}
+
public String toBodyString() throws JMSException
{
- return _map.toString();
+ return "MapSize:" + _map.getEncodedSize() + "\nMapData:\n" + _map.toString();
}
public String getMimeType()
@@ -95,7 +90,23 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
if (b == null)
{
- b = Boolean.valueOf(_map.getString(string));
+ if (_map.containsKey(string))
+ {
+ Object str = _map.getObject(string);
+
+ if (str == null || !(str instanceof String))
+ {
+ throw new MessageFormatException("getBoolean can't use " + string + " item.");
+ }
+ else
+ {
+ return Boolean.valueOf((String) str);
+ }
+ }
+ else
+ {
+ b = Boolean.valueOf(null);
+ }
}
return b;
@@ -106,26 +117,55 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
Byte b = _map.getByte(string);
if (b == null)
{
- b = Byte.valueOf(_map.getString(string));
+ if (_map.containsKey(string))
+ {
+ Object str = _map.getObject(string);
+
+ if (str == null || !(str instanceof String))
+ {
+ throw new MessageFormatException("getByte can't use " + string + " item.");
+ }
+ else
+ {
+ return Byte.valueOf((String) str);
+ }
+ }
+ else
+ {
+ b = Byte.valueOf(null);
+ }
}
+
return b;
}
public short getShort(String string) throws JMSException
{
- Short s = _map.getShort(string);
-
- if (s == null)
{
- s = Short.valueOf(getByte(string));
- }
+ Short s = _map.getShort(string);
- return s;
+ if (s == null)
+ {
+ s = Short.valueOf(getByte(string));
+ }
+
+ return s;
+ }
}
public char getChar(String string) throws JMSException
{
- return _map.getCharacter(string);
+
+ Character result = _map.getCharacter(string);
+
+ if (result == null)
+ {
+ throw new MessageFormatException("getChar couldn't find " + string + " item.");
+ }
+ else
+ {
+ return result;
+ }
}
public int getInt(String string) throws JMSException
@@ -142,6 +182,7 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
public long getLong(String string) throws JMSException
{
+
Long l = _map.getLong(string);
if (l == null)
@@ -150,18 +191,38 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
}
return l;
+
}
public float getFloat(String string) throws JMSException
{
+
Float f = _map.getFloat(string);
if (f == null)
{
- f = Float.valueOf(_map.getString(string));
+ if (_map.containsKey(string))
+ {
+ Object str = _map.getObject(string);
+
+ if (str == null || !(str instanceof String))
+ {
+ throw new MessageFormatException("getFloat can't use " + string + " item.");
+ }
+ else
+ {
+ return Float.valueOf((String) str);
+ }
+ }
+ else
+ {
+ f = Float.valueOf(null);
+ }
+
}
return f;
+
}
public double getDouble(String string) throws JMSException
@@ -182,8 +243,25 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
if (s == null)
{
- Object o = _map.getObject(string);
- s = o.toString();
+ if (_map.containsKey(string))
+ {
+ Object o = _map.getObject(string);
+ if (o instanceof byte[])
+ {
+ throw new MessageFormatException("getObject couldn't find " + string + " item.");
+ }
+ else
+ {
+ if (o == null)
+ {
+ return null;
+ }
+ else
+ {
+ s = String.valueOf(o);
+ }
+ }
+ }
}
return s;
@@ -191,7 +269,16 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
public byte[] getBytes(String string) throws JMSException
{
- return _map.getBytes(string);
+
+ byte[] result = _map.getBytes(string);
+
+ if (result == null)
+ {
+ throw new MessageFormatException("getBytes couldn't find " + string + " item.");
+ }
+
+ return result;
+
}
public Object getObject(String string) throws JMSException
@@ -282,19 +369,9 @@ public class JMSMapMessage extends JMSTextMessage implements javax.jms.MapMessag
public ByteBuffer getData()
{
-
- try
- {
- setText(toString());
- return super.getData();
- }
- catch (JMSException e)
- {
- // should never occur according to setText
- //fixme -- what to do if it does occur.
- }
-
- return ByteBuffer.allocate(0);
+ //What if _data is null?
+ _map.writeToBuffer(_data);
+ return super.getData();
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessageFactory.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessageFactory.java
index 8d17f2bbf0..38b8b67ff9 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessageFactory.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSMapMessageFactory.java
@@ -36,6 +36,6 @@ public class JMSMapMessageFactory extends AbstractJMSMessageFactory
protected AbstractJMSMessage createMessage(long deliveryTag, ByteBuffer data, ContentHeaderBody contentHeader) throws AMQException
{
- return new JMSMapMessage(deliveryTag, (BasicContentHeaderProperties) contentHeader.properties, data);
+ return new JMSMapMessage(deliveryTag, contentHeader, data);
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
index 6fbc4809eb..24cc1b6259 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
@@ -21,14 +21,11 @@
package org.apache.qpid.test.unit.basic;
import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.message.JMSTextMessage;
import org.apache.qpid.client.message.JMSMapMessage;
import org.apache.qpid.testutil.VMBrokerSetup;
+import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Iterator;
@@ -40,20 +37,26 @@ import junit.framework.Assert;
public class MapMessageTest extends TestCase implements MessageListener
{
+
+ private static final Logger _logger = Logger.getLogger(MapMessageTest.class);
+
private AMQConnection _connection;
private Destination _destination;
private AMQSession _session;
private final List<JMSMapMessage> received = new ArrayList<JMSMapMessage>();
- private final List<String> messages = new ArrayList<String>();
+
+ private static final String MESSAGE = "Message ";
private int _count = 100;
public String _connectionString = "vm://:1";
private byte[] _bytes = {99, 98, 97, 96, 95};
+ private static final float _smallfloat = 100.0f;
protected void setUp() throws Exception
{
super.setUp();
try
{
+ //TransportConnection.createVMBroker(1);
init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
}
catch (Exception e)
@@ -64,7 +67,9 @@ public class MapMessageTest extends TestCase implements MessageListener
protected void tearDown() throws Exception
{
+ _logger.info("Tearing Down unit.basic.MapMessageTest");
super.tearDown();
+ //TransportConnection.killAllVMBrokers();
}
private void init(AMQConnection connection) throws Exception
@@ -90,7 +95,6 @@ public class MapMessageTest extends TestCase implements MessageListener
send(count);
waitFor(count);
check();
- System.out.println("Completed without failure");
_connection.close();
}
@@ -100,38 +104,45 @@ public class MapMessageTest extends TestCase implements MessageListener
MessageProducer producer = _session.createProducer(_destination);
for (int i = 0; i < count; i++)
{
- String text = "Message " + i;
- messages.add(text);
MapMessage message = _session.createMapMessage();
- message.setBoolean("odd", i / 2 == 0);
- message.setByte("byte", (byte) Byte.MAX_VALUE);
+ setMapValues(message, i);
- message.setBytes("bytes", _bytes);
- message.setChar("char", (char) 'c');
- message.setDouble("double", (double) Double.MAX_VALUE);
- message.setFloat("float", (float) Float.MAX_VALUE);
-
- message.setInt("messageNumber", i);
- message.setInt("int", (int) Integer.MAX_VALUE);
+ producer.send(message);
+ }
+ }
- message.setLong("long", (long) Long.MAX_VALUE);
- message.setShort("short", (short) Short.MAX_VALUE);
- message.setString("message", text);
+ private void setMapValues(MapMessage message, int i) throws JMSException
+ {
+ message.setBoolean("odd", i / 2 == 0);
+ message.setByte("byte", (byte) Byte.MAX_VALUE);
+ message.setBytes("bytes", _bytes);
+ message.setChar("char", (char) 'c');
+ message.setDouble("double", (double) Double.MAX_VALUE);
+ message.setFloat("float", (float) Float.MAX_VALUE);
+ message.setFloat("smallfloat", 100);
+ message.setInt("messageNumber", i);
+ message.setInt("int", (int) Integer.MAX_VALUE);
+ message.setLong("long", (long) Long.MAX_VALUE);
+ message.setShort("short", (short) Short.MAX_VALUE);
+ message.setString("message", MESSAGE + i);
+ //Test Setting Object Values
+ message.setObject("object-bool", true);
+ message.setObject("object-byte", Byte.MAX_VALUE);
+ message.setObject("object-bytes", _bytes);
+ message.setObject("object-char", 'c');
+ message.setObject("object-double", Double.MAX_VALUE);
+ message.setObject("object-float", Float.MAX_VALUE);
+ message.setObject("object-int", Integer.MAX_VALUE);
+ message.setObject("object-long", Long.MAX_VALUE);
+ message.setObject("object-short", Short.MAX_VALUE);
- message.setObject("object-bool", true);
- message.setObject("object-byte", Byte.MAX_VALUE);
- message.setObject("object-bytes", _bytes);
- message.setObject("object-char", 'c');
- message.setObject("object-double", Double.MAX_VALUE);
- message.setObject("object-float", Float.MAX_VALUE);
- message.setObject("object-int", Integer.MAX_VALUE);
- message.setObject("object-long", Long.MAX_VALUE);
- message.setObject("object-short", Short.MAX_VALUE);
+ //Set a null String value
+ message.setString("nullString", null);
+ // Highlight protocol problem
+ message.setString("emptyString", "");
- producer.send(message);
- }
}
void waitFor(int count) throws InterruptedException
@@ -152,80 +163,1016 @@ public class MapMessageTest extends TestCase implements MessageListener
for (JMSMapMessage m : received)
{
actual.add(m.getString("message"));
- assertEqual(m.getInt("messageNumber"), count);
+ testMapValues(m, count);
- assertEqual(count / 2 == 0, m.getBoolean("odd"));
- assertEqual((byte) Byte.MAX_VALUE, m.getByte("byte"));
+ testMessageWriteStatus(m);
- assertBytesEqual(_bytes, m.getBytes("bytes"));
- assertEqual((char) 'c', m.getChar("char"));
- assertEqual((double) Double.MAX_VALUE, m.getDouble("double"));
- assertEqual((float) Float.MAX_VALUE, m.getFloat("float"));
+ testPropertyWriteStatus(m);
- assertEqual(count, m.getInt("messageNumber"));
- assertEqual((int) Integer.MAX_VALUE, m.getInt("int"));
- assertEqual((long) Long.MAX_VALUE, m.getLong("long"));
- assertEqual((short) Short.MAX_VALUE, m.getShort("short"));
+ testCorrectExceptions(m);
- assertEqual(true, m.getObject("object-bool"));
- assertEqual(Byte.MAX_VALUE, m.getObject("object-byte"));
- assertBytesEqual(_bytes, (byte[]) m.getObject("object-bytes"));
- assertEqual('c', m.getObject("object-char"));
- assertEqual(Double.MAX_VALUE, m.getObject("object-double"));
- assertEqual(Float.MAX_VALUE, m.getObject("object-float"));
- assertEqual(Integer.MAX_VALUE, m.getObject("object-int"));
- assertEqual(Long.MAX_VALUE, m.getObject("object-long"));
- assertEqual(Short.MAX_VALUE, m.getObject("object-short"));
+ count++;
+ }
+ }
+ private void testCorrectExceptions(JMSMapMessage m) throws JMSException
+ {
+ testBoolean(m);
- try
- {
- m.setInt("testint", 3);
- fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- //normal execution
- }
+ testByte(m);
- m.clearBody();
+ testBytes(m);
- try
- {
- m.setInt("testint", 3);
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
+ testChar(m);
- //Check property write status
- try
- {
- m.setStringProperty("test", "test");
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- //normal execution
- }
+ testDouble(m);
- m.clearProperties();
+ testFloat(m);
- try
- {
- m.setStringProperty("test", "test");
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
+ testInt(m);
- count++;
+ testLong(m);
+
+ testShort(m);
+
+ testString(m);
+ }
+
+ private void testString(JMSMapMessage m) throws JMSException
+ {
+
+ Assert.assertFalse(m.getBoolean("message"));
+
+ try
+ {
+ m.getByte("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("message");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getInt("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+ try
+ {
+ m.getLong("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("message");
+ fail("Exception Expected.");
+ }
+ catch (NumberFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("message");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(MESSAGE + m.getInt("messageNumber"), m.getString("message"));
+ }
+
+ private void testShort(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(Short.MAX_VALUE, m.getShort("short"));
+
+ //Try bad reads
+ try
+ {
+ m.getChar("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(Short.MAX_VALUE, m.getInt("short"));
+
+ Assert.assertEquals(Short.MAX_VALUE, m.getLong("short"));
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("short");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Short.MAX_VALUE, m.getString("short"));
+ }
+
+ private void testLong(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
}
- assertEqual(messages.iterator(), actual.iterator());
+ try
+ {
+ m.getShort("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getInt("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(Long.MAX_VALUE, m.getLong("long"));
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("long");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Long.MAX_VALUE, m.getString("long"));
+ }
+
+ private void testDouble(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getInt("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ try
+ {
+ m.getLong("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+
+ Assert.assertEquals(Double.MAX_VALUE, m.getDouble("double"));
+
+ //Try bad reads
+ try
+ {
+ m.getBytes("double");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Double.MAX_VALUE, m.getString("double"));
+ }
+
+
+ private void testFloat(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getInt("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ try
+ {
+ m.getLong("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+
+ Assert.assertEquals(Float.MAX_VALUE, m.getFloat("float"));
+
+ Assert.assertEquals(_smallfloat, (float) m.getDouble("smallfloat"));
+
+ //Try bad reads
+ try
+ {
+ m.getBytes("float");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Float.MAX_VALUE, m.getString("float"));
+ }
+
+
+ private void testInt(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(Integer.MAX_VALUE, m.getInt("int"));
+
+ Assert.assertEquals(Integer.MAX_VALUE, (int) m.getLong("int"));
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("int");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Integer.MAX_VALUE, m.getString("int"));
+ }
+
+
+ private void testChar(JMSMapMessage m) throws JMSException
+ {
+
+ //Try bad reads
+ try
+ {
+ m.getBoolean("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals('c', m.getChar("char"));
+
+ try
+ {
+ m.getInt("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ try
+ {
+ m.getLong("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("char");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + 'c', m.getString("char"));
+ }
+
+ private void testBytes(JMSMapMessage m) throws JMSException
+ {
+ //Try bad reads
+ try
+ {
+ m.getBoolean("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getByte("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getShort("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getChar("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getInt("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ try
+ {
+ m.getLong("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+
+ assertBytesEqual(_bytes, m.getBytes("bytes"));
+
+ try
+ {
+ m.getString("bytes");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+
+ }
+
+ private void testByte(JMSMapMessage m) throws JMSException
+ {
+ //Try bad reads
+ try
+ {
+ m.getBoolean("byte");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals(Byte.MAX_VALUE, m.getByte("byte"));
+
+ Assert.assertEquals((short) Byte.MAX_VALUE, m.getShort("byte"));
+
+ //Try bad reads
+ try
+ {
+ m.getChar("byte");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Reading a byte as an int is ok
+ Assert.assertEquals((short) Byte.MAX_VALUE, m.getInt("byte"));
+
+ Assert.assertEquals((short) Byte.MAX_VALUE, m.getLong("byte"));
+
+ //Try bad reads
+ try
+ {
+ m.getFloat("byte");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("byte");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("byte");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + Byte.MAX_VALUE, m.getString("byte"));
+
+ }
+
+ private void testBoolean(JMSMapMessage m) throws JMSException
+ {
+
+ Assert.assertEquals((m.getInt("messageNumber") / 2) == 0, m.getBoolean("odd"));
+
+ //Try bad reads
+ try
+ {
+ m.getByte("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ //Try bad reads
+ try
+ {
+ m.getShort("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getChar("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getInt("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getLong("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getFloat("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getDouble("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+ //Try bad reads
+ try
+ {
+ m.getBytes("odd");
+ fail("Exception Expected.");
+ }
+ catch (MessageFormatException nfe)
+ {
+ //normal execution
+ }
+
+ Assert.assertEquals("" + ((m.getInt("messageNumber") / 2) == 0), m.getString("odd"));
+ }
+
+
+ private void testPropertyWriteStatus(JMSMapMessage m) throws JMSException
+ {
+ //Check property write status
+ try
+ {
+ m.setStringProperty("test", "test");
+ Assert.fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearProperties();
+
+ try
+ {
+ m.setStringProperty("test", "test");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+ }
+
+ private void testMessageWriteStatus(JMSMapMessage m) throws JMSException
+ {
+ try
+ {
+ m.setInt("testint", 3);
+ fail("Message should not be writeable");
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ //normal execution
+ }
+
+ m.clearBody();
+
+ try
+ {
+ m.setInt("testint", 3);
+ }
+ catch (MessageNotWriteableException mnwe)
+ {
+ Assert.fail("Message should be writeable");
+ }
+ }
+
+ private void testMapValues(JMSMapMessage m, int count) throws JMSException
+ {
+ //Test get<Primiative>
+
+ //Boolean
+ assertEqual(count / 2 == 0, m.getBoolean("odd"));
+ assertEqual("" + (count / 2 == 0), m.getString("odd"));
+
+ //Byte
+ assertEqual(Byte.MAX_VALUE, m.getByte("byte"));
+ assertEqual("" + Byte.MAX_VALUE, m.getString("byte"));
+
+ //Bytes
+ assertBytesEqual(_bytes, m.getBytes("bytes"));
+
+ //Char
+ assertEqual('c', m.getChar("char"));
+
+ //Double
+ assertEqual(Double.MAX_VALUE, m.getDouble("double"));
+ assertEqual("" + Double.MAX_VALUE, m.getString("double"));
+
+ //Float
+ assertEqual(Float.MAX_VALUE, m.getFloat("float"));
+ assertEqual(_smallfloat, (float) m.getDouble("smallfloat"));
+ assertEqual("" + Float.MAX_VALUE, m.getString("float"));
+
+ //Integer
+ assertEqual(Integer.MAX_VALUE, m.getInt("int"));
+ assertEqual("" + Integer.MAX_VALUE, m.getString("int"));
+ assertEqual(count, m.getInt("messageNumber"));
+
+ //long
+ assertEqual(Long.MAX_VALUE, m.getLong("long"));
+ assertEqual("" + Long.MAX_VALUE, m.getString("long"));
+
+ //Short
+ assertEqual(Short.MAX_VALUE, m.getShort("short"));
+ assertEqual("" + Short.MAX_VALUE, m.getString("short"));
+ assertEqual((int) Short.MAX_VALUE, m.getInt("short"));
+
+ //String
+ assertEqual(MESSAGE + count, m.getString("message"));
+
+ //Test getObjects
+ assertEqual(true, m.getObject("object-bool"));
+ assertEqual(Byte.MAX_VALUE, m.getObject("object-byte"));
+ assertBytesEqual(_bytes, (byte[]) m.getObject("object-bytes"));
+ assertEqual('c', m.getObject("object-char"));
+ assertEqual(Double.MAX_VALUE, m.getObject("object-double"));
+ assertEqual(Float.MAX_VALUE, m.getObject("object-float"));
+ assertEqual(Integer.MAX_VALUE, m.getObject("object-int"));
+ assertEqual(Long.MAX_VALUE, m.getObject("object-long"));
+ assertEqual(Short.MAX_VALUE, m.getObject("object-short"));
+
+ //Check Special values
+ assertTrue(m.getString("nullString") == null);
+ assertTrue(m.getString("emptyString") == null);
+ _logger.warn("An emptyString should not become a null string after transmission.");
+ //assertEqual("", m.getString("emptyString"));
}
private void assertBytesEqual(byte[] expected, byte[] actual)
@@ -279,6 +1226,7 @@ public class MapMessageTest extends TestCase implements MessageListener
{
synchronized(received)
{
+ _logger.info("****************** Recevied Messgage:" + (JMSMapMessage) message);
received.add((JMSMapMessage) message);
received.notify();
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java
index f55f2428ce..e5458fd89e 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java
@@ -25,6 +25,7 @@ import junit.framework.Assert;
import org.apache.qpid.framing.PropertyFieldTable;
import org.apache.qpid.client.message.JMSMapMessage;
import org.apache.qpid.client.message.TestMessageHelper;
+import org.apache.log4j.Logger;
import javax.jms.JMSException;
import javax.jms.MessageFormatException;
@@ -203,7 +204,7 @@ public class MapMessageTest extends TestCase
{
JMSMapMessage mm = TestMessageHelper.newJMSMapMessage();
mm.getByte("random");
- Assert.fail("NumberFormatException should be received.");
+ Assert.fail("MessageFormatException expected");
}
catch (NumberFormatException e)
{
@@ -221,7 +222,12 @@ public class MapMessageTest extends TestCase
try
{
JMSMapMessage mm = TestMessageHelper.newJMSMapMessage();
- Assert.assertEquals(null, mm.getBytes("random"));
+ mm.getBytes("random");
+ Assert.fail("MessageFormatException expected");
+ }
+ catch (MessageFormatException mfe)
+ {
+ //normal path
}
catch (JMSException e)
{
@@ -235,9 +241,9 @@ public class MapMessageTest extends TestCase
{
JMSMapMessage mm = TestMessageHelper.newJMSMapMessage();
mm.getChar("random");
- Assert.fail("NullPointerException should be received.");
+ Assert.fail("MessageFormatException expected");
}
- catch (NullPointerException e)
+ catch (MessageFormatException e)
{
//normal execution
}