Package org.drools.guvnor.models.commons.shared.rule

Examples of org.drools.guvnor.models.commons.shared.rule.RuleModel


                model.lhs[0] );
    }

    @Test
    public void testRemoveItemRhs() {
        final RuleModel model = new RuleModel();

        model.rhs = new IAction[3];
        final ActionRetractFact r0 = new ActionRetractFact( "x" );
        final ActionRetractFact r1 = new ActionRetractFact( "y" );
        final ActionRetractFact r2 = new ActionRetractFact( "z" );

        model.rhs[0] = r0;
        model.rhs[1] = r1;
        model.rhs[2] = r2;

        model.removeRhsItem( 1 );

        assertEquals( 2,
                model.rhs.length );
        assertEquals( r0,
                model.rhs[0] );
View Full Code Here


                vars.get( 2 ) );
    }
*/
    @Test
    public void testScopedVariablesWithCompositeFact() {
        RuleModel m = new RuleModel();
        FactPattern p = new FactPattern();

        CompositeFieldConstraint cf = new CompositeFieldConstraint();
        cf.addConstraint( new SingleFieldConstraint( "x" ) );
        p.addConstraint( cf );

        SingleFieldConstraint sf = new SingleFieldConstraint( "q" );
        sf.setFieldBinding( "abc" );
        p.addConstraint( sf );

        SingleFieldConstraint sf2 = new SingleFieldConstraint( "q" );
        sf2.setFieldBinding( "qed" );
        cf.addConstraint( sf2 );
        m.addLhsItem( p );

        List vars = m.getAllVariables();
        assertEquals( 1,
                vars.size() );
        assertEquals( "abc",
                vars.get( 0 ) );
    }
View Full Code Here

                varTypeCar.getFactType() );
    }
