Author: ritchiem
Date: Wed Nov 22 09:07:08 2006
New Revision: 478242

URL: http://svn.apache.org/viewvc?view=rev&rev=478242
Log:
Created a PropertyFieldTable with test. Pulls the functionality that is used in 
AbstractJMSMessage to a central location, FieldTable should be refactored to 
AMQHeaderPropertyFieldTable extending PropertyFieldTable limiting insertions to 
values that can be placed in the headers so that AbstractJMSMessage can then 
utilise that class.

Added:
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
   (with props)
    incubator/qpid/trunk/qpid/java/common/src/test/
    incubator/qpid/trunk/qpid/java/common/src/test/java/
    incubator/qpid/trunk/qpid/java/common/src/test/java/org/
    incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/
    incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/
    incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/
    
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
   (with props)

Added: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java?view=auto&rev=478242
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
 Wed Nov 22 09:07:08 2006
@@ -0,0 +1,656 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.framing;
+
+import org.apache.log4j.Logger;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+//extends FieldTable
+public class PropertyFieldTable
+{
+
+    private static final Logger _logger = 
Logger.getLogger(PropertyFieldTable.class);
+
+    public static final char BOOLEAN_PROPERTY_PREFIX = 'B';
+    public static final char BYTE_PROPERTY_PREFIX = 'b';
+    public static final char SHORT_PROPERTY_PREFIX = 's';
+    public static final char INT_PROPERTY_PREFIX = 'i';
+    public static final char LONG_PROPERTY_PREFIX = 'l';
+    public static final char FLOAT_PROPERTY_PREFIX = 'f';
+    public static final char DOUBLE_PROPERTY_PREFIX = 'd';
+    public static final char STRING_PROPERTY_PREFIX = 'S';
+    public static final char CHAR_PROPERTY_PREFIX = 'c';
+    public static final char BYTES_PROPERTY_PREFIX = 'y';
+
+
+    private static final String BOOLEAN = "boolean";
+    private static final String BYTE = "byte";
+    private static final String BYTES = "bytes";
+    private static final String SHORT = "short";
+    private static final String INT = "int";
+    private static final String LONG = "long";
+    private static final String FLOAT = "float";
+    private static final String DOUBLE = "double";
+    private static final String STRING = "string";
+    private static final String CHAR = "char";
+    private static final String UNKNOWN = "unknown type";
+
+    private static final String PROPERTY_FIELD_TABLE_CLOSE_XML = 
"</PropertyFieldTable>";
+    private static final String PROPERTY_FIELD_TABLE_OPEN_XML = 
"<PropertyFieldTable>";
+    private static final String BYTES_CLOSE_XML = "</" + BYTES + ">";
+    private static final String BYTES_OPEN_XML_START = "<" + BYTES;
+
+    private LinkedHashMap<String, Object> _properties;
+    private LinkedHashMap<String, String> _propertyNamesTypeMap;
+
+
+    public PropertyFieldTable()
+    {
+        super();
+        _properties = new LinkedHashMap<String, Object>();
+        _propertyNamesTypeMap = new LinkedHashMap<String, String>();
+    }
+
+    public PropertyFieldTable(String textFormat)
+    {
+        this();
+        try
+        {
+            parsePropertyFieldTable(textFormat);
+        }
+        catch (Exception e)
+        {
+            System.out.println(textFormat);
+            e.printStackTrace();
+        }
+
+    }
+
+    // ************  Getters
+
+    public Boolean getBoolean(String string)
+    {
+        return (Boolean) _properties.get(BOOLEAN_PROPERTY_PREFIX + string);
+    }
+
+    public Byte getByte(String string)
+    {
+        return (Byte) _properties.get(BYTE_PROPERTY_PREFIX + string);
+    }
+
+    public Short getShort(String string)
+    {
+        return (Short) _properties.get(SHORT_PROPERTY_PREFIX + string);
+    }
+
+    public Integer getInteger(String string)
+    {
+        return (Integer) _properties.get(INT_PROPERTY_PREFIX + string);
+    }
+
+    public Long getLong(String string)
+    {
+        return (Long) _properties.get(LONG_PROPERTY_PREFIX + string);
+    }
+
+    public Float getFloat(String string)
+    {
+        return (Float) _properties.get(FLOAT_PROPERTY_PREFIX + string);
+    }
+
+    public Double getDouble(String string)
+    {
+        return (Double) _properties.get(DOUBLE_PROPERTY_PREFIX + string);
+    }
+
+    public String getString(String string)
+    {
+        return (String) _properties.get(STRING_PROPERTY_PREFIX + string);
+    }
+
+    public Character getCharacter(String string)
+    {
+        return (Character) _properties.get(CHAR_PROPERTY_PREFIX + string);
+    }
+
+    public byte[] getBytes(String string)
+    {
+        return (byte[]) _properties.get(BYTES_PROPERTY_PREFIX + string);
+    }
+
+    public Object getObject(String string)
+    {
+        String typestring = _propertyNamesTypeMap.get(string);
+
+        if (typestring != null && !typestring.equals(""))
+        {
+            char type = typestring.charAt(0);
+
+            return _properties.get(type + string);
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    // ************  Setters
+
+
+    public void setBoolean(String string, boolean b)
+    {
+        checkPropertyName(string, BOOLEAN_PROPERTY_PREFIX);
+
+
+        _propertyNamesTypeMap.put(string, "" + BOOLEAN_PROPERTY_PREFIX);
+        _properties.put(BOOLEAN_PROPERTY_PREFIX + string, b);// ? new Long(1) 
: new Long(0));
+    }
+
+    public void setByte(String string, byte b)
+    {
+        checkPropertyName(string, BYTE_PROPERTY_PREFIX);
+
+
+        _properties.put(BYTE_PROPERTY_PREFIX + string, b);
+    }
+
+    public void setShort(String string, short i)
+    {
+        checkPropertyName(string, SHORT_PROPERTY_PREFIX);
+
+
+        _properties.put(SHORT_PROPERTY_PREFIX + string, i);
+    }
+
+    public void setInteger(String string, int i)
+    {
+        checkPropertyName(string, INT_PROPERTY_PREFIX);
+
+
+        _properties.put(INT_PROPERTY_PREFIX + string, i);
+    }
+
+    public void setLong(String string, long l)
+    {
+        checkPropertyName(string, LONG_PROPERTY_PREFIX);
+
+
+        _properties.put(LONG_PROPERTY_PREFIX + string, l);
+    }
+
+    public void setFloat(String string, float v)
+    {
+        checkPropertyName(string, FLOAT_PROPERTY_PREFIX);
+
+
+        _properties.put(FLOAT_PROPERTY_PREFIX + string, v);
+    }
+
+    public void setDouble(String string, double v)
+    {
+        checkPropertyName(string, DOUBLE_PROPERTY_PREFIX);
+
+
+        _properties.put(DOUBLE_PROPERTY_PREFIX + string, v);
+    }
+
+    public void setString(String string, String string1)
+    {
+        checkPropertyName(string, STRING_PROPERTY_PREFIX);
+
+
+        _properties.put(STRING_PROPERTY_PREFIX + string, string1);
+    }
+
+    public void setChar(String string, char c)
+    {
+        checkPropertyName(string, CHAR_PROPERTY_PREFIX);
+
+        _properties.put(CHAR_PROPERTY_PREFIX + string, c);
+    }
+
+    public void setBytes(String string, byte[] bytes)
+    {
+        setBytes(string, bytes, 0, bytes.length);
+    }
+
+    public void setBytes(String string, byte[] bytes, int start, int length)
+    {
+        checkPropertyName(string, BYTES_PROPERTY_PREFIX);
+
+        _properties.put(BYTES_PROPERTY_PREFIX + string, sizeByteArray(bytes, 
start, length));
+    }
+
+    private byte[] sizeByteArray(byte[] bytes, int start, int length)
+    {
+        byte[] resized = new byte[length];
+        int newIndex = 0;
+        for (int oldIndex = start; oldIndex < length; oldIndex++)
+        {
+            resized[newIndex] = bytes[oldIndex];
+            newIndex++;
+        }
+
+        return resized;
+    }
+
+
+    public void setObject(String string, Object object)
+    {
+        if (object instanceof Boolean)
+        {
+            setBoolean(string, (Boolean) object);
+        }
+        else
+        {
+            if (object instanceof Byte)
+            {
+                setByte(string, (Byte) object);
+            }
+            else
+            {
+                if (object instanceof Short)
+                {
+                    setShort(string, (Short) object);
+                }
+                else
+                {
+                    if (object instanceof Integer)
+                    {
+                        setInteger(string, (Integer) object);
+                    }
+                    else
+                    {
+                        if (object instanceof Long)
+                        {
+                            setLong(string, (Long) object);
+                        }
+                        else
+                        {
+                            if (object instanceof Float)
+                            {
+                                setFloat(string, (Float) object);
+                            }
+                            else
+                            {
+                                if (object instanceof Double)
+                                {
+                                    setDouble(string, (Double) object);
+                                }
+                                else
+                                {
+                                    if (object instanceof String)
+                                    {
+                                        setString(string, (String) object);
+                                    }
+                                    else
+                                    {
+                                        if (object instanceof Character)
+                                        {
+                                            setChar(string, (Character) 
object);
+                                        }
+                                        else
+                                        {
+                                            if (object instanceof byte[])
+                                            {
+                                                setBytes(string, (byte[]) 
object);
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+
+    }
+
+    // ***** Methods
+
+    public Enumeration getPropertyNames()
+    {
+        Vector<String> names = new Vector<String>();
+
+        Iterator keys = _properties.keySet().iterator();
+
+        while (keys.hasNext())
+        {
+            String key = (String) keys.next();
+
+            names.add(key.substring(1));
+        }
+
+        return names.elements();
+    }
+
+
+    public boolean itemExists(String string)
+    {
+        Iterator keys = _properties.keySet().iterator();
+
+        while (keys.hasNext())
+        {
+            String key = (String) keys.next();
+
+            if (key.endsWith(string))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    public String toString()
+    {
+        return valueOf(this);
+    }
+
+    public static String valueOf(PropertyFieldTable table)
+    {
+        StringBuffer buf = new StringBuffer(PROPERTY_FIELD_TABLE_OPEN_XML);
+
+        final Iterator it = table._properties.entrySet().iterator();
+
+        while (it.hasNext())
+        {
+            final Map.Entry entry = (Map.Entry) it.next();
+            final String propertyName = (String) entry.getKey();
+            if (propertyName == null)
+            {
+                buf.append("\nInternal error: Property with NULL key defined");
+            }
+            else
+            {
+                buf.append('\n');
+                buf.append(propertyXML(propertyName, true));
+
+                if (propertyName.charAt(0) == BYTES_PROPERTY_PREFIX)
+                {
+                    //remove '>'
+                    buf.deleteCharAt(buf.length() - 1);
+
+                    byte[] bytes = (byte[]) entry.getValue();
+                    buf.append(" length='").append(bytes.length).append("'>");
+
+                    buf.append(byteArrayToXML(propertyName.substring(1), 
bytes));
+                }
+                else
+                {
+
+                    buf.append(String.valueOf(entry.getValue()));
+                }
+                buf.append(propertyXML(propertyName, false));
+
+            }
+        }
+        buf.append("\n");
+        buf.append(PROPERTY_FIELD_TABLE_CLOSE_XML);
+
+        return buf.toString();
+    }
+
+    private void checkPropertyName(String propertyName, char propertyPrefix)
+    {
+        if (propertyName == null)
+        {
+            throw new IllegalArgumentException("Property name must not be 
null");
+        }
+        else if ("".equals(propertyName))
+        {
+            throw new IllegalArgumentException("Property name must not be the 
empty string");
+        }
+
+        String currentValue = _propertyNamesTypeMap.get(propertyName);
+
+        if (currentValue != null)
+        {
+            _properties.remove(currentValue + propertyName);
+        }
+
+        _propertyNamesTypeMap.put(propertyName, "" + propertyPrefix);
+    }
+
+    private static String propertyXML(String propertyName, boolean start)
+    {
+        char typeIdentifier = propertyName.charAt(0);
+
+        StringBuffer buf = new StringBuffer();
+
+        if (start)
+        {
+            buf.append("<");
+        }
+        else
+        {
+            buf.append("</");
+        }
+
+
+        switch (typeIdentifier)
+        {
+            case BOOLEAN_PROPERTY_PREFIX:
+                buf.append(BOOLEAN);
+                break;
+            case BYTE_PROPERTY_PREFIX:
+                buf.append(BYTE);
+                break;
+            case BYTES_PROPERTY_PREFIX:
+                buf.append(BYTES);
+                break;
+            case SHORT_PROPERTY_PREFIX:
+                buf.append(SHORT);
+                break;
+            case INT_PROPERTY_PREFIX:
+                buf.append(INT);
+                break;
+            case LONG_PROPERTY_PREFIX:
+                buf.append(LONG);
+                break;
+            case FLOAT_PROPERTY_PREFIX:
+                buf.append(FLOAT);
+                break;
+            case DOUBLE_PROPERTY_PREFIX:
+                buf.append(DOUBLE);
+                break;
+            case STRING_PROPERTY_PREFIX:
+                buf.append(STRING);
+                break;
+            case CHAR_PROPERTY_PREFIX:
+                buf.append(CHAR);
+                break;
+            default:
+                buf.append(UNKNOWN + " (identifier 
").append(typeIdentifier).append(")");
+                break;
+        }
+
+
+        if (start)
+        {
+            buf.append(" 
name='").append(propertyName.substring(1)).append("'");
+        }
+
+        buf.append(">");
+
+        return buf.toString();
+    }
+
+    private static String byteArrayToXML(String propertyName, byte[] bytes)
+    {
+        StringBuffer buf = new StringBuffer();
+
+        for (int index = 0; index < bytes.length; index++)
+        {
+            buf.append("\n");
+            buf.append(propertyXML(BYTE_PROPERTY_PREFIX + propertyName + "[" + 
index + "]", true));
+            buf.append(bytes[index]);
+            buf.append(propertyXML(BYTE_PROPERTY_PREFIX + propertyName + "[" + 
index + "]", false));
+        }
+        buf.append("\n");
+        return buf.toString();
+    }
+
+    private void processBytesXMLLine(String xmlline)
+    {
+        String type = xmlline.substring(1, xmlline.indexOf(" "));
+
+        String propertyName = xmlline.substring(xmlline.indexOf('\'') + 1,
+                                                xmlline.indexOf('\'', 
xmlline.indexOf('\'') + 1));
+        String value = xmlline.substring(xmlline.indexOf(">") + 1,
+                                         xmlline.indexOf("</"));
+
+        Integer index = 
Integer.parseInt(propertyName.substring(propertyName.lastIndexOf("[") + 1,
+                                                                
propertyName.lastIndexOf("]")));
+        propertyName = propertyName.substring(0, 
propertyName.lastIndexOf("["));
+
+        getBytes(propertyName)[index] = Byte.parseByte(value);
+    }
+
+    private void parsePropertyFieldTable(String textFormat)
+    {
+        StringTokenizer tokenizer = new StringTokenizer(textFormat, "\n");
+
+        boolean processing = false;
+
+        boolean processing_bytes = false;
+
+        while (tokenizer.hasMoreTokens())
+        {
+            String token = tokenizer.nextToken();
+
+
+            if (token.equals(PROPERTY_FIELD_TABLE_CLOSE_XML)
+                || token.equals(BYTES_CLOSE_XML))
+            {
+                processing = false;
+            }
+
+            if (token.equals(BYTES_CLOSE_XML))
+            {
+                processing_bytes = false;
+
+            }
+
+            if (processing)
+            {
+                processXMLLine(token);
+            }
+            else if (processing_bytes)
+            {
+                processBytesXMLLine(token);
+            }
+
+            if (token.startsWith(BYTES_OPEN_XML_START))
+            {
+                processing_bytes = true;
+                processing = false;
+            }
+
+            if (token.equals(PROPERTY_FIELD_TABLE_OPEN_XML) ||
+                token.equals(BYTES_CLOSE_XML))
+            {
+                processing = true;
+            }
+
+        }
+    }
+
+
+    private void processXMLLine(String xmlline)
+    {
+        // <<type> name='<property>'><value></<type>>
+        // <string name='message' >Message 99</string >
+
+        String type = xmlline.substring(1, xmlline.indexOf(" "));
+
+        String propertyName = xmlline.substring(xmlline.indexOf('\'') + 1,
+                                                xmlline.indexOf('\'', 
xmlline.indexOf('\'') + 1));
+
+        String value = "";
+
+        if (!type.equals(BYTES))
+        {
+            value = xmlline.substring(xmlline.indexOf(">") + 1,
+                                      xmlline.indexOf("</"));
+        }
+
+        if (type.equals(BOOLEAN))
+        {
+            setBoolean(propertyName, Boolean.parseBoolean(value));
+        }
+        if (type.equals(BYTE))
+        {
+            setByte(propertyName, Byte.parseByte(value));
+        }
+        if (type.equals(BYTES))
+        {
+            Integer length = Integer.parseInt(xmlline.substring(
+                    xmlline.lastIndexOf("=") + 2
+                    , xmlline.lastIndexOf("'")));
+            byte[] bytes = new byte[length];
+            setBytes(propertyName, bytes);
+        }
+        if (type.equals(SHORT))
+        {
+            setShort(propertyName, Short.parseShort(value));
+        }
+        if (type.equals(INT))
+        {
+            setInteger(propertyName, Integer.parseInt(value));
+        }
+        if (type.equals(LONG))
+        {
+            setLong(propertyName, Long.parseLong(value));
+        }
+        if (type.equals(FLOAT))
+        {
+            setFloat(propertyName, Float.parseFloat(value));
+        }
+        if (type.equals(DOUBLE))
+        {
+            setDouble(propertyName, Double.parseDouble(value));
+        }
+        if (type.equals(STRING))
+        {
+            setString(propertyName, value);
+        }
+        if (type.equals(CHAR))
+        {
+            setChar(propertyName, value.charAt(0));
+        }
+        if (type.equals(UNKNOWN))
+        {
+            _logger.error("Ignoring unknown property value:" + xmlline);
+        }
+    }
+
+
+}
+

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java?view=auto&rev=478242
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
 Wed Nov 22 09:07:08 2006
@@ -0,0 +1,302 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.    
+ *
+ * 
+ */
+package org.apache.qpid.framing;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import java.util.Enumeration;
+
+public class PropertyFieldTableTest extends TestCase
+{
+
+    //Test byte modification
+
+    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 replacement
+
+    public void testReplacement()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setBoolean("value", true);
+        table1.setInteger("value", Integer.MAX_VALUE);
+        Assert.assertEquals(null, table1.getBoolean("value"));
+        Assert.assertEquals((Integer) Integer.MAX_VALUE, 
table1.getInteger("value"));
+    }
+
+    //Test Lookups
+
+    public void testBooleanLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setBoolean("value", true);
+        Assert.assertEquals((Boolean) true, table1.getBoolean("value"));
+    }
+
+    public void testByteLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setByte("value", (byte) 1);
+        Assert.assertEquals((Byte) (byte) 1, table1.getByte("value"));
+    }
+
+    public void testShortLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setShort("value", Short.MAX_VALUE);
+        Assert.assertEquals((Short) Short.MAX_VALUE, table1.getShort("value"));
+    }
+
+
+    public void testCharLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setChar("value", 'b');
+        Assert.assertEquals((Character) 'b', table1.getCharacter("value"));
+    }
+
+    public void testDoubleLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setDouble("value", Double.MAX_VALUE);
+        Assert.assertEquals(Double.MAX_VALUE, table1.getDouble("value"));
+    }
+
+    public void testFloatLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setFloat("value", Float.MAX_VALUE);
+        Assert.assertEquals(Float.MAX_VALUE, table1.getFloat("value"));
+    }
+
+    public void testIntLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setInteger("value", Integer.MAX_VALUE);
+        Assert.assertEquals((Integer) Integer.MAX_VALUE, 
table1.getInteger("value"));
+    }
+
+    public void testLongLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        table1.setLong("value", Long.MAX_VALUE);
+        Assert.assertEquals((Long) Long.MAX_VALUE, table1.getLong("value"));
+    }
+
+    public void testBytesLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        byte[] bytes = {99, 98, 97, 96, 95};
+        table1.setBytes("bytes", bytes);
+        assertBytesEqual(bytes, table1.getBytes("bytes"));
+    }
+
+    // Failed Lookups
+
+    public void testFailedBooleanLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getBoolean("int"));
+    }
+
+    public void testFailedByteLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getByte("int"));
+    }
+
+    public void testFailedBytesLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getBytes("int"));
+    }
+
+    public void testFailedCharLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getCharacter("int"));
+    }
+
+    public void testFailedDoubleLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getDouble("int"));
+    }
+
+    public void testFailedFloatLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getFloat("int"));
+    }
+
+    public void testFailedIntLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getInteger("int"));
+    }
+
+    public void testFailedLongLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getLong("int"));
+    }
+
+    public void testFailedShortLookup()
+    {
+        PropertyFieldTable table1 = new PropertyFieldTable();
+        Assert.assertEquals(null, table1.getShort("int"));
+    }
+
+    public void testXML()
+    {
+        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.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);
+
+        String table1XML = table1.toString();
+
+        PropertyFieldTable table2 = new PropertyFieldTable(table1XML);
+
+        Assert.assertEquals(table1XML, table2.toString());
+        System.out.println(table2.toString());
+    }
+
+    public void testKeyEnumeration()
+    {
+        PropertyFieldTable table = new PropertyFieldTable();
+        table.setLong("one", 1L);
+        table.setLong("two", 2L);
+        table.setLong("three", 3L);
+        table.setLong("four", 4L);
+        table.setLong("five", 5L);
+
+        Enumeration e = table.getPropertyNames();
+
+        Assert.assertTrue("one".equals(e.nextElement()));
+        Assert.assertTrue("two".equals(e.nextElement()));
+        Assert.assertTrue("three".equals(e.nextElement()));
+        Assert.assertTrue("four".equals(e.nextElement()));
+        Assert.assertTrue("five".equals(e.nextElement()));
+    }
+
+    public void testValues()
+    {
+        PropertyFieldTable table = new PropertyFieldTable();
+        table.setBoolean("bool", true);
+        table.setByte("byte", Byte.MAX_VALUE);
+        byte[] bytes = {99, 98, 97, 96, 95};
+        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);
+
+        table.setObject("object-bool", true);
+        table.setObject("object-byte", Byte.MAX_VALUE);
+        table.setObject("object-bytes", bytes);
+        table.setObject("object-char", 'c');
+        table.setObject("object-double", Double.MAX_VALUE);
+        table.setObject("object-float", Float.MAX_VALUE);
+        table.setObject("object-int", Integer.MAX_VALUE);
+        table.setObject("object-long", Long.MAX_VALUE);
+        table.setObject("object-short", Short.MAX_VALUE);
+
+
+        Assert.assertEquals((Boolean) true, table.getBoolean("bool"));
+        Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte"));
+        assertBytesEqual(bytes, table.getBytes("bytes"));
+        Assert.assertEquals((Character) 'c', table.getCharacter("char"));
+        Assert.assertEquals(Double.MAX_VALUE, table.getDouble("double"));
+        Assert.assertEquals(Float.MAX_VALUE, table.getFloat("float"));
+        Assert.assertEquals((Integer) Integer.MAX_VALUE, 
table.getInteger("int"));
+        Assert.assertEquals((Long) Long.MAX_VALUE, table.getLong("long"));
+        Assert.assertEquals((Short) Short.MAX_VALUE, table.getShort("short"));
+
+        Assert.assertEquals(true, table.getObject("object-bool"));
+        Assert.assertEquals(Byte.MAX_VALUE, table.getObject("object-byte"));
+        assertBytesEqual(bytes, (byte[]) table.getObject("object-bytes"));
+        Assert.assertEquals('c', table.getObject("object-char"));
+        Assert.assertEquals(Double.MAX_VALUE, 
table.getObject("object-double"));
+        Assert.assertEquals(Float.MAX_VALUE, table.getObject("object-float"));
+        Assert.assertEquals(Integer.MAX_VALUE, table.getObject("object-int"));
+        Assert.assertEquals(Long.MAX_VALUE, table.getObject("object-long"));
+        Assert.assertEquals(Short.MAX_VALUE, table.getObject("object-short"));
+    }
+
+    private void assertBytesEqual(byte[] expected, byte[] actual)
+    {
+        Assert.assertEquals(expected.length, actual.length);
+
+        for (int index = 0; index < expected.length; index++)
+        {
+            Assert.assertEquals(expected[index], actual[index]);
+        }
+    }
+
+    private void assertBytesNotEqual(byte[] expected, byte[] actual)
+    {
+        Assert.assertEquals(expected.length, actual.length);
+
+        for (int index = 0; index < expected.length; index++)
+        {
+            Assert.assertFalse(expected[index] == actual[index]);
+        }
+    }
+
+    public static junit.framework.Test suite()
+    {
+        return new junit.framework.TestSuite(PropertyFieldTableTest.class);
+    }
+
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to