Search in sources :

Example 6 with IntervalTimer

use of org.drools.core.time.impl.IntervalTimer in project drools by kiegroup.

the class RuleBuilderTest method testBuildAttributes.

@Test
public void testBuildAttributes() throws Exception {
    // creates mock objects
    final RuleBuildContext context = mock(RuleBuildContext.class);
    final RuleImpl rule = mock(RuleImpl.class);
    // creates input object
    final RuleDescr ruleDescr = new RuleDescr("my rule");
    ruleDescr.addAttribute(new AttributeDescr("no-loop", "true"));
    ruleDescr.addAttribute(new AttributeDescr("auto-focus", "false"));
    ruleDescr.addAttribute(new AttributeDescr("agenda-group", "my agenda"));
    ruleDescr.addAttribute(new AttributeDescr("activation-group", "my activation"));
    ruleDescr.addAttribute(new AttributeDescr("lock-on-active", ""));
    ruleDescr.addAttribute(new AttributeDescr("enabled", "false"));
    ruleDescr.addAttribute(new AttributeDescr("duration", "60"));
    ruleDescr.addAttribute(new AttributeDescr("calendars", "\"cal1\""));
    ruleDescr.addAttribute(new AttributeDescr("date-effective", "10-Jul-1974"));
    ruleDescr.addAttribute(new AttributeDescr("date-expires", "10-Jul-2040"));
    // creates expected results
    final Calendar effective = Calendar.getInstance();
    effective.setTime(DateUtils.parseDate("10-Jul-1974"));
    final Calendar expires = Calendar.getInstance();
    expires.setTime(DateUtils.parseDate("10-Jul-2040"));
    // defining expectations on the mock object
    when(context.getRule()).thenReturn(rule);
    when(context.getRuleDescr()).thenReturn(ruleDescr);
    when(context.getKnowledgeBuilder()).thenReturn(new KnowledgeBuilderImpl());
    // calling the build method
    RuleBuilder.buildAttributes(context);
    // check expectations
    verify(rule).setNoLoop(true);
    verify(rule).setAutoFocus(false);
    verify(rule).setAgendaGroup("my agenda");
    verify(rule).setActivationGroup("my activation");
    verify(rule).setLockOnActive(true);
    verify(rule).setEnabled(EnabledBoolean.ENABLED_FALSE);
    verify(rule).setTimer(new IntervalTimer(null, null, -1, TimeUtils.parseTimeString("60"), 0));
    verify(rule).setCalendars(new String[] { "cal1" });
    verify(rule).setDateEffective(effective);
    verify(rule).setDateExpires(expires);
}
Also used : RuleBuildContext(org.drools.compiler.rule.builder.RuleBuildContext) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Calendar(java.util.Calendar) RuleDescr(org.drools.drl.ast.descr.RuleDescr) IntervalTimer(org.drools.core.time.impl.IntervalTimer) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Aggregations

IntervalTimer (org.drools.core.time.impl.IntervalTimer)6 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)4 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)4 Test (org.junit.Test)4 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 StringTokenizer (java.util.StringTokenizer)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)2 AttributeDescr (org.drools.compiler.lang.descr.AttributeDescr)2 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 CronExpression (org.drools.core.time.impl.CronExpression)2 CronTimer (org.drools.core.time.impl.CronTimer)2 ExpressionIntervalTimer (org.drools.core.time.impl.ExpressionIntervalTimer)2 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)2 RuleDescr (org.drools.drl.ast.descr.RuleDescr)2 DroolsError (org.drools.compiler.compiler.DroolsError)1 RuleBuildError (org.drools.compiler.compiler.RuleBuildError)1 MVELObjectExpression (org.drools.core.base.mvel.MVELObjectExpression)1 TimerExpression (org.drools.core.time.TimerExpression)1 Timer (org.drools.core.time.impl.Timer)1