protected StreamRuleMatcher getMatcher(StreamRule rule) { StreamRuleMatcher matcher = super.getMatcher(rule); assertEquals(matcher.getClass(), RegexMatcher.class); return matcher; }
@Test public void testMissedMatch() { StreamRule rule = getSampleRule(); rule.setValue("^foo"); Message msg = getSampleMessage(); msg.addField("something", "zomg"); StreamRuleMatcher matcher = getMatcher(rule); assertFalse(matcher.match(msg, rule)); }
@Test public void testSuccessfulMatch() { StreamRule rule = getSampleRule(); rule.setValue("^foo"); Message msg = getSampleMessage(); msg.addField("something", "foobar"); StreamRuleMatcher matcher = getMatcher(rule); assertTrue(matcher.match(msg, rule)); }
@Test public void testSuccessfulComplexRegexMatch() { StreamRule rule = getSampleRule(); rule.setField("some_field"); rule.setValue("foo=^foo|bar\\d.+wat"); Message msg = getSampleMessage(); msg.addField("some_field", "bar1foowat"); StreamRuleMatcher matcher = getMatcher(rule); assertTrue(matcher.match(msg, rule)); }