Author: jmesnil
Date: 2010-03-04 10:31:34 -0500 (Thu, 04 Mar 2010)
New Revision: 8913
Modified:
trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java
trunk/src/main/org/hornetq/core/filter/impl/Operator.java
trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java
Log:
fix message filter
* allow an identifier as a valid message filter
* does not treat a property which is not set as a match failure (false) with LIKE AND NOT
IN,
return null instead
Modified: trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java 2010-03-04 11:44:07 UTC
(rev 8912)
+++ trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java 2010-03-04 15:31:34 UTC
(rev 8913)
@@ -64,10 +64,12 @@
private final Map<SimpleString, Identifier> identifiers = new
HashMap<SimpleString, Identifier>();
- private final Operator operator;
-
private final FilterParser parser = new FilterParser();
+ private final Object result;
+
+ private final Class<? extends Object> resultType;
+
// Static ---------------------------------------------------------
/**
@@ -103,7 +105,10 @@
try
{
- operator = (Operator)parser.parse(sfilterString, identifiers);
+
+ result = parser.parse(sfilterString, identifiers);
+ resultType = result.getClass();
+
}
catch (Throwable e)
{
@@ -145,11 +150,17 @@
}
- // Compute the result of this operator
-
- boolean res = (Boolean)operator.apply();
-
- return res;
+ if (resultType.equals(Identifier.class))
+ return (Boolean)((Identifier)result).getValue();
+ else if (resultType.equals(Operator.class))
+ {
+ Operator op = (Operator) result;
+ System.out.println(result);
+ return (Boolean)op.apply();
+ } else
+ {
+ throw new Exception("Bad object type: " + result);
+ }
}
catch (Exception e)
{
Modified: trunk/src/main/org/hornetq/core/filter/impl/Operator.java
===================================================================
--- trunk/src/main/org/hornetq/core/filter/impl/Operator.java 2010-03-04 11:44:07 UTC (rev
8912)
+++ trunk/src/main/org/hornetq/core/filter/impl/Operator.java 2010-03-04 15:31:34 UTC (rev
8913)
@@ -911,7 +911,7 @@
if (arg1 == null)
{
- return Boolean.FALSE;
+ return null;
}
if (class1 != Operator.SIMPLE_STRING)
@@ -1002,7 +1002,7 @@
computeArgument1();
if (arg1 == null)
{
- return true;
+ return null;
}
if (class1 != Operator.SIMPLE_STRING)
{
Modified: trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2010-03-04
11:44:07 UTC (rev 8912)
+++ trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2010-03-04
15:31:34 UTC (rev 8913)
@@ -59,9 +59,6 @@
public void testInvalidString() throws Exception
{
- testInvalidFilter("invalid");
- testInvalidFilter(new SimpleString("invalid"));
-
testInvalidFilter("color = 'red");
testInvalidFilter(new SimpleString("color = 'red"));
@@ -161,6 +158,13 @@
testBoolean("MyBoolean", true);
}
+ public void testIdentifier() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("MyBoolean"));
+
+ testBoolean("MyBoolean", true);
+ }
+
public void testDifferentNullString() throws Exception
{
filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
@@ -227,6 +231,36 @@
}
+ public void testNOT_INWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT IN
('foo','jms','test')"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
+ public void testNOT_LIKEWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT LIKE
'1_3'"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
+ public void testIS_NOT_NULLWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp IS NOT
NULL"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
public void testStringLike() throws Exception
{
// test LIKE operator with no wildcards
@@ -410,10 +444,10 @@
public void testNotLikeExpression() throws Exception
{
- // Should evaluate to true since the property MyString does not exist
+ // Should evaluate to false when the property MyString is not set
filter = FilterImpl.createFilter(new SimpleString("NOT (MyString LIKE
'%')"));
- Assert.assertTrue(filter.match(message));
+ Assert.assertFalse(filter.match(message));
}
public void testStringLikePercentWildcard() throws Exception
Modified: trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java 2010-03-04
11:44:07 UTC (rev 8912)
+++ trunk/tests/src/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java 2010-03-04
15:31:34 UTC (rev 8913)
@@ -417,7 +417,7 @@
OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("lose"),
pattern, true);
OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("loose"),
pattern, false);
- OperatorTest.assertSuccess(Operator.LIKE, null, pattern, false);
+ OperatorTest.assertSuccess(Operator.LIKE, null, pattern, null);
}
public void test_LIKE_ESCAPE() throws Exception
@@ -426,7 +426,7 @@
SimpleString escapeChar = new SimpleString("\\");
OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, true);
OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new SimpleString("bar"),
pattern, escapeChar, false);
- OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, null, pattern, escapeChar,
false);
+ OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, null, pattern, escapeChar, null);
OperatorTest.assertFailure(Operator.LIKE_ESCAPE,
new SimpleString("_foo"),
@@ -440,7 +440,7 @@
OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("123"),
pattern, false);
OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("12993"),
pattern, false);
OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("1234"),
pattern, true);
- OperatorTest.assertSuccess(Operator.NOT_LIKE, null, pattern, false);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE, null, pattern, null);
}
public void test_NOT_LIKE_ESCAPE() throws Exception
@@ -449,7 +449,7 @@
SimpleString escapeChar = new SimpleString("\\");
OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, false);
OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("bar"), pattern, escapeChar, true);
- OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, null, pattern, escapeChar,
false);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, null, pattern, escapeChar,
null);
OperatorTest.assertFailure(Operator.NOT_LIKE_ESCAPE,
new SimpleString("_foo"),