Package org.drools.ide.common.client.modeldriven.brl

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern


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

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );
        fp0.setNegated( true );
        model.lhs[0] = fp0;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 1,
                      clone.lhs.length );
        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) clone.lhs[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );
        assertEquals( fp0.isNegated(),
                      fp0Clone.isNegated() );
    }
View Full Code Here


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

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );
        fp0.setNegated( true );
        CEPWindow cepWindow0 = new CEPWindow();
        cepWindow0.setOperator( SuggestionCompletionEngine.getCEPWindowOperators().get( 0 ) );
        cepWindow0.setParameter( "cepWindow0P0",
                                 "cepWindow0P0Value" );
        cepWindow0.setParameter( "cepWindow0P1",
                                 "cepWindow0P1Value" );
        fp0.setWindow( cepWindow0 );
        model.lhs[0] = fp0;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 1,
                      clone.lhs.length );
        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) clone.lhs[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );
        assertEquals( fp0.isNegated(),
                      fp0Clone.isNegated() );

        assertNotSame( fp0.getWindow(),
                       fp0Clone.getWindow() );
        assertNotNull( fp0Clone.getWindow() );
        assertTrue( fp0Clone.getWindow() instanceof CEPWindow );
        CEPWindow cepWindow0Clone = (CEPWindow) fp0Clone.getWindow();
        assertEquals( cepWindow0.getOperator(),
                      cepWindow0Clone.getOperator() );
        assertEquals( cepWindow0.getParameters().size(),
                      cepWindow0Clone.getParameters().size() );
        assertNotNull( cepWindow0Clone.getParameter( "cepWindow0P0" ) );
