@Test public void testDateEffectiveExpires() { WorkingMemory wm = new KnowledgeBaseImpl("x", null).newStatefulSession(); final RuleImpl rule = new RuleImpl("myrule"); final Calendar past = Calendar.getInstance(); past.setTimeInMillis(10); final Calendar future = Calendar.getInstance(); future.setTimeInMillis(future.getTimeInMillis() + 100000000); rule.setDateEffective(past); rule.setDateExpires(future); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); rule.setDateExpires(past); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); rule.setDateExpires(future); rule.setDateEffective(future); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); }
@Test public void testDateEffective() { WorkingMemory wm = new KnowledgeBaseImpl("x", null).newStatefulSession(); final RuleImpl rule = new RuleImpl("myrule"); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); final Calendar earlier = Calendar.getInstance(); earlier.setTimeInMillis(10); rule.setDateEffective(earlier); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); final Calendar later = Calendar.getInstance(); later.setTimeInMillis(later.getTimeInMillis() + 100000000); assertTrue(later.after(Calendar.getInstance())); rule.setDateEffective(later); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); }
@Test public void testRuleEnabled() { WorkingMemory wm = new KnowledgeBaseImpl("x", null).newStatefulSession(); final RuleImpl rule = new RuleImpl("myrule"); rule.setEnabled(EnabledBoolean.ENABLED_FALSE); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); final Calendar past = Calendar.getInstance(); past.setTimeInMillis(10); rule.setDateEffective(past); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); rule.setEnabled(EnabledBoolean.ENABLED_TRUE); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); }
@Test public void testTimeMachine() { SessionConfiguration conf = SessionConfiguration.newInstance(); conf.setClockType(ClockType.PSEUDO_CLOCK); WorkingMemory wm = new KnowledgeBaseImpl("x", null).newStatefulSession(conf, null); final Calendar future = Calendar.getInstance(); ((PseudoClockScheduler) wm.getSessionClock()).setStartupTime(future.getTimeInMillis()); final RuleImpl rule = new RuleImpl("myrule"); rule.setEnabled(EnabledBoolean.ENABLED_TRUE); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); future.setTimeInMillis(future.getTimeInMillis() + 100000000); rule.setDateEffective(future); assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm)); ((PseudoClockScheduler) wm.getSessionClock()) .advanceTime(1000000000000L, TimeUnit.MILLISECONDS); assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm)); }