ConcreteComparisonFilter matchesFilter = new ConcreteComparisonFilter(
ComparisonFilter.Operator.MATCHES);
ConcreteComparisonFilter likeFilter = new ConcreteComparisonFilter(
ComparisonFilter.Operator.LIKE);
assertTrue(containsFilter.isOperatorMatch(new TextValue("blah blah"),
new TextValue("ah bl")));
assertTrue(containsFilter.isOperatorMatch(new TextValue("foo bar"),
new TextValue("foo ")));
assertTrue(containsFilter.isOperatorMatch(new TextValue("foo bar"),
new TextValue(" bar")));
assertFalse(containsFilter.isOperatorMatch(new TextValue("abc123"),
new TextValue("bd")));
assertTrue(startsWithFilter.isOperatorMatch(new TextValue("this is a " +
"text value"), new TextValue("this is")));
assertFalse(startsWithFilter.isOperatorMatch(new TextValue("foo bar"),
new TextValue("oo bar")));
assertTrue(endsWithFilter.isOperatorMatch(new TextValue("this is a " +
"text value"), new TextValue("text value")));
assertFalse(endsWithFilter.isOperatorMatch(new TextValue("foo bar"),
new TextValue("foo ba")));
assertTrue(matchesFilter.isOperatorMatch(new TextValue("aaaaaa123"),
new TextValue("a*123")));
assertTrue(matchesFilter.isOperatorMatch(new TextValue("abcdefghijk"),
new TextValue("[a-k]+")));
assertFalse(matchesFilter.isOperatorMatch(new TextValue("abc1234"),
new TextValue("a*123")));
assertFalse(matchesFilter.isOperatorMatch(new TextValue("blah blah"),
new TextValue("%^@%!%$#^*&*$!@#$((((")));
// Test partial
assertFalse(matchesFilter.isOperatorMatch(new TextValue("aaaaaaa123"),
new TextValue("a*")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("aaaabbbccc"),
new TextValue("a%b_b%c")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("aaaabbbccc"),
new TextValue("aaqqb_c%c")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("aaaabbbccc"),
new TextValue("a%%b_b%c")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("aaaabbbccc"),
new TextValue("%")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foo bar"),
new TextValue("foo_bar")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foo%bar"),
new TextValue("foo_bar")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("blah blah"),
new TextValue("bla%b%aa")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foobar"),
new TextValue("foo__r")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("foobr"),
new TextValue("foo__r")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("foobaar"),
new TextValue("foo__r")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foobaar"),
new TextValue("foo__%_r")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foobaaar"),
new TextValue("foo__%_r")));
assertTrue(likeFilter.isOperatorMatch(new TextValue("foobaaaar"),
new TextValue("foo__%_r")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("foobar"),
new TextValue("foo__%_r")));
assertFalse(likeFilter.isOperatorMatch(new TextValue("foobr"),
new TextValue("foo__%_r")));
// Partial match:
assertFalse(likeFilter.isOperatorMatch(new TextValue("blah blah"),
new TextValue("bla%b%a")));
// Test non-strings:
assertTrue(containsFilter.isOperatorMatch(new NumberValue(123),
new NumberValue(3)));
assertTrue(containsFilter.isOperatorMatch(new NumberValue(123.45),
new TextValue("23.4")));
assertFalse(containsFilter.isOperatorMatch(new NumberValue(23423),
BooleanValue.TRUE));
assertTrue(startsWithFilter.isOperatorMatch(BooleanValue.FALSE,
new TextValue("fa")));
assertTrue(endsWithFilter.isOperatorMatch(new NumberValue(123.456),
new TextValue("456")));
assertTrue(matchesFilter.isOperatorMatch(new NumberValue(123),
new TextValue(".*")));
assertTrue(likeFilter.isOperatorMatch(new NumberValue(123),
new TextValue("_2%")));
}