private static ReteooBuilder[] getReteBuilders(int count) { System.out.println("Creating "+count+" ReteBuilder's"); ReteooBuilder[] reteBuilders = new ReteooBuilder[count]; RuleBaseConfiguration conf = new RuleBaseConfiguration(); for (int i = 0; i < reteBuilders.length; i++) { reteBuilders[i] = new ReteooBuilder(new KnowledgeBaseImpl( "id1", conf )); } return reteBuilders; }
@Before public void setUp() throws Exception { this.builder = new ReteooRuleBuilder(); this.rulebase = new KnowledgeBaseImpl( "default", null ); }
@Test public void testDateEffective() { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl( "x", null).newKieSession(); 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 testDateExpires() throws Exception { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(); final RuleImpl rule = new RuleImpl( "myrule" ); assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) ); final Calendar earlier = Calendar.getInstance(); earlier.setTimeInMillis( 10 ); rule.setDateExpires( earlier ); assertFalse( rule.isEffective(null, new RuleTerminalNode(), wm ) ); final Calendar later = Calendar.getInstance(); later.setTimeInMillis( later.getTimeInMillis() + 100000000 ); rule.setDateExpires( later ); assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) ); }
final String className = TestEvalExpression.class.getName(); KnowledgeBaseImpl kBase = new KnowledgeBaseImpl( "xxx", null );
@Test public void testDateEffectiveExpires() { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x",null).newKieSession(); 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 testRuleEnabled() { WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(); 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 testStaticImports() { KnowledgeBaseImpl base = new KnowledgeBaseImpl( "default", null); // assume empty knowledge base assertTrue( base.getPackages().length == 0 ); // add package with function static import into knowledge base InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.drools.test" ); pkg.addStaticImport( "org.drools.function.myFunction" ); base.addPackage( pkg ); // verify package has been added assertTrue( base.getPackages().length == 1 ); // retrieve copied and merged package from the base InternalKnowledgePackage copy = base.getPackage( "org.drools.test" ); assertEquals( Collections.singleton( "org.drools.function.myFunction" ), copy.getStaticImports() ); } }
@Test public void testTimeMachine() { SessionConfiguration conf = SessionConfiguration.newInstance(); conf.setClockType( ClockType.PSEUDO_CLOCK ); WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(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 )); }
public BuildContext createContext() { RuleBaseConfiguration conf = new RuleBaseConfiguration(); KnowledgeBaseImpl rbase = new KnowledgeBaseImpl( "ID", conf ); BuildContext buildContext = new BuildContext( rbase ); RuleImpl rule = new RuleImpl( "rule1").setPackage( "org.pkg1" ); InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.pkg1" ); pkg.getDialectRuntimeRegistry().setDialectData( "mvel", new MVELDialectRuntimeData() ); pkg.addRule( rule ); buildContext.setRule( rule ); return buildContext; }
public BuildContext createContext() { RuleBaseConfiguration conf = new RuleBaseConfiguration(); KnowledgeBaseImpl rbase = new KnowledgeBaseImpl( "ID", conf ); BuildContext buildContext = new BuildContext( rbase ); RuleImpl rule = new RuleImpl( "rule1").setPackage( "org.pkg1" ); InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.pkg1" ); pkg.getDialectRuntimeRegistry().setDialectData( "mvel", new MVELDialectRuntimeData() ); pkg.addRule( rule ); buildContext.setRule( rule ); return buildContext; }
public BuildContext createContext() { RuleBaseConfiguration conf = new RuleBaseConfiguration(); KnowledgeBaseImpl rbase = new KnowledgeBaseImpl( "ID", conf ); BuildContext buildContext = new BuildContext( rbase ); RuleImpl rule = new RuleImpl( "rule1").setPackage( "org.pkg1" ); InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.pkg1" ); pkg.getDialectRuntimeRegistry().setDialectData( "mvel", new MVELDialectRuntimeData() ); pkg.addRule( rule ); buildContext.setRule( rule ); return buildContext; }
public BuildContext createContext() { RuleBaseConfiguration conf = new RuleBaseConfiguration(); KnowledgeBaseImpl rbase = new KnowledgeBaseImpl( "ID", conf ); BuildContext buildContext = new BuildContext( rbase ); RuleImpl rule = new RuleImpl( "rule1").setPackage( "org.pkg1" ); InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.pkg1" ); pkg.getDialectRuntimeRegistry().setDialectData( "mvel", new MVELDialectRuntimeData() ); pkg.addRule( rule ); buildContext.setRule( rule ); return buildContext; } }