summaryrefslogtreecommitdiff
path: root/java/common/src/test
diff options
context:
space:
mode:
authorRobert Greig <rgreig@apache.org>2006-12-22 20:32:43 +0000
committerRobert Greig <rgreig@apache.org>2006-12-22 20:32:43 +0000
commit56e155dc210a1e46796b18f179a00a56ae52a0e7 (patch)
tree9add891a6b632f7d1eeefeb2019079efce7739df /java/common/src/test
parenta71fc76d0f605d1faa76f8aec7b4498c168aec46 (diff)
downloadqpid-python-56e155dc210a1e46796b18f179a00a56ae52a0e7.tar.gz
QPID-229 : Patch supplied by Rob Godfrey - Change implementation of FieldTable
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@489748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common/src/test')
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java12
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java52
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java349
3 files changed, 90 insertions, 323 deletions
diff --git a/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java b/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
index 66dd1b10ef..ffbdf730a9 100644
--- a/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
+++ b/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
@@ -31,7 +31,7 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
BasicContentHeaderProperties _testProperties;
- PropertyFieldTable _testTable;
+ FieldTable _testTable;
String _testString = "This is a test string";
int _testint = 666;
@@ -45,11 +45,9 @@ public class BasicContentHeaderPropertiesTest extends TestCase
public void setUp()
{
- HashMap _testMap = new HashMap(10);
- _testMap.put("TestString", _testString);
- _testMap.put("Testint", _testint);
- _testTable = new PropertyFieldTable();
- _testTable.putAll(_testMap);
+ _testTable = new FieldTable();
+ _testTable.setString("TestString", _testString);
+ _testTable.setInteger("Testint", _testint);
_testProperties = new BasicContentHeaderProperties();
_testProperties.setHeaders(_testTable);
}
@@ -57,7 +55,7 @@ public class BasicContentHeaderPropertiesTest extends TestCase
public void testGetPropertyListSize()
{
//needs a better test but at least we're exercising the code !
- // FT size is encoded in an int
+ // FT length is encoded in an int
int expectedSize = EncodingUtils.encodedIntegerLength();
expectedSize += EncodingUtils.encodedShortStringLength("TestInt");
diff --git a/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
index 9cad31766b..94c97ef808 100644
--- a/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
+++ b/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
@@ -51,7 +51,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testReplacement() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
//Set a boolean value
table1.setBoolean("value", true);
@@ -73,7 +73,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testRemoval() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
//Set a boolean value
table1.setBoolean("value", true);
@@ -99,7 +99,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testBoolean() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setBoolean("value", true);
Assert.assertTrue(table1.propertyExists("value"));
@@ -184,7 +184,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value will return false
@@ -197,7 +197,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testByte() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setByte("value", Byte.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -243,7 +243,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -266,7 +266,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testShort() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setShort("value", Short.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -323,7 +323,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -345,7 +345,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testDouble() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setDouble("value", Double.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -414,7 +414,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -437,7 +437,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testFloat() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setFloat("value", Float.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -500,7 +500,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -522,7 +522,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testInt() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setInteger("value", Integer.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -586,7 +586,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -608,7 +608,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testLong() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setLong("value", Long.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -679,7 +679,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value
@@ -700,7 +700,7 @@ public class JMSPropertyFieldTableTest extends TestCase
* Calls all methods that can be used to check the table is empty
* - getEncodedSize
* - isEmpty
- * - size
+ * - length
*
* @param table to check is empty
*/
@@ -716,7 +716,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testString() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setString("value", "Hello");
Assert.assertTrue(table1.propertyExists("value"));
@@ -799,7 +799,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testValues() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
table.setBoolean("bool", true);
table.setDouble("double", Double.MAX_VALUE);
table.setFloat("float", Float.MAX_VALUE);
@@ -842,7 +842,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasNull() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
try
{
@@ -862,7 +862,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasEmptyString() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
try
{
@@ -882,7 +882,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNamehasMaxLength() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
StringBuffer longPropertyName = new StringBuffer(129);
@@ -910,7 +910,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsLetter() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -931,7 +931,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameContainsInvalidCharacter() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -953,7 +953,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameIsInvalid() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -995,7 +995,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testSets()
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
table.put("n1", "1");
table.put("n2", "2");
diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
index 5256c62054..c259d3ee8a 100644
--- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
+++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
@@ -37,39 +37,23 @@ public class PropertyFieldTableTest extends TestCase
private static final Logger _logger = Logger.getLogger(PropertyFieldTableTest.class);
- /**
- * Test that modifying a byte[] after setting property doesn't change property
- */
- public void testByteModification()
- {
- PropertyFieldTable table = new PropertyFieldTable();
- byte[] bytes = {99, 98, 97, 96, 95};
- table.setBytes("bytes", bytes);
- bytes[0] = 1;
- bytes[1] = 2;
- bytes[2] = 3;
- bytes[3] = 4;
- bytes[4] = 5;
-
- assertBytesNotEqual(bytes, table.getBytes("bytes"));
- }
/**
* Test that setting a similar named value replaces any previous value set on that name
*/
public void testReplacement()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
//Set a boolean value
table1.setBoolean("value", true);
- //Check size of table is correct (<Value length> + <type> + <Boolean length>)
+ //Check length of table is correct (<Value length> + <type> + <Boolean length>)
int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength();
Assert.assertEquals(size, table1.getEncodedSize());
// reset value to an integer
table1.setInteger("value", Integer.MAX_VALUE);
- // Check the size has changed accordingly (<Value length> + <type> + <Integer length>)
+ // Check the length has changed accordingly (<Value length> + <type> + <Integer length>)
size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength();
Assert.assertEquals(size, table1.getEncodedSize());
@@ -86,7 +70,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testBoolean()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setBoolean("value", true);
Assert.assertTrue(table1.propertyExists("value"));
@@ -107,19 +91,9 @@ public class PropertyFieldTableTest extends TestCase
//except value as a string
Assert.assertEquals("true", table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BOOLEAN_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getBoolean("value"));
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -132,7 +106,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testByte()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setByte("value", Byte.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -151,20 +125,8 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BYTE_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getByte("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -177,7 +139,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testShort()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setShort("value", Short.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -196,20 +158,8 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_SHORT_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getShort("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -223,7 +173,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testChar()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setChar("value", 'c');
Assert.assertTrue(table1.propertyExists("value"));
@@ -242,26 +192,9 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("c", table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_ASCII_CHARACTER_PROPERTY_PREFIX, "value", null);
-
- try
- {
- table1.getString("value");
- fail("Should throw NullPointerException");
- }
- catch (NullPointerException npe)
- {
- //Normal Path
- }
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -275,7 +208,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testDouble()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setDouble("value", Double.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -293,20 +226,11 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value"));
-
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_DOUBLE_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getDouble("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -320,7 +244,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testFloat()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setFloat("value", Float.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -339,19 +263,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_FLOAT_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getFloat("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -365,7 +282,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testInt()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setInteger("value", Integer.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -384,19 +301,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_INT_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getInteger("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -410,7 +320,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testLong()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setLong("value", Long.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -429,19 +339,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_LONG_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getLong("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -457,7 +360,7 @@ public class PropertyFieldTableTest extends TestCase
{
byte[] bytes = {99, 98, 97, 96, 95};
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setBytes("value", bytes);
Assert.assertTrue(table1.propertyExists("value"));
@@ -476,19 +379,11 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it is null
Assert.assertEquals(null, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BINARY_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getBytes("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -499,19 +394,17 @@ public class PropertyFieldTableTest extends TestCase
* Calls all methods that can be used to check the table is empty
* - getEncodedSize
* - isEmpty
- * - size
+ * - length
*
* @param table to check is empty
*/
- private void checkEmpty(PropertyFieldTable table)
+ private void checkEmpty(FieldTable table)
{
Assert.assertEquals(0, table.getEncodedSize());
Assert.assertTrue(table.isEmpty());
Assert.assertEquals(0, table.size());
Assert.assertEquals(0, table.keySet().size());
- Assert.assertEquals(0, table.values().size());
- Assert.assertEquals(0, table.entrySet().size());
}
@@ -521,7 +414,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testString()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setString("value", "Hello");
Assert.assertTrue(table1.propertyExists("value"));
@@ -562,79 +455,11 @@ public class PropertyFieldTableTest extends TestCase
}
- /**
- * Test that the generated XML can be used to create a field table with the same values.
- */
- public void testValidXML()
- {
- PropertyFieldTable table1 = new PropertyFieldTable();
- table1.setBoolean("bool", true);
- table1.setByte("byte", Byte.MAX_VALUE);
- byte[] bytes = {99, 98, 97, 96, 95};
- table1.setBytes("bytes", bytes);
- table1.setChar("char", 'c');
- table1.setDouble("double", Double.MAX_VALUE);
- table1.setFloat("float", Float.MAX_VALUE);
- table1.setInteger("int", Integer.MAX_VALUE);
- table1.setLong("long", Long.MAX_VALUE);
- table1.setShort("short", Short.MAX_VALUE);
- table1.setString("string", "Hello");
- table1.setString("null-string", null);
-
- table1.setObject("object-bool", true);
- table1.setObject("object-byte", Byte.MAX_VALUE);
- table1.setObject("object-bytes", bytes);
- table1.setObject("object-char", 'c');
- table1.setObject("object-double", Double.MAX_VALUE);
- table1.setObject("object-float", Float.MAX_VALUE);
- table1.setObject("object-int", Integer.MAX_VALUE);
- table1.setObject("object-long", Long.MAX_VALUE);
- table1.setObject("object-short", Short.MAX_VALUE);
- table1.setObject("object-string", "Hello");
-
- Assert.assertEquals(21, table1.size());
-
- String table1XML = table1.toString();
-
- PropertyFieldTable table2 = new PropertyFieldTable(table1XML);
-
- Assert.assertEquals(table1XML, table2.toString());
-
- //Check that when bytes is written out as a string with no new line between items that it is read in ok.
-
- }
-
- /**
- * Test that invalid input throws the correct Exception
- */
- public void testInvalidXML()
- {
- try
- {
- _logger.warn("Testing Invalid XML expecting IllegalArgumentException");
- new PropertyFieldTable("Rubbish");
- fail("IllegalArgumentException expected");
- }
- catch (IllegalArgumentException iae)
- {
- //normal path
- }
- try
- {
- _logger.warn("Testing Invalid XML expecting IllegalArgumentException");
- new PropertyFieldTable("");
- fail("IllegalArgumentException expected");
- }
- catch (IllegalArgumentException iae)
- {
- //normal path
- }
- }
-
+
public void testKeyEnumeration()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setLong("one", 1L);
table.setLong("two", 2L);
table.setLong("three", 3L);
@@ -652,7 +477,7 @@ public class PropertyFieldTableTest extends TestCase
public void testValues()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
byte[] bytes = {99, 98, 97, 96, 95};
@@ -707,7 +532,7 @@ public class PropertyFieldTableTest extends TestCase
{
byte[] bytes = {99, 98, 97, 96, 95};
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
@@ -732,7 +557,7 @@ public class PropertyFieldTableTest extends TestCase
try
{
- PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
+ FieldTable table2 = new FieldTable(buffer, length);
Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
@@ -756,7 +581,7 @@ public class PropertyFieldTableTest extends TestCase
public void testEncodingSize()
{
- PropertyFieldTable result = new PropertyFieldTable();
+ FieldTable result = new FieldTable();
int size = 0;
result.setBoolean("boolean", true);
@@ -847,31 +672,31 @@ public class PropertyFieldTableTest extends TestCase
// public void testEncodingSize1()
// {
// PropertyFieldTable table = new PropertyFieldTable();
-// int size = 0;
+// int length = 0;
// result.put("one", 1L);
-// size = EncodingUtils.encodedShortStringLength("one");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length = EncodingUtils.encodedShortStringLength("one");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("two", 2L);
-// size += EncodingUtils.encodedShortStringLength("two");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("two");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("three", 3L);
-// size += EncodingUtils.encodedShortStringLength("three");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("three");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("four", 4L);
-// size += EncodingUtils.encodedShortStringLength("four");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("four");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("five", 5L);
-// size += EncodingUtils.encodedShortStringLength("five");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("five");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// //fixme should perhaps be expanded to incorporate all types.
//
@@ -907,7 +732,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testSetObject()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try setting a non primative object
@@ -920,7 +745,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -929,7 +754,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasNull()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
try
{
@@ -940,7 +765,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -950,7 +775,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasEmptyString()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
try
{
@@ -961,7 +786,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -971,7 +796,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNamehasMaxLength()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
StringBuffer longPropertyName = new StringBuffer(129);
@@ -989,7 +814,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -999,7 +824,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsLetter()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try a name that starts with a number
try
@@ -1011,7 +836,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -1021,7 +846,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsHashorDollar()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try a name that starts with a number
try
@@ -1041,12 +866,10 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testContents()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.put("StringProperty", "String");
- Assert.assertTrue(table.containsValue("String"));
-
Assert.assertEquals("String", table.get("StringProperty"));
//Test Clear
@@ -1062,7 +885,7 @@ public class PropertyFieldTableTest extends TestCase
public void testSets()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.put("n1", "1");
table.put("n2", "2");
@@ -1075,64 +898,10 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertFalse(iterator.hasNext());
- iterator = table.values().iterator();
- Assert.assertEquals("1", iterator.next());
- Assert.assertEquals("2", iterator.next());
- Assert.assertEquals("3", iterator.next());
- Assert.assertFalse(iterator.hasNext());
-
-
- iterator = table.entrySet().iterator();
- Map.Entry entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n1", entry.getKey());
- Assert.assertEquals("1", entry.getValue());
- entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n2", entry.getKey());
- Assert.assertEquals("2", entry.getValue());
- entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n3", entry.getKey());
- Assert.assertEquals("3", entry.getValue());
- Assert.assertFalse(iterator.hasNext());
-
}
- /**
- * Test that all the values are preserved after a putAll
- */
- public void testPutAll()
- {
- Map map = new HashMap();
-
- map.put("char", 'c');
- map.put("double", Double.MAX_VALUE);
- map.put("float", Float.MAX_VALUE);
- map.put("int", Integer.MAX_VALUE);
- map.put("long", Long.MAX_VALUE);
- map.put("short", Short.MAX_VALUE);
-
- PropertyFieldTable table = new PropertyFieldTable();
-
- table.putAll(map);
-
- Assert.assertEquals(6, table.size());
-
- Assert.assertTrue(table.containsKey("char"));
- Assert.assertEquals('c', (char) table.getCharacter("char"));
- Assert.assertTrue(table.containsKey("double"));
- Assert.assertEquals(Double.MAX_VALUE, table.getDouble("double"));
- Assert.assertTrue(table.containsKey("float"));
- Assert.assertEquals(Float.MAX_VALUE, table.getFloat("float"));
- Assert.assertTrue(table.containsKey("int"));
- Assert.assertEquals(Integer.MAX_VALUE, (int) table.getInteger("int"));
- Assert.assertTrue(table.containsKey("long"));
- Assert.assertEquals(Long.MAX_VALUE, (long) table.getLong("long"));
- Assert.assertTrue(table.containsKey("short"));
- Assert.assertEquals(Short.MAX_VALUE, (short) table.getShort("short"));
- Assert.assertEquals(Short.MAX_VALUE, (short) table.getShort("short"));
- }
-
private void assertBytesEqual(byte[] expected, byte[] actual)
{