You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/02/13 12:55:11 UTC

svn commit: r1567898 - in /qpid/jms/trunk/src: main/java/org/apache/qpid/jms/impl/MessageImpl.java test/java/org/apache/qpid/jms/impl/MessageImplTest.java

Author: robbie
Date: Thu Feb 13 11:55:11 2014
New Revision: 1567898

URL: http://svn.apache.org/r1567898
Log:
QPIDJMS-9: implement validation that property names meet the identifier requirements

Modified:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java?rev=1567898&r1=1567897&r2=1567898&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java Thu Feb 13 11:55:11 2014
@@ -113,8 +113,57 @@ public abstract class MessageImpl<T exte
             throw new IllegalArgumentException("Property name must not be the empty string");
         }
 
-        //TODO: validate name format?
-        //checkPropertyNameFormat(propertyName);
+        checkIdentifierFormat(propertyName);
+    }
+
+    private void checkIdentifierFormat(String identifier) throws IllegalArgumentException
+    {
+        checkIdentifierLetterAndDigitRequirements(identifier);
+        checkIdentifierIsntNullTrueFalse(identifier);
+        checkIdentifierIsntLogicOperator(identifier);
+    }
+
+    private void checkIdentifierIsntLogicOperator(String identifier)
+    {
+        //Identifiers cannot be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE.
+        if("NOT".equals(identifier) || "AND".equals(identifier) || "OR".equals(identifier)
+                || "BETWEEN".equals(identifier) || "LIKE".equals(identifier) || "IN".equals(identifier)
+                    || "IS".equals(identifier) || "ESCAPE".equals(identifier))
+        {
+            throw new IllegalArgumentException("Identifier not allowed in JMS: '" + identifier + "'");
+        }
+    }
+
+    private void checkIdentifierIsntNullTrueFalse(String identifier)
+    {
+        //Identifiers cannot be the names NULL, TRUE, and FALSE.
+        if("NULL".equals(identifier) || "TRUE".equals(identifier) || "FALSE".equals(identifier))
+        {
+            throw new IllegalArgumentException("Identifier not allowed in JMS: '" + identifier + "'");
+        }
+    }
+
+    private void checkIdentifierLetterAndDigitRequirements(String identifier)
+    {
+        //An identifier is an unlimited-length sequence of letters and digits, the first of which must be a letter.
+        //A letter is any character for which the method Character.isJavaLetter returns true. This includes '_' and '$'.
+        //A letter or digit is any character for which the method Character.isJavaLetterOrDigit returns true.
+        char startChar = identifier.charAt(0);
+        if (!(Character.isJavaIdentifierStart(startChar)))
+        {
+            throw new IllegalArgumentException("Identifier does not begin with a valid JMS identifier start character: '" + identifier + "' ");
+        }
+
+        // JMS part character
+        int length = identifier.length();
+        for (int i = 1; i < length; i++)
+        {
+            char ch = identifier.charAt(i);
+            if (!(Character.isJavaIdentifierPart(ch)))
+            {
+                throw new IllegalArgumentException("Identifier contains invalid JMS identifier character '" + ch + "': '" + identifier + "' ");
+            }
+        }
     }
 
     private void setPropertiesWritable(boolean writable)

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java?rev=1567898&r1=1567897&r2=1567898&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Thu Feb 13 11:55:11 2014
@@ -193,7 +193,7 @@ public class MessageImplTest extends Qpi
     @Test
     public void testGetMissingPrimitivePropertyResultsInExpectedBehaviour() throws Exception
     {
-        String propertyName = "does.not.exist";
+        String propertyName = "does_not_exist";
 
         //expect false from Boolean.valueOf(null).
         assertFalse(_testMessage.getBooleanProperty(propertyName));
@@ -282,6 +282,246 @@ public class MessageImplTest extends Qpi
         }
     }
 
+    /**
+     * Property 'identifiers' (i.e. names) must begin with a letter for which
+     * {@link Character#isJavaLetter(char)} is true, as described in {@link javax.jms.Message}.
+     * Verify an IAE is thrown if setting a property beginning with a non-letter character.
+     */
+    @Test
+    public void testSetPropertyWithNonLetterAsFirstCharacterThrowsIAE() throws Exception
+    {
+        String propertyName = "1name";
+        try
+        {
+            _testMessage.setObjectProperty(propertyName, "value");
+            fail("expected rejection of identifier starting with non-letter character");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) must continue with a letter or digit for which
+     * {@link Character#isJavaLetterOrDigit(char)} is true, as described in {@link javax.jms.Message}.
+     * Verify an IAE is thrown if setting a property continuing with a non-letter-or-digit character.
+     */
+    @Test
+    public void testSetPropertyWithNonLetterOrDigitCharacterThrowsIAE() throws Exception
+    {
+        String propertyName = "name-invalid";
+        try
+        {
+            _testMessage.setObjectProperty(propertyName, "value");
+            fail("expected rejection of identifier starting with non-letter character");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NULL, TRUE, or FALSE, as described
+     * in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameNULL() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("NULL", "value");
+            fail("expected rejection of identifier named NULL");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NULL, TRUE, or FALSE, as described
+     * in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameTRUE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("TRUE", "value");
+            fail("expected rejection of identifier named TRUE");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NULL, TRUE, or FALSE, as described
+     * in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameFALSE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("FALSE", "value");
+            fail("expected rejection of identifier named FALSE");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    //TODO: delete this marker comment
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameNOT() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("NOT", "value");
+            fail("expected rejection of identifier named NOT");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameAND() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("AND", "value");
+            fail("expected rejection of identifier named AND");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameOR() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("OR", "value");
+            fail("expected rejection of identifier named OR");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameBETWEEN() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("BETWEEN", "value");
+            fail("expected rejection of identifier named BETWEEN");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameLIKE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("LIKE", "value");
+            fail("expected rejection of identifier named LIKE");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameIN() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("IN", "value");
+            fail("expected rejection of identifier named IN");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameIS() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("IS", "value");
+            fail("expected rejection of identifier named IS");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+    /**
+     * Property 'identifiers' (i.e. names) are not allowed to be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or ESCAPE,
+     * as described in {@link javax.jms.Message}. Verify an IAE is thrown if setting a property with these values.
+     */
+    @Test
+    public void testSetPropertyWithNameESCAPE() throws Exception
+    {
+        try
+        {
+            _testMessage.setObjectProperty("ESCAPE", "value");
+            fail("expected rejection of identifier named ESCAPE");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
+
     // ======= String Properties =========
 
     @Test



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org