View Full Code Here

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

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );

        SingleFieldConstraint sfc0 = new SingleFieldConstraint();
        sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc0.setFieldBinding( "$sfc0" );
        sfc0.setFieldName( "sfc0" );
        sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc0.setOperator( "==" );
        sfc0.setParameter( "sfc0p0",
                           "sfc0p0Value" );
        sfc0.setValue( "sfc0Value" );
        fp0.addConstraint( sfc0 );

        SingleFieldConstraint sfc1 = new SingleFieldConstraint();
        sfc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc1.setFieldBinding( "$sfc1" );
        sfc1.setFieldName( "sfc1" );
        sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc1.setOperator( "==" );
        sfc1.setParameter( "sfc1p0",
                           "sfc1p0Value" );
        sfc1.setValue( "sfc1Value" );
        fp0.addConstraint( sfc1 );

        model.lhs[0] = fp0;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 1,
                      clone.lhs.length );
        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) clone.lhs[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );

        assertEquals( 2,
                      fp0Clone.constraintList.constraints.length );

        assertNotSame( fp0.constraintList.constraints[0],
View Full Code Here

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

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );

        SingleFieldConstraint sfc0 = new SingleFieldConstraint();
        sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc0.setFieldBinding( "$sfc0" );
        sfc0.setFieldName( "sfc0" );
        sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc0.setOperator( "==" );
        sfc0.setParameter( "sfc0p0",
                           "sfc0p0Value" );
        sfc0.setValue( "sfc0Value" );
        fp0.addConstraint( sfc0 );

        sfc0.addNewConnective();
        ConnectiveConstraint sfc0cc0 = sfc0.connectives[0];
        sfc0cc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc0cc0.setFieldName( "sfc0" );
        sfc0cc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc0cc0.setOperator( "|| ==" );
        sfc0cc0.setParameter( "sfc0cc0p0",
                              "sfc0cc0p0Value" );
        sfc0cc0.setValue( "sfc0cc0Value" );

        model.lhs[0] = fp0;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 1,
                      clone.lhs.length );
        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) clone.lhs[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );

        assertEquals( 1,
                      fp0Clone.constraintList.constraints.length );

        assertNotSame( fp0.constraintList.constraints[0],
View Full Code Here

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

        model.lhs = new IPattern[1];
        FactPattern fp0 = new FactPattern();
        fp0.setBoundName( "$t0" );
        fp0.setFactType( "FT0" );

        CompositeFieldConstraint cfc0 = new CompositeFieldConstraint();
        cfc0.compositeJunctionType = CompositeFieldConstraint.COMPOSITE_TYPE_OR;

        SingleFieldConstraint sfc0 = new SingleFieldConstraint();
        sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc0.setFieldBinding( "$sfc0" );
        sfc0.setFieldName( "sfc0" );
        sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc0.setOperator( "==" );
        sfc0.setParameter( "sfc0p0",
                           "sfc0p0Value" );
        sfc0.setValue( "sfc0Value" );
        cfc0.addConstraint( sfc0 );

        SingleFieldConstraint sfc1 = new SingleFieldConstraint();
        sfc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        sfc1.setFieldBinding( "$sfc1" );
        sfc1.setFieldName( "sfc1" );
        sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        sfc1.setOperator( "==" );
        sfc1.setParameter( "sfc1p0",
                           "sfc1p0Value" );
        sfc1.setValue( "sfc1Value" );
        cfc0.addConstraint( sfc1 );

        fp0.addConstraint( cfc0 );

        model.lhs[0] = fp0;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 1,
                      clone.lhs.length );
        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof FactPattern );
        FactPattern fp0Clone = (FactPattern) clone.lhs[0];
        assertEquals( fp0.getBoundName(),
                      fp0Clone.getBoundName() );
        assertEquals( fp0.getFactType(),
                      fp0Clone.getFactType() );

        assertEquals( 1,
                      fp0Clone.constraintList.constraints.length );

        assertNotSame( fp0.constraintList.constraints[0],
View Full Code Here

                      ((FactPattern) rm.lhs[1]).getFactType() );
        assertEquals( "c",
                      ((FactPattern) rm.lhs[1]).getBoundName() );

        // examine the first pattern
        FactPattern person = (FactPattern) rm.lhs[0];
        assertEquals( 3,
                      person.constraintList.constraints.length );
        SingleFieldConstraint cons = (SingleFieldConstraint) person.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      cons.getConstraintValueType() );
        assertEquals( "name",
                      cons.getFieldName() );
        assertEquals( "==",
                      cons.getOperator() );
        assertEquals( "mike",
                      cons.getValue() );

        cons = (SingleFieldConstraint) person.constraintList.constraints[1];
        assertEquals( BaseSingleFieldConstraint.TYPE_RET_VALUE,
                      cons.getConstraintValueType() );
        assertEquals( "age",
                      cons.getFieldName() );
        assertEquals( "<",
                      cons.getOperator() );
        assertEquals( "33 + 1",
                      cons.getValue() );

        cons = (SingleFieldConstraint) person.constraintList.constraints[2];
        assertEquals( BaseSingleFieldConstraint.TYPE_PREDICATE,
                      cons.getConstraintValueType() );
        assertEquals( "age > 6",
                      cons.getValue() );

        // examine the second pattern
        FactPattern cheese = (FactPattern) rm.lhs[1];
        assertEquals( 1,
                      cheese.constraintList.constraints.length );
        cons = (SingleFieldConstraint) cheese.constraintList.constraints[0];
        assertEquals( "type",
                      cons.getFieldName() );
View Full Code Here

                      ((FactPattern) rm.lhs[0]).getFactType() );
        assertEquals( "p1",
                      ((FactPattern) rm.lhs[0]).getBoundName() );

        // examine the first pattern
        FactPattern person = (FactPattern) rm.lhs[0];
        assertEquals( 3,
                      person.constraintList.constraints.length );

        SingleFieldConstraint cons = (SingleFieldConstraint) person.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
View Full Code Here

                      ((FactPattern) rm.lhs[1]).getFactType() );
        assertEquals( "c",
                      ((FactPattern) rm.lhs[1]).getBoundName() );

        // examine the first pattern
        FactPattern person = (FactPattern) rm.lhs[0];
        assertEquals( 3,
                      person.constraintList.constraints.length );
        SingleFieldConstraint cons = (SingleFieldConstraint) person.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      cons.getConstraintValueType() );
        assertEquals( "name",
                      cons.getFieldName() );
        assertEquals( "==",
                      cons.getOperator() );
        assertEquals( "mike",
                      cons.getValue() );

        cons = (SingleFieldConstraint) person.constraintList.constraints[1];
        assertEquals( BaseSingleFieldConstraint.TYPE_RET_VALUE,
                      cons.getConstraintValueType() );
        assertEquals( "age",
                      cons.getFieldName() );
        assertEquals( "<",
                      cons.getOperator() );
        assertEquals( "33 + 1",
                      cons.getValue() );

        cons = (SingleFieldConstraint) person.constraintList.constraints[2];
        assertEquals( BaseSingleFieldConstraint.TYPE_PREDICATE,
                      cons.getConstraintValueType() );
        assertEquals( "age > 6",
                      cons.getValue() );

        assertEquals( person.isNegated(),
                      true );

        assertTrue( drl.indexOf( "not Person(" ) > 0 );

        // examine the second pattern
        FactPattern cheese = (FactPattern) rm.lhs[1];
        assertEquals( 1,
                      cheese.constraintList.constraints.length );
        cons = (SingleFieldConstraint) cheese.constraintList.constraints[0];
        assertEquals( "type",
                      cons.getFieldName() );
        assertEquals( "==",
                      cons.getOperator() );
        assertEquals( "stilton",
                      cons.getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      cons.getConstraintValueType() );

        assertEquals( cheese.isNegated(),
                      false );

        assertTrue( drl.indexOf( "c : Cheese(" ) > 0 );

    }
