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

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


        System.out.println( brl );
    }

    @Test
    public void testGetVariableNameForRHS() {
        RuleModel m = new RuleModel();
        m.name = "blah";

        FactPattern pat = new FactPattern( "Person" );
        pat.setBoundName( "pat" );

        m.addLhsItem( pat );

        List l = m.getAllVariables();
        assertEquals( 1,
                l.size() );
        assertEquals( "pat",
                l.get( 0 ) );
View Full Code Here


    }

    @Test
    public void testIsDSLEnhanced() throws Exception {
        RuleModel m = new RuleModel();

        assertFalse( m.hasDSLSentences() );

        m.addLhsItem( new FactPattern() );
        assertFalse( m.hasDSLSentences() );

        m.addRhsItem( new ActionSetField( "q" ) );

        assertFalse( m.hasDSLSentences() );

        m.addLhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m.addRhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m = new RuleModel();

        m.addLhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m = new RuleModel();
        m.addRhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

    }
View Full Code Here

    }

    @Test
    public void testMetaData() {
        final RuleModel m = new RuleModel();

        final RuleMetadata rm = new RuleMetadata( "foo",
                "bar" );

        // test add
        m.addMetadata( rm );
        assertEquals( 1,
                m.metadataList.length );
        assertEquals( rm,
                m.metadataList[0] );

        // should be able to find it
        RuleMetadata gm = m.getMetaData( "foo" );
        assertNotNull( gm );

        // test add and remove
        final RuleMetadata rm2 = new RuleMetadata( "foo2",
                "bar2" );
        m.addMetadata( rm2 );
        assertEquals( 2,
                m.metadataList.length );
        assertEquals( rm2,
                m.metadataList[1] );
        assertEquals( "@foo(bar)",
                rm.toString() );

        m.removeMetadata( 0 );
        assertEquals( 1,
                m.metadataList.length );
        assertEquals( rm2,
                m.metadataList[0] );
        assertEquals( "@foo2(bar2)",
                (m.metadataList[0]).toString() );

        // should be able to find it now that it was removed
        gm = m.getMetaData( "foo" );
        assertNull( gm );

        // test add via update method
        m.updateMetadata( rm );
        gm = m.getMetaData( "foo" );
        assertNotNull( gm );

        // test update of existing element
        rm.setValue( "bar2" );
        m.updateMetadata( rm );
        gm = m.getMetaData( "foo" );
        assertNotNull( gm );
        assertEquals( "bar2",
                gm.getValue() );

    }
View Full Code Here

                                 m );
    }

    @Test
    public void testCompositeFactPatternWithFromWithDSL() {
        final RuleModel m = new RuleModel();
        m.name = "model";

        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( "A DSL phrase" );
        m.addLhsItem( sen );

        final FactPattern fp1 = new FactPattern( "Data" );
        fp1.setBoundName( "$d" );
        m.addLhsItem( fp1 );

        final CompositeFactPattern cp = new CompositeFactPattern( CompositeFactPattern.COMPOSITE_TYPE_NOT );

        final FactPattern fp2 = new FactPattern( "Person" );
        final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
        ffp1.setExpression( new ExpressionFormLine( new ExpressionVariable( fp1 ) ) );
        ffp1.setFactPattern( fp2 );
        cp.addFactPattern( ffp1 );
        m.addLhsItem( cp );

        final String actual = BRDRLPersistence.getInstance().marshal( m );
        final String expected = "rule \"model\"\n" +
                "dialect \"mvel\"\n" +
                "when\n" +
View Full Code Here

                "dialect \"mvel\"" +
                "when\n" +
                "then\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        assertEquals( 1,
                      m.getImports().getImports().size() );
        assertEquals( "java.util.ArrayList",
                      m.getImports().getImports().get( 0 ).getType() );
    }
View Full Code Here

                "$a : Applicant( )\n" +
                "then\n" +
                "$a.setName( \"Michael\" );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
View Full Code Here

                "$a : Applicant( )\n" +
                "then\n" +
                "$a.addName( \"Michael\" );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
View Full Code Here

                        "$a : Applicant( )\n" +
                        "then\n" +
                        "list.add( $a );\n" +
                        "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshalUsingDSL( drl, Arrays.asList( global ) );

        assertNotNull( m );
        assertEqualsIgnoreWhitespace( drl, BRDRLPersistence.getInstance().marshal( m ) );

        //LHS
View Full Code Here

                "Here's something typed by the user as free-format DRL\n" +
                "$b : Bananna( )\n" +
                "then\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 3,
                      m.lhs.length );
View Full Code Here

                "$a.setName( \"Michael\" );\n" +
                "Here's something typed by the user as free-format DRL\n" +
                "$a.setAge( 40 );\n" +
                "end\n";

        final RuleModel m = BRDRLPersistence.getInstance().unmarshal( drl );
        assertNotNull( m );

        //LHS
        assertEquals( 1,
                      m.lhs.length );
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.