diff options
author | Martin Ritchie <ritchiem@apache.org> | 2006-12-15 08:33:10 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2006-12-15 08:33:10 +0000 |
commit | a96152eea7e7ce48bb9340f477f3935744ee5ea6 (patch) | |
tree | ada0a6c314add42f32e5143e298c010ecc4b997c /java/client | |
parent | b6e573a5889ff89ccceeab3d3dc0504157a8c285 (diff) | |
download | qpid-python-a96152eea7e7ce48bb9340f477f3935744ee5ea6.tar.gz |
QPID-181 QPID-180
AbstractJMSMessage.java - updated to use getJMSHeaders
JMSMapMessage.java - JMSPropertyFieldTable.java - Moved functionality of setting and retrieving a JMS property. Now shared by the Headers and MapMessageTest.java
MapMessageTest.java - Updated the exceptions that are caught as all methods should throw a JMSException i.e. MessageFormatException
TextMessageTest.java - Added tests for the Message Properties
common/pom.xml - Added JMS dependency for the JMSPropertyFieldTable.java and associated tests
EncodingUtils.java - changed comments and changed getencodedCharLength return to an int
PropertyFieldTable.java - Cleaned up and now uses enum for prefixs. Created comprehensive test of both PropertyFieldTable classes.
AMQPInvalidClassException.java - created to throw a runtime exception when trying to add a non-primative value. Forcing clients to handle this would break the Map usage of the FieldTable.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@487481 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client')
5 files changed, 424 insertions, 299 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java index c1ed88b167..978b74e789 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java @@ -32,11 +32,13 @@ import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.JmsNotImplementedException; import org.apache.qpid.framing.BasicContentHeaderProperties; import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.framing.JMSPropertyFieldTable; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageNotReadableException; import javax.jms.MessageNotWriteableException; +import javax.jms.MessageFormatException; import java.util.Collections; import java.util.Enumeration; import java.util.Map; @@ -234,7 +236,7 @@ public abstract class AbstractJMSMessage extends AMQMessage implements javax.jms public void clearProperties() throws JMSException { - getJmsContentHeaderProperties().getHeaders().clear(); + getJmsContentHeaderProperties().getJMSHeaders().clear(); _readableProperties = false; } @@ -249,135 +251,136 @@ public abstract class AbstractJMSMessage extends AMQMessage implements javax.jms public boolean propertyExists(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().propertyExists(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().propertyExists(propertyName); } public boolean getBooleanProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getBoolean(propertyName); + + return getJmsContentHeaderProperties().getJMSHeaders().getBoolean(propertyName); } public byte getByteProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getByte(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getByte(propertyName); } public short getShortProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getShort(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getShort(propertyName); } public int getIntProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getInteger(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getInteger(propertyName); } public long getLongProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getLong(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getLong(propertyName); } public float getFloatProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getFloat(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getFloat(propertyName); } public double getDoubleProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getDouble(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getDouble(propertyName); } public String getStringProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getString(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getString(propertyName); } public Object getObjectProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - return getJmsContentHeaderProperties().getHeaders().getObject(propertyName); + return getJmsContentHeaderProperties().getJMSHeaders().getObject(propertyName); } public Enumeration getPropertyNames() throws JMSException { - return getJmsContentHeaderProperties().getHeaders().getPropertyNames(); + return getJmsContentHeaderProperties().getJMSHeaders().getPropertyNames(); } public void setBooleanProperty(String propertyName, boolean b) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setBoolean(propertyName, b); + getJmsContentHeaderProperties().getJMSHeaders().setBoolean(propertyName, b); } public void setByteProperty(String propertyName, byte b) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setByte(propertyName, new Byte(b)); + getJmsContentHeaderProperties().getJMSHeaders().setByte(propertyName, new Byte(b)); } public void setShortProperty(String propertyName, short i) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setShort(propertyName, new Short(i)); + getJmsContentHeaderProperties().getJMSHeaders().setShort(propertyName, new Short(i)); } public void setIntProperty(String propertyName, int i) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setInteger(propertyName, new Integer(i)); + getJmsContentHeaderProperties().getJMSHeaders().setInteger(propertyName, new Integer(i)); } public void setLongProperty(String propertyName, long l) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setLong(propertyName, new Long(l)); + getJmsContentHeaderProperties().getJMSHeaders().setLong(propertyName, new Long(l)); } public void setFloatProperty(String propertyName, float f) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setFloat(propertyName, new Float(f)); + getJmsContentHeaderProperties().getJMSHeaders().setFloat(propertyName, new Float(f)); } public void setDoubleProperty(String propertyName, double v) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setDouble(propertyName, new Double(v)); + getJmsContentHeaderProperties().getJMSHeaders().setDouble(propertyName, new Double(v)); } public void setStringProperty(String propertyName, String value) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setString(propertyName, value); + getJmsContentHeaderProperties().getJMSHeaders().setString(propertyName, value); } public void setObjectProperty(String propertyName, Object object) throws JMSException { checkWritableProperties(); checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().setObject(propertyName, object); + getJmsContentHeaderProperties().getJMSHeaders().setObject(propertyName, object); } protected void removeProperty(String propertyName) throws JMSException { checkPropertyName(propertyName); - getJmsContentHeaderProperties().getHeaders().remove(propertyName); + getJmsContentHeaderProperties().getJMSHeaders().remove(propertyName); } public void acknowledge() throws JMSException @@ -426,13 +429,13 @@ public abstract class AbstractJMSMessage extends AMQMessage implements javax.jms buf.append("\nJMS reply to: ").append(String.valueOf(getJMSReplyTo())); buf.append("\nAMQ message number: ").append(_deliveryTag); buf.append("\nProperties:"); - if (getJmsContentHeaderProperties().getHeaders().isEmpty()) + if (getJmsContentHeaderProperties().getJMSHeaders().isEmpty()) { buf.append("<NONE>"); } else { - buf.append('\n').append(getJmsContentHeaderProperties().getHeaders()); + buf.append('\n').append(getJmsContentHeaderProperties().getJMSHeaders()); } return buf.toString(); } @@ -462,9 +465,6 @@ public abstract class AbstractJMSMessage extends AMQMessage implements javax.jms { throw new IllegalArgumentException("Property name must not be the empty string"); } - - // Call to ensure that the it has been set. - getJmsContentHeaderProperties().getHeaders(); } public BasicContentHeaderProperties getJmsContentHeaderProperties() 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 1f084b8de3..fccce92dee 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 @@ -25,6 +25,8 @@ 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.framing.JMSPropertyFieldTable; +import org.apache.qpid.framing.AMQFrameDecodingException; import org.apache.qpid.AMQException; import org.apache.log4j.Logger; @@ -39,7 +41,7 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa public static final String MIME_TYPE = "jms/map-message"; - private PropertyFieldTable _map; + private JMSPropertyFieldTable _properties; JMSMapMessage() throws JMSException { @@ -49,16 +51,9 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa JMSMapMessage(ByteBuffer data) throws JMSException { super(data); // this instantiates a content header - _map = new PropertyFieldTable(); + _properties = new JMSPropertyFieldTable(); } - - @Override - public void clearBodyImpl() throws JMSException { - super.clearBodyImpl(); - _map = new PropertyFieldTable(); - } - JMSMapMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data) throws AMQException { @@ -68,19 +63,33 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa { long tableSize = EncodingUtils.readInteger(_data); - _map = (PropertyFieldTable) FieldTableFactory.newFieldTable(_data, tableSize); - + try + { + _properties = new JMSPropertyFieldTable(_data, tableSize); + } + catch (JMSException e) + { + Exception error = e.getLinkedException(); + if (error instanceof AMQFrameDecodingException) + { + throw(AMQFrameDecodingException) error; + } + else + { + throw new AMQException(e.getMessage(), e); + } + } } else { - _map = (PropertyFieldTable) FieldTableFactory.newFieldTable(); + _properties = new JMSPropertyFieldTable(); } } public String toBodyString() throws JMSException { - return "MapSize:" + _map.getEncodedSize() + "\nMapData:\n" + _map.toString(); + return _properties.toString(); } public String getMimeType() @@ -88,81 +97,40 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa return MIME_TYPE; } - // MapMessage Interface - public boolean getBoolean(String string) throws JMSException + public ByteBuffer getData() { - Boolean b = _map.getBoolean(string); - - if (b == null) - { - if (_map.containsKey(string)) - { - Object str = _map.getObject(string); + //What if _data is null? + _properties.writeToBuffer(_data); + return super.getData(); + } - 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); - } - } + @Override + public void clearBodyImpl() throws JMSException + { + super.clearBodyImpl(); + _properties.clear(); + } - return b; + public boolean getBoolean(String string) throws JMSException + { + return _properties.getBoolean(string); } public byte getByte(String string) throws JMSException { - Byte b = _map.getByte(string); - if (b == null) - { - 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; + return _properties.getByte(string); } public short getShort(String string) throws JMSException { - { - Short s = _map.getShort(string); - - if (s == null) - { - s = Short.valueOf(getByte(string)); - } - - return s; - } + return _properties.getShort(string); } public char getChar(String string) throws JMSException { - Character result = _map.getCharacter(string); + Character result = _properties.getCharacter(string); if (result == null) { @@ -176,179 +144,97 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa public int getInt(String string) throws JMSException { - Integer i = _map.getInteger(string); - - if (i == null) - { - i = Integer.valueOf(getShort(string)); - } - - return i; + return _properties.getInteger(string); } public long getLong(String string) throws JMSException { - - Long l = _map.getLong(string); - - if (l == null) - { - l = Long.valueOf(getInt(string)); - } - - return l; - + return _properties.getLong(string); } public float getFloat(String string) throws JMSException { - - Float f = _map.getFloat(string); - - if (f == null) - { - 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; - + return _properties.getFloat(string); } public double getDouble(String string) throws JMSException { - Double d = _map.getDouble(string); - - if (d == null) - { - d = Double.valueOf(getFloat(string)); - } - - return d; + return _properties.getDouble(string); } public String getString(String string) throws JMSException { - String s = _map.getString(string); - - if (s == null) - { - 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; + return _properties.getString(string); } public byte[] getBytes(String string) throws JMSException { - - byte[] result = _map.getBytes(string); - - if (result == null) - { - throw new MessageFormatException("getBytes couldn't find " + string + " item."); - } - - return result; - + return _properties.getBytes(string); } public Object getObject(String string) throws JMSException { - return _map.getObject(string); + return _properties.getObject(string); } public Enumeration getMapNames() throws JMSException { - return _map.getPropertyNames(); + return _properties.getMapNames(); } + public void setBoolean(String string, boolean b) throws JMSException { checkWritable(); - _map.setBoolean(string, b); + _properties.setBoolean(string, b); } public void setByte(String string, byte b) throws JMSException { checkWritable(); - _map.setByte(string, b); + _properties.setByte(string, b); } public void setShort(String string, short i) throws JMSException { checkWritable(); - _map.setShort(string, i); + _properties.setShort(string, i); } public void setChar(String string, char c) throws JMSException { checkWritable(); - _map.setChar(string, c); + _properties.setChar(string, c); } public void setInt(String string, int i) throws JMSException { checkWritable(); - _map.setInteger(string, i); + _properties.setInteger(string, i); } public void setLong(String string, long l) throws JMSException { checkWritable(); - _map.setLong(string, l); + _properties.setLong(string, l); } public void setFloat(String string, float v) throws JMSException { checkWritable(); - _map.setFloat(string, v); + _properties.setFloat(string, v); } public void setDouble(String string, double v) throws JMSException { checkWritable(); - _map.setDouble(string, v); + _properties.setDouble(string, v); } public void setString(String string, String string1) throws JMSException { checkWritable(); - _map.setString(string, string1); + _properties.setString(string, string1); } public void setBytes(String string, byte[] bytes) throws JMSException @@ -359,25 +245,18 @@ public class JMSMapMessage extends JMSBytesMessage implements javax.jms.MapMessa public void setBytes(String string, byte[] bytes, int i, int i1) throws JMSException { checkWritable(); - _map.setBytes(string, bytes, i, i1); + _properties.setBytes(string, bytes, i, i1); } public void setObject(String string, Object object) throws JMSException { checkWritable(); - _map.setObject(string, object); + _properties.setObject(string, object); } public boolean itemExists(String string) throws JMSException { - return _map.itemExists(string); - } - - public ByteBuffer getData() - { - //What if _data is null? - _map.writeToBuffer(_data); - return super.getData(); + return _properties.itemExists(string); } } 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 1a469c1d12..823406daa4 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 @@ -166,12 +166,12 @@ public class MapMessageTest extends TestCase implements MessageListener testMapValues(m, count); - testMessageWriteStatus(m); - testPropertyWriteStatus(m); testCorrectExceptions(m); + testMessageWriteStatus(m); + count++; } } @@ -207,9 +207,9 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } @@ -217,9 +217,9 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } @@ -228,7 +228,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -238,18 +238,18 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } try { m.getLong("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } @@ -258,9 +258,9 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } @@ -268,9 +268,9 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (NumberFormatException nfe) + catch (MessageFormatException nfe) { //normal execution } @@ -278,7 +278,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("message"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -295,7 +295,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -305,7 +305,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -318,7 +318,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -333,7 +333,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -343,7 +343,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -353,7 +353,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("short"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -370,7 +370,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -380,7 +380,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -390,7 +390,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -401,7 +401,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -411,7 +411,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -424,7 +424,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -434,7 +434,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -444,7 +444,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("long"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -461,7 +461,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -471,7 +471,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -481,7 +481,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -492,7 +492,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -502,7 +502,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -511,7 +511,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getLong("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -522,7 +522,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -536,7 +536,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("double"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -554,7 +554,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -564,7 +564,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -574,7 +574,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -585,7 +585,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -595,7 +595,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -604,7 +604,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getLong("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -620,7 +620,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("float"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -638,7 +638,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -648,7 +648,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -658,7 +658,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -669,7 +669,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -684,7 +684,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -694,7 +694,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -704,7 +704,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("int"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -722,7 +722,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -732,7 +732,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -742,7 +742,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -754,7 +754,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -763,7 +763,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getLong("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -774,7 +774,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -784,7 +784,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -794,7 +794,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("char"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -810,7 +810,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -820,7 +820,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -830,7 +830,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -841,7 +841,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -851,7 +851,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -861,7 +861,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getLong("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -872,7 +872,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -882,7 +882,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -895,7 +895,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getString("bytes"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -911,7 +911,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBoolean("byte"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -926,7 +926,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("byte"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -942,7 +942,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("byte"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -952,7 +952,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("byte"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -962,7 +962,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("byte"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -982,7 +982,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getByte("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -993,7 +993,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getShort("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1003,9 +1003,9 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getChar("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } - catch (MessageFormatException nfe) + catch (MessageFormatException npe) { //normal execution } @@ -1013,7 +1013,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getInt("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1023,7 +1023,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getLong("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1033,7 +1033,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getFloat("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1043,7 +1043,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getDouble("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1053,7 +1053,7 @@ public class MapMessageTest extends TestCase implements MessageListener try { m.getBytes("odd"); - fail("Exception Expected."); + fail("MessageFormatException expected as value doesn't exist."); } catch (MessageFormatException nfe) { @@ -1224,7 +1224,6 @@ 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 e5458fd89e..58e62e8252 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 @@ -206,7 +206,7 @@ public class MapMessageTest extends TestCase mm.getByte("random"); Assert.fail("MessageFormatException expected"); } - catch (NumberFormatException e) + catch (MessageFormatException e) { //normal execution } @@ -295,9 +295,9 @@ public class MapMessageTest extends TestCase { JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); mm.getInt("random"); - Assert.fail("NumberFormatException should be received."); + Assert.fail("MessageFormatException should be received."); } - catch (NumberFormatException e) + catch (MessageFormatException e) { //normal execution } @@ -313,9 +313,9 @@ public class MapMessageTest extends TestCase { JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); mm.getLong("random"); - Assert.fail("NumberFormatException should be received."); + Assert.fail("MessageFormatException should be received."); } - catch (NumberFormatException e) + catch (MessageFormatException e) { //normal execution } @@ -331,9 +331,9 @@ public class MapMessageTest extends TestCase { JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); mm.getShort("random"); - Assert.fail("NumberFormatException should be received."); + Assert.fail("MessageFormatException should be received."); } - catch (NumberFormatException e) + catch (MessageFormatException e) { //normal execution } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java index 337b0f3bbc..1345c0defb 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java @@ -22,8 +22,13 @@ package org.apache.qpid.test.unit.client.message; import org.apache.qpid.client.message.TestMessageHelper; import org.apache.qpid.client.message.JMSTextMessage; +import org.apache.qpid.client.message.JMSMapMessage; import junit.framework.TestCase; +import junit.framework.Assert; + +import javax.jms.JMSException; +import javax.jms.MessageFormatException; public class TextMessageTest extends TestCase { @@ -47,6 +52,248 @@ public class TextMessageTest extends TestCase assertEquals(val, "Banana"); } + + public void testBooleanPropertyLookup() + { + try + { + JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); + + tm.setBooleanProperty("value", true); + Assert.assertEquals(true, tm.getBooleanProperty("value")); + Assert.assertEquals("true", tm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testBytePropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setByteProperty("value", Byte.MAX_VALUE); + + Assert.assertEquals(Byte.MAX_VALUE, mm.getByteProperty("value")); + Assert.assertEquals((short) Byte.MAX_VALUE, mm.getShortProperty("value")); + Assert.assertEquals(Byte.MAX_VALUE, mm.getIntProperty("value")); + Assert.assertEquals((long) Byte.MAX_VALUE, mm.getLongProperty("value")); + Assert.assertEquals("" + Byte.MAX_VALUE, mm.getStringProperty("value")); + + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testShortPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setShortProperty("value", Short.MAX_VALUE); + Assert.assertEquals(Short.MAX_VALUE, mm.getShortProperty("value")); + Assert.assertEquals((int) Short.MAX_VALUE, mm.getIntProperty("value")); + Assert.assertEquals((long) Short.MAX_VALUE, mm.getLongProperty("value")); + Assert.assertEquals("" + Short.MAX_VALUE, mm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testDoublePropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setDoubleProperty("value", Double.MAX_VALUE); + Assert.assertEquals(Double.MAX_VALUE, mm.getDoubleProperty("value")); + Assert.assertEquals("" + Double.MAX_VALUE, mm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testFloatPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setFloatProperty("value", Float.MAX_VALUE); + Assert.assertEquals(Float.MAX_VALUE, mm.getFloatProperty("value")); + Assert.assertEquals((double) Float.MAX_VALUE, mm.getDoubleProperty("value")); + Assert.assertEquals("" + Float.MAX_VALUE, mm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testIntPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setIntProperty("value", Integer.MAX_VALUE); + Assert.assertEquals(Integer.MAX_VALUE, mm.getIntProperty("value")); + Assert.assertEquals((long) Integer.MAX_VALUE, mm.getLongProperty("value")); + Assert.assertEquals("" + Integer.MAX_VALUE, mm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testLongPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.setLongProperty("value", Long.MAX_VALUE); + Assert.assertEquals(Long.MAX_VALUE, mm.getLongProperty("value")); + Assert.assertEquals("" + Long.MAX_VALUE, mm.getStringProperty("value")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + + // Failed Lookups + + public void testFailedBooleanPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + Assert.assertEquals(false, mm.getBooleanProperty("int")); + } + catch (JMSException e) + { + Assert.fail("JMSException received." + e); + } + } + + public void testFailedBytePropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getByteProperty("random"); + Assert.fail("MessageFormatException expected"); + } + catch (MessageFormatException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + + } + + public void testFailedDoublePropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getDoubleProperty("random"); + Assert.fail("NullPointerException should be received."); + } + catch (NullPointerException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + } + + public void testFailedFloatPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getFloatProperty("random"); + Assert.fail("NullPointerException should be received."); + } + catch (NullPointerException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + } + + public void testFailedIntPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getIntProperty("random"); + Assert.fail("MessageFormatException should be received."); + } + catch (MessageFormatException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + } + + public void testFailedLongPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getLongProperty("random"); + Assert.fail("MessageFormatException should be received."); + } + catch (MessageFormatException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + } + + public void testFailedShortPropertyLookup() + { + try + { + JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); + mm.getShortProperty("random"); + Assert.fail("MessageFormatException should be received."); + } + catch (MessageFormatException e) + { + //normal execution + } + catch (JMSException e) + { + Assert.fail("JMSException received:" + e); + } + } + + public static junit.framework.Test suite() { return new junit.framework.TestSuite(TextMessageTest.class); |