Package org.drools.core

Examples of org.drools.core.RuleBase


    @Test
    public void testApplicationDataView() throws Exception {
        Reader source = new InputStreamReader(DebugViewsTest.class.getResourceAsStream("/debug.drl"));
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl(source);
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage(builder.getPackage());
        StatefulSession session = ruleBase.newStatefulSession();
        session.setGlobal("s", "String");
        List list = new ArrayList();
        list.add("Value");
        session.setGlobal("list", list);
        Entry[] globals = ((MapGlobalResolver) session.getGlobalResolver()).getGlobals();
View Full Code Here


    @Test @Ignore
    public void testAgendaView() throws Exception {
        Reader source = new InputStreamReader(DebugViewsTest.class.getResourceAsStream("/debug.drl"));
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl(source);
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage(builder.getPackage());
        AbstractWorkingMemory session = (AbstractWorkingMemory) ruleBase.newStatefulSession();
        List list = new ArrayList();
        session.setGlobal("list", list);
        session.insert("String1");
        String focusName = session.getAgenda().getFocusName();
        assertEquals("MAIN", focusName);
View Full Code Here

     * VIEWS (which are using reflection)
     */
   
    @Test
    public void testWorkingMemoryView() throws Exception {
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        AbstractWorkingMemory session = (AbstractWorkingMemory) ruleBase.newStatefulSession();
        session.insert("Test1");
        session.insert("Test2");
        Object[] objects = session.iterateObjectsToList().toArray();
        assertEquals(2, objects.length);
        assertTrue(("Test1".equals(objects[0]) && "Test2".equals(objects[1])) ||
View Full Code Here

    private transient ReteooRuleBase ruleBase;
   
   
    public static void setMode( VirtualPropertyMode newMode, KnowledgeBase kBase ) {
        RuleBase ruleBase = ((KnowledgeBaseImpl) kBase).getRuleBase();
        KieComponentFactory rcf = ((ReteooRuleBase) ruleBase).getConfiguration().getComponentFactory();
        ClassBuilderFactory cbf = rcf.getClassBuilderFactory();
        rcf.getTraitFactory().mode = newMode;
        switch ( newMode ) {
            case MAP    :
View Full Code Here

public class RuleBaseFactoryTest {

    @Test
    public void testReteOO() {
        final RuleBase rb = RuleBaseFactory.newRuleBase();
        assertTrue( rb instanceof org.drools.core.reteoo.ReteooRuleBase );

        assertTrue( !"default".equals( ((InternalRuleBase) rb).getId() ) );
        assertTrue( !"".equals( ((InternalRuleBase) rb).getId() ) );
        assertNotNull( ((InternalRuleBase) rb).getId() );

        final RuleBase rb2 = RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
                                                          null );

        assertTrue( rb2 instanceof org.drools.core.reteoo.ReteooRuleBase );
        assertNotSame( rb2,
                       rb );
View Full Code Here

    }

    @Test
    public void testNotRemoveIdentities() throws Exception {
        // Default is remove identity FALSE
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( this.pkg );

        this.workingMemory = ruleBase.newStatefulSession();
        this.workingMemory.insert( "F1" );
        this.workingMemory.insert( "F2" );
        this.workingMemory.insert( "F3" );
        this.workingMemory.insert( "F4" );
View Full Code Here

    @Test
    public void testRemoveIdentities() throws Exception {
        System.setProperty( "drools.removeIdentities",
                            "true" );
        try {
            final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
            ruleBase.addPackage( this.pkg );

            this.workingMemory = ruleBase.newStatefulSession();
            this.workingMemory.insert( "F1" );
            this.workingMemory.insert( "F2" );
            this.workingMemory.insert( "F3" );
            this.workingMemory.insert( "F4" );
View Full Code Here

        betaConstraints = new SingleBetaConstraints( constraints,
                                                     config );

        BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );

        RuleBase rb = RuleBaseFactory.newRuleBase();
        StatefulSession ss = rb.newStatefulSession();

        InternalFactHandle fh1 = (InternalFactHandle) ss.insert( new Foo( "brie",
                                                                          1 ) );
        InternalFactHandle fh2 = (InternalFactHandle) ss.insert( new Foo( "brie",
                                                                          1 ) );
View Full Code Here

       
        betaConstraints = new SingleBetaConstraints(constraints, config);
       
        BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );
       
        RuleBase rb = RuleBaseFactory.newRuleBase();
        StatefulSession ss = rb.newStatefulSession();
       
        InternalFactHandle fh1 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
        InternalFactHandle fh2 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
        InternalFactHandle fh3 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
        InternalFactHandle fh4 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
View Full Code Here

*/
public class OtherwiseTest {
   
    @Test
    public void testOneRuleFiringNoOtherwise() throws Exception {
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );

        final Package pkg = new Package( "Miss Manners" );
        pkg.setClassFieldAccessorCache( new ClassFieldAccessorCache( Thread.currentThread().getContextClassLoader() ) );
        final Rule rule1 = getRule( "rule1" );
        pkg.addRule( rule1 );

        final Rule ruleOtherwise = getOtherwise( "rule2" );
        pkg.addRule( ruleOtherwise );

        ruleBase.addPackage( pkg );

        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
        workingMemory.insert( new TestBean() );
        workingMemory.fireAllRules();

        assertTrue( ((MockConsequence) rule1.getConsequence()).fired );
        assertFalse( ((MockConsequence) ruleOtherwise.getConsequence()).fired );
View Full Code Here

TOP

Related Classes of org.drools.core.RuleBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.