View Full Code Here

        //BRL Column
        BRLConditionColumn brl1 = new BRLConditionColumn();

        //BRL Column definition
        List<IPattern> brl1Definition = new ArrayList<IPattern>();
        FactPattern brl1DefinitionFactPattern1 = new FactPattern( "Smurf" );

        SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
        brl1DefinitionFactPattern1Constraint1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        brl1DefinitionFactPattern1Constraint1.setConstraintValueType( SingleFieldConstraint.TYPE_TEMPLATE );
        brl1DefinitionFactPattern1Constraint1.setFieldName( "name" );
        brl1DefinitionFactPattern1Constraint1.setOperator( "==" );
        brl1DefinitionFactPattern1Constraint1.setValue( "$name" );
        brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint1 );

        SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint();
        brl1DefinitionFactPattern1Constraint2.setFieldType( SuggestionCompletionEngine.TYPE_NUMERIC );
        brl1DefinitionFactPattern1Constraint2.setConstraintValueType( SingleFieldConstraint.TYPE_TEMPLATE );
        brl1DefinitionFactPattern1Constraint2.setFieldName( "age" );
        brl1DefinitionFactPattern1Constraint2.setOperator( "==" );
        brl1DefinitionFactPattern1Constraint2.setValue( "$age" );
        brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint2 );

        brl1Definition.add( brl1DefinitionFactPattern1 );

        brl1.setDefinition( brl1Definition );

        //Setup BRL column bindings
        BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn( "$name",
                                                                                   SuggestionCompletionEngine.TYPE_STRING,
                                                                                   "Person",
                                                                                   "name" );
        brl1.getChildColumns().add( brl1Variable1 );
        BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn( "$age",
                                                                                   SuggestionCompletionEngine.TYPE_NUMERIC,
                                                                                   "Person",
                                                                                   "age" );
        brl1.getChildColumns().add( brl1Variable2 );

        dtable.getConditions().add( brl1 );

        //Now to test conversion
        RuleModel rm = new RuleModel();
        List<BaseColumn> allColumns = dtable.getExpandedColumns();
        List<CompositeColumn< ? >> allPatterns = dtable.getConditions();
        List<List<DTCellValue52>> dtData = upgrader.makeDataLists( data );

        //Row 0
        List<DTCellValue52> dtRowData0 = upgrader.makeDataRowList( data[0] );
        TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider( allColumns,
                                                                                  dtRowData0 );
        p.doConditions( allColumns,
                        allPatterns,
                        rowDataProvider0,
                        dtRowData0,
                        dtData,
                        rm );

        assertEquals( 2,
                      rm.lhs.length );
        assertEquals( "Baddie",
                      ((FactPattern) rm.lhs[0]).getFactType() );
        assertEquals( "Smurf",
                      ((FactPattern) rm.lhs[1]).getFactType() );

        // examine the first pattern
        FactPattern result0Fp1 = (FactPattern) rm.lhs[0];
        assertEquals( 1,
                      result0Fp1.constraintList.constraints.length );

        SingleFieldConstraint result0Fp1Con1 = (SingleFieldConstraint) result0Fp1.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      result0Fp1Con1.getConstraintValueType() );
        assertEquals( "name",
                      result0Fp1Con1.getFieldName() );
        assertEquals( "==",
                      result0Fp1Con1.getOperator() );
        assertEquals( "Gargamel",
                      result0Fp1Con1.getValue() );

        // examine the second pattern
        FactPattern result0Fp2 = (FactPattern) rm.lhs[1];
        assertEquals( 2,
                      result0Fp2.constraintList.constraints.length );

        SingleFieldConstraint result0Fp2Con1 = (SingleFieldConstraint) result0Fp2.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_TEMPLATE,
                      result0Fp2Con1.getConstraintValueType() );
        assertEquals( "name",
                      result0Fp2Con1.getFieldName() );
        assertEquals( "==",
                      result0Fp2Con1.getOperator() );
        assertEquals( "$name",
                      result0Fp2Con1.getValue() );

        SingleFieldConstraint result0Fp2Con2 = (SingleFieldConstraint) result0Fp2.constraintList.constraints[1];
        assertEquals( BaseSingleFieldConstraint.TYPE_TEMPLATE,
                      result0Fp2Con2.getConstraintValueType() );
        assertEquals( "age",
                      result0Fp2Con2.getFieldName() );
        assertEquals( "==",
                      result0Fp2Con2.getOperator() );
        assertEquals( "$age",
                      result0Fp2Con2.getValue() );

        //Row 1
        List<DTCellValue52> dtRowData1 = upgrader.makeDataRowList( data[1] );
        TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider( allColumns,
                                                                                  dtRowData1 );
        p.doConditions( allColumns,
                        allPatterns,
                        rowDataProvider1,
                        dtRowData1,
                        dtData,
                        rm );

        assertEquals( 1,
                      rm.lhs.length );
        assertEquals( "Baddie",
                      ((FactPattern) rm.lhs[0]).getFactType() );

        // examine the first pattern
        FactPattern result1Fp1 = (FactPattern) rm.lhs[0];
        assertEquals( 1,
                      result1Fp1.constraintList.constraints.length );

        SingleFieldConstraint result1Fp1Con1 = (SingleFieldConstraint) result1Fp1.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      result1Fp1Con1.getConstraintValueType() );
        assertEquals( "name",
                      result1Fp1Con1.getFieldName() );
        assertEquals( "==",
                      result1Fp1Con1.getOperator() );
        assertEquals( "Gargamel",
                      result1Fp1Con1.getValue() );

        //Row 2
        List<DTCellValue52> dtRowData2 = upgrader.makeDataRowList( data[2] );
        TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider( allColumns,
                                                                                  dtRowData2 );
        p.doConditions( allColumns,
                        allPatterns,
                        rowDataProvider2,
                        dtRowData2,
                        dtData,
                        rm );

        assertEquals( 1,
                      rm.lhs.length );
        assertEquals( "Baddie",
                      ((FactPattern) rm.lhs[0]).getFactType() );

        // examine the first pattern
        FactPattern result2Fp1 = (FactPattern) rm.lhs[0];
        assertEquals( 1,
                      result2Fp1.constraintList.constraints.length );

        SingleFieldConstraint result2Fp1Con1 = (SingleFieldConstraint) result2Fp1.constraintList.constraints[0];
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
View Full Code Here

        //BRL Column
        BRLConditionColumn brl1 = new BRLConditionColumn();

        //BRL Column definition
        List<IPattern> brl1Definition = new ArrayList<IPattern>();
        FactPattern brl1DefinitionFactPattern1 = new FactPattern( "Smurf" );

        SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
        brl1DefinitionFactPattern1Constraint1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        brl1DefinitionFactPattern1Constraint1.setConstraintValueType( SingleFieldConstraint.TYPE_TEMPLATE );
        brl1DefinitionFactPattern1Constraint1.setFieldName( "name" );
        brl1DefinitionFactPattern1Constraint1.setOperator( "==" );
        brl1DefinitionFactPattern1Constraint1.setValue( "$name" );
        brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint1 );

        SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint();
        brl1DefinitionFactPattern1Constraint2.setFieldType( SuggestionCompletionEngine.TYPE_NUMERIC );
        brl1DefinitionFactPattern1Constraint2.setConstraintValueType( SingleFieldConstraint.TYPE_TEMPLATE );
        brl1DefinitionFactPattern1Constraint2.setFieldName( "age" );
        brl1DefinitionFactPattern1Constraint2.setOperator( "==" );
        brl1DefinitionFactPattern1Constraint2.setValue( "$age" );
        brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint2 );

        brl1Definition.add( brl1DefinitionFactPattern1 );

        brl1.setDefinition( brl1Definition );
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.brl.FactPattern

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.