*/
    @Test
    public void testAddItemLhsAtSpecificPosition() {
        final RuleModel model = new RuleModel();

        final FactPattern a = new FactPattern();
        model.addLhsItem( a );

        assertEquals( 1,
                model.lhs.length );

        final FactPattern b = new FactPattern();
        model.addLhsItem( b );

        assertEquals( 2,
                model.lhs.length );

        final FactPattern c = new FactPattern();
        model.addLhsItem( c,
                true );

        assertEquals( 3,
                model.lhs.length );

        assertEquals( a,
                model.lhs[0] );
        assertEquals( b,
                model.lhs[1] );
        assertEquals( c,
                model.lhs[2] );

        final FactPattern d = new FactPattern();
        model.addLhsItem( d,
                false );

        assertEquals( 4,
                model.lhs.length );

        assertEquals( d,
                model.lhs[0] );
        assertEquals( a,
                model.lhs[1] );
        assertEquals( b,
                model.lhs[2] );
        assertEquals( c,
                model.lhs[3] );

        final FactPattern e = new FactPattern();
        model.addLhsItem( e,
                2 );

        assertEquals( 5,
                model.lhs.length );

        assertEquals( d,
                model.lhs[0] );
        assertEquals( a,
                model.lhs[1] );
        assertEquals( e,
                model.lhs[2] );
        assertEquals( b,
                model.lhs[3] );
        assertEquals( c,
                model.lhs[4] );

        //test auto-bound
        final FactPattern f = new FactPattern();
        final FactPattern g = new FactPattern();
        model.addLhsItem( f,
                -1 );
        model.addLhsItem( g,
                100 );

        assertEquals( 7,
                model.lhs.length );

        assertEquals( f,
                model.lhs[0] );
        assertEquals( d,
                model.lhs[1] );
        assertEquals( a,
                model.lhs[2] );
        assertEquals( e,
                model.lhs[3] );
        assertEquals( b,
                model.lhs[4] );
        assertEquals( c,
                model.lhs[5] );
        assertEquals( g,
                model.lhs[6] );

        model.moveLhsItemDown( 5 );
        model.moveLhsItemUp( 3 );

        assertEquals( 7,
                model.lhs.length );

        assertEquals( f,
                model.lhs[0] );
        assertEquals( d,
                model.lhs[1] );
        assertEquals( e,
                model.lhs[2] );
        assertEquals( a,
                model.lhs[3] );
        assertEquals( b,
                model.lhs[4] );
        assertEquals( g,
                model.lhs[5] );
        assertEquals( c,
                model.lhs[6] );

        model.moveLhsItemUp( 0 );
        model.moveLhsItemDown( 6 );

        assertEquals( 7,
                model.lhs.length );

        assertEquals( f,
View Full Code Here

    }

    @Test
    public void testAddItemRhsAtSpecificPosition() {
        final RuleModel model = new RuleModel();

        final ActionSetField a = new ActionSetField();
        model.addRhsItem( a );

        assertEquals( 1,
                model.rhs.length );

        final ActionSetField b = new ActionSetField();
        model.addRhsItem( b );

        assertEquals( 2,
                model.rhs.length );

        final ActionSetField c = new ActionSetField();
        model.addRhsItem( c,
                true );

        assertEquals( 3,
                model.rhs.length );

        assertEquals( a,
                model.rhs[0] );
        assertEquals( b,
                model.rhs[1] );
        assertEquals( c,
                model.rhs[2] );

        final ActionSetField d = new ActionSetField();
        model.addRhsItem( d,
                false );

        assertEquals( 4,
                model.rhs.length );

        assertEquals( d,
                model.rhs[0] );
        assertEquals( a,
                model.rhs[1] );
        assertEquals( b,
                model.rhs[2] );
        assertEquals( c,
                model.rhs[3] );

        final ActionSetField e = new ActionSetField();
        model.addRhsItem( e,
                2 );

        assertEquals( 5,
                model.rhs.length );

        assertEquals( d,
                model.rhs[0] );
        assertEquals( a,
                model.rhs[1] );
        assertEquals( e,
                model.rhs[2] );
        assertEquals( b,
                model.rhs[3] );
        assertEquals( c,
                model.rhs[4] );

        //test auto-bound
        final ActionSetField f = new ActionSetField();
        final ActionSetField g = new ActionSetField();
        model.addRhsItem( f,
                -1 );
        model.addRhsItem( g,
                100 );

        assertEquals( 7,
                model.rhs.length );

        assertEquals( f,
                model.rhs[0] );
        assertEquals( d,
                model.rhs[1] );
        assertEquals( a,
                model.rhs[2] );
        assertEquals( e,
                model.rhs[3] );
        assertEquals( b,
                model.rhs[4] );
        assertEquals( c,
                model.rhs[5] );
        assertEquals( g,
                model.rhs[6] );

        model.moveRhsItemDown( 5 );
        model.moveRhsItemUp( 3 );

        assertEquals( 7,
                model.rhs.length );

        assertEquals( f,
                model.rhs[0] );
        assertEquals( d,
                model.rhs[1] );
        assertEquals( e,
                model.rhs[2] );
        assertEquals( a,
                model.rhs[3] );
        assertEquals( b,
                model.rhs[4] );
        assertEquals( g,
                model.rhs[5] );
        assertEquals( c,
                model.rhs[6] );

        model.moveRhsItemUp( 0 );
        model.moveRhsItemDown( 6 );

        assertEquals( 7,
                model.rhs.length );

        assertEquals( f,
View Full Code Here

    }

    @Test
    public void testBoundFromCompositeFactFinder() {
        final RuleModel model = new RuleModel();

        model.lhs = new IPattern[1];

        final FromCompositeFactPattern fcfp = new FromCompositeFactPattern();
        final FactPattern x = new FactPattern( "Car" );
        x.setBoundName( "x" );
        final SingleFieldConstraint a = new SingleFieldConstraint( "name" );
        a.setFieldBinding( "a" );
        a.setFieldType( "String" );
        x.addConstraint( a );
        fcfp.setFactPattern( x );

        model.lhs[0] = fcfp;

        assertEquals( x,
                model.getLHSBoundFact( "x" ) );

        assertEquals( 1,
                model.getLHSBoundFacts().size() );
        assertEquals( "x",
                model.getLHSBoundFacts().get( 0 ) );

        assertEquals( a,
                model.getLHSBoundField( "a" ) );

        assertEquals( "Car",
                model.getLHSBindingType( "x" ) );
        assertEquals( "String",
                model.getLHSBindingType( "a" ) );

        assertEquals( x,
                model.getLHSParentFactPatternForBinding( "a" ) );

        assertEquals( 2,
                model.getAllLHSVariables().size() );
        assertTrue( model.getAllLHSVariables().contains( "x" ) );
        assertTrue( model.getAllLHSVariables().contains( "a" ) );

        model.rhs = new IAction[1];
        final ActionSetField set = new ActionSetField();
        set.setVariable( "x");
        model.rhs[0] = set;

        assertTrue( model.isBoundFactUsed( "x" ) );

        assertEquals( 1,
                model.lhs.length );
        assertFalse( model.removeLhsItem( 0 ) );
        assertEquals( 1,
                model.lhs.length );
    }
View Full Code Here

    }

    @Test
    public void testFieldBindingWithNoConstraints() {
        // to satisfy JBRULES-850
        RuleModel m = getModelWithNoConstraints();
        String s = BRDRLPersistence.getInstance().marshal( m );
        // System.out.println(s);
        assertTrue( s.contains( "Person( f1 : age)" ) );

        checkMarshallUnmarshall( s, m );
View Full Code Here

        checkMarshallUnmarshall( s, m );
    }

    @Test
    public void textIsNullOperator() {
        final RuleModel m = new RuleModel();
        m.name = "IsNullOperator";
        final FactPattern pat = new FactPattern( "Person" );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldName( "age" );
        con.setOperator( "== null" );
        pat.addConstraint( con );

        m.addLhsItem( pat );

        String s = BRDRLPersistence.getInstance().marshal( m );
        assertTrue( s.indexOf( "Person( age == null )" ) != -1 );
        checkMarshallUnmarshall( s, m );
    }
View Full Code Here

        checkMarshallUnmarshall( s, m );
    }

    @Test
    public void textIsNotNullOperator() {
        final RuleModel m = new RuleModel();
        m.name = "IsNotNullOperator";
        final FactPattern pat = new FactPattern( "Person" );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldName( "age" );
        con.setOperator( "!= null" );
        pat.addConstraint( con );

        m.addLhsItem( pat );

        String s = BRDRLPersistence.getInstance().marshal( m );
        assertTrue( s.indexOf( "Person( age != null )" ) != -1 );
        checkMarshallUnmarshall( s, m );
    }
