@Test public void testRichCondition() { Pattern<Event, Event> pattern = Pattern.<Event>begin("start") .where(mock(IterativeCondition.class)) .where(mock(IterativeCondition.class)) .followedBy("end") .where(mock(IterativeCondition.class)) .or(mock(IterativeCondition.class)); assertTrue(pattern.getCondition() instanceof RichOrCondition); assertTrue(pattern.getPrevious().getCondition() instanceof RichAndCondition); }
@Test public void testNFACompilerUniquePatternName() { // adjust the rule expectedException.expect(MalformedPatternException.class); expectedException.expectMessage("Duplicate pattern name: start. Names must be unique."); Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter()) .followedBy("middle").where(new TestFilter()) .followedBy("start").where(new TestFilter()); // here we must have an exception because of the two "start" patterns with the same name. compile(invalidPattern, false); }
@Test public void testNFACompilerPatternEndsWithNotFollowedBy() { // adjust the rule expectedException.expect(MalformedPatternException.class); expectedException.expectMessage("NotFollowedBy is not supported as a last part of a Pattern!"); Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter()) .followedBy("middle").where(new TestFilter()) .notFollowedBy("end").where(new TestFilter()); // here we must have an exception because of the two "start" patterns with the same name. compile(invalidPattern, false); }
@Test(expected = IllegalArgumentException.class) public void testPatternTimesNegativeTimes() throws Exception { Pattern.begin("start").where(dummyCondition()).times(-1); }
@Test public void testStartWithOneOrMoreStrict() throws Exception { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new SimpleCondition<Event>() { private static final long serialVersionUID = 5726188262756267490L; @Override public boolean filter(Event value) throws Exception { return value.getName().equals("a"); } }).oneOrMore().consecutive(); testStartWithOneOrZeroOrMoreStrict(pattern); }
@Test(expected = MalformedPatternException.class) public void testPatternCanHaveQuantifierSpecifiedOnce3() throws Exception { Pattern.begin("start").where(dummyCondition()).times(1).oneOrMore(); }
@Test(expected = MalformedPatternException.class) public void testPatternCanHaveQuantifierSpecifiedOnce4() throws Exception { Pattern.begin("start").where(dummyCondition()).oneOrMore().oneOrMore(); }
@Override public NFA<Event> createNFA() { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new StartFilter()) .within(Time.milliseconds(10L)); return NFACompiler.compileFactory(pattern, handleTimeout).createNFA(); } }
@Test public void testStartWithZeroOrMoreStrict() throws Exception { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new SimpleCondition<Event>() { private static final long serialVersionUID = 5726188262756267490L; @Override public boolean filter(Event value) throws Exception { return value.getName().equals("a"); } }).oneOrMore().optional().consecutive(); testStartWithOneOrZeroOrMoreStrict(pattern); }
@Test(expected = MalformedPatternException.class) public void testPatternCanHaveQuantifierSpecifiedOnce1() throws Exception { Pattern.begin("start").where(dummyCondition()).oneOrMore().oneOrMore().optional(); }
@Test(expected = MalformedPatternException.class) public void testUntilCannotBeAppliedToTimes() throws Exception { Pattern.begin("start").where(dummyCondition()).times(1).until(dummyCondition()); }
@Test(expected = MalformedPatternException.class) public void testPatternCanHaveQuantifierSpecifiedOnce2() throws Exception { Pattern.begin("start").where(dummyCondition()).oneOrMore().optional().times(1); }
@Test(expected = MalformedPatternException.class) public void testPatternCanHaveQuantifierSpecifiedOnce5() throws Exception { Pattern.begin("start").where(dummyCondition()).oneOrMore().oneOrMore().optional(); }
@Test(expected = MalformedPatternException.class) public void testUntilCannotBeAppliedTwice() throws Exception { Pattern.begin("start").where(dummyCondition()).until(dummyCondition()).until(dummyCondition()); }
@Override public NFA<Event> createNFA() { Pattern<Event, ?> pattern = Pattern.<Event>begin("start") .subtype(SubEvent.class) .where(new MiddleFilter()) .or(new SubEventEndFilter()) .times(2) .within(Time.milliseconds(10L)); return NFACompiler.compileFactory(pattern, handleTimeout).createNFA(); } }