summaryrefslogtreecommitdiff
path: root/qpid/java/common/src/test
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2006-12-05 18:37:18 +0000
committerMartin Ritchie <ritchiem@apache.org>2006-12-05 18:37:18 +0000
commit2e4d9c40a39cb0a89cfaae57a3aaca97ce133fbc (patch)
treeba5fd44f48a1519db1f6696bfdffc1d107df1e48 /qpid/java/common/src/test
parent3259d875114106fe2543e02d43b9562185de8226 (diff)
downloadqpid-python-2e4d9c40a39cb0a89cfaae57a3aaca97ce133fbc.tar.gz
FieldTable change.
FieldTable is now an interface with a PropertyFieldTable.java implementation. This PropertyFieldTable has been updated to handle the wire level encoding and decoding of the underlying map. It also allows XML encoding of the data as used by JMSMapMessage. Currently the AMQP doesn't support all the Java primitives as a result all values are written out as XML using a prefix of 'X'. (See QPID-9 for further details) Changes where not specified are changes from new FieldTable() to FieldTableFactory.newFieldTable() AbstractJMSMessage.java - the type prefixing of properties is now not requried as all the functionality has been moved to PropertyFieldTable.java. In addition set/getObjectProperty is now implemented as PFT does this. basic Tests have been updated to send all property values. FieldTableKeyEnumeration.java has been removed as it is nolonger required. The PFT handles this internally. ToDo: The Tests need to be consolidated so that there is a clear view of the code coverage. QPID-158 git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@482733 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/test')
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java117
1 files changed, 116 insertions, 1 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
index 5070b6ecb1..0b6820b8a9 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
@@ -25,6 +25,10 @@ import junit.framework.TestCase;
import java.util.Enumeration;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.ByteBufferProxy;
+import org.apache.mina.common.support.BaseByteBuffer;
+
public class PropertyFieldTableTest extends TestCase
{
@@ -206,7 +210,7 @@ public class PropertyFieldTableTest extends TestCase
PropertyFieldTable table2 = new PropertyFieldTable(table1XML);
- Assert.assertEquals(table1XML, table2.toString());
+ Assert.assertEquals(table1XML, table2.toString());
}
public void testKeyEnumeration()
@@ -273,6 +277,117 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertEquals(Short.MAX_VALUE, table.getObject("object-short"));
}
+
+ public void testwriteBuffer()
+ {
+ byte[] bytes = {99, 98, 97, 96, 95};
+
+ PropertyFieldTable table = new PropertyFieldTable();
+ table.setBoolean("bool", true);
+ table.setByte("byte", Byte.MAX_VALUE);
+
+ table.setBytes("bytes", bytes);
+ table.setChar("char", 'c');
+ table.setDouble("double", Double.MAX_VALUE);
+ table.setFloat("float", Float.MAX_VALUE);
+ table.setInteger("int", Integer.MAX_VALUE);
+ table.setLong("long", Long.MAX_VALUE);
+ table.setShort("short", Short.MAX_VALUE);
+
+
+ final ByteBuffer buffer = ByteBuffer.allocate((int) table.getEncodedSize()); // FIXME XXX: Is cast a problem?
+
+ table.writeToBuffer(buffer);
+
+ buffer.flip();
+
+ long length = buffer.getUnsignedInt();
+
+ try
+ {
+ PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
+
+ Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
+ Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
+ assertBytesEqual(bytes, table2.getBytes("bytes"));
+ Assert.assertEquals((Character) 'c', table2.getCharacter("char"));
+ Assert.assertEquals(Double.MAX_VALUE, table2.getDouble("double"));
+ Assert.assertEquals(Float.MAX_VALUE, table2.getFloat("float"));
+ Assert.assertEquals((Integer) Integer.MAX_VALUE, table2.getInteger("int"));
+ Assert.assertEquals((Long) Long.MAX_VALUE, table2.getLong("long"));
+ Assert.assertEquals((Short) Short.MAX_VALUE, table2.getShort("short"));
+ }
+ catch (AMQFrameDecodingException e)
+ {
+ e.printStackTrace();
+ fail("PFT should be instantiated from bytes." + e.getCause());
+ }
+ }
+
+ public void testEncodingSize()
+ {
+ FieldTable result = FieldTableFactory.newFieldTable();
+ int size = 0;
+ result.put("one", 1L);
+ // size is 1(size) + bytes for short string
+ size = 1 + 3; // 1 + key length
+ // or size is 1(the type) + number of bytes (4bytes worth) + bytes
+ size += 1 + 4; // 1 + 4 + value length
+ size += "<long name='one'>1</long>".length(); // this is the xml encoding for a long.
+ assertEquals(size, result.getEncodedSize());
+
+ result.put("two", 2L);
+ size += 1 + 3; // 1 + key length
+ size += 1 + 4; // 1 + 4 + value length
+ size += "<long name='two'>2</long>".length(); // this is the xml encoding for a long.
+ assertEquals(size, result.getEncodedSize());
+
+ result.put("three", 3L);
+ size += 1 + 5; // 1 + key length
+ size += 1 + 4; // 1 + 4 + value length
+ size += "<long name='three'>3</long>".length(); // this is the xml encoding for a long.
+ assertEquals(size, result.getEncodedSize());
+
+ result.put("four", 4L);
+ size += 1 + 4; // 1 + key length
+ size += 1 + 4; // 1 + 4 + value length
+ size += "<long name='four'>4</long>".length(); // this is the xml encoding for a long.
+ assertEquals(size, result.getEncodedSize());
+
+ result.put("five", 5L);
+ size += 1 + 4; // 1 + key length
+ size += 1 + 4; // 1 + 4 + value length
+ size += "<long name='five'>5</long>".length(); // this is the xml encoding for a long.
+ assertEquals(size, result.getEncodedSize());
+
+ //fixme should perhaps be expanded to incorporate all types.
+
+ final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem?
+
+ result.writeToBuffer(buffer);
+
+ buffer.flip();
+
+ long length = buffer.getUnsignedInt();
+
+ try
+ {
+ PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
+
+ Assert.assertEquals((Long) 1L, table2.getLong("one"));
+ Assert.assertEquals((Long) 2L, table2.getLong("two"));
+ Assert.assertEquals((Long) 3L, table2.getLong("three"));
+ Assert.assertEquals((Long) 4L, table2.getLong("four"));
+ Assert.assertEquals((Long) 5L, table2.getLong("five"));
+ }
+ catch (AMQFrameDecodingException e)
+ {
+ e.printStackTrace();
+ fail("PFT should be instantiated from bytes." + e.getCause());
+ }
+
+ }
+
private void assertBytesEqual(byte[] expected, byte[] actual)
{
Assert.assertEquals(expected.length, actual.length);