View Full Code Here

        assertTrue( s.indexOf( "Person( age != null )" ) != -1 );
        checkMarshallUnmarshall( s, m );
    }

    private RuleModel getModelWithNoConstraints() {
        final RuleModel m = new RuleModel();
        m.name = "Complex Rule";
        final FactPattern pat = new FactPattern( "Person" );
        pat.setBoundName( "p1" );
        final SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldBinding( "f1" );
        con.setFieldName( "age" );
        // con.operator = "<";
        // con.value = "42";
        pat.addConstraint( con );

        m.addLhsItem( pat );

        return m;
    }
View Full Code Here

        return m;
    }

    @Test
    public void testOrComposite() throws Exception {
        RuleModel m = new RuleModel();
        m.name = "or";
        CompositeFactPattern cp = new CompositeFactPattern(
                CompositeFactPattern.COMPOSITE_TYPE_OR );
        FactPattern p1 = new FactPattern( "Person" );
        SingleFieldConstraint sf1 = new SingleFieldConstraint( "age" );
        sf1.setOperator( "==" );
        sf1.setValue( "42" );
        p1.addConstraint( sf1 );

        cp.addFactPattern( p1 );

        FactPattern p2 = new FactPattern( "Person" );
        SingleFieldConstraint sf2 = new SingleFieldConstraint( "age" );
        sf2.setOperator( "==" );
        sf2.setValue( "43" );
        p2.addConstraint( sf2 );

        cp.addFactPattern( p2 );

        m.addLhsItem( cp );

        String result = BRDRLPersistence.getInstance().marshal( m );
        assertTrue( result.indexOf( "( Person( age == 42 ) or Person( age == 43 ) )" ) > 0 );

        checkMarshallUnmarshall( result, m );
View Full Code Here

TOP

Related Classes of org.drools.guvnor.models.commons.shared.rule.RuleModel

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.