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

Examples of org.drools.ide.common.client.modeldriven.dt52.GuidedDecisionTable52


    private GuidedDecisionTableModelUpgradeHelper upgrader = new GuidedDecisionTableModelUpgradeHelper();

    @Test
    public void test2Rules() throws Exception {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableName( "michael" );

        AttributeCol52 attr = new AttributeCol52();
        attr.setAttribute( "salience" );
        attr.setDefaultValue( "66" );
        dt.getAttributeCols().add( attr );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "f1" );
        p1.setFactType( "Driver" );

        ConditionCol52 con = new ConditionCol52();
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con.setFactField( "age" );
        con.setHeader( "Driver f1 age" );
        con.setOperator( "==" );
        p1.getChildColumns().add( con );

        ConditionCol52 con2 = new ConditionCol52();
        con2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con2.setFactField( "name" );
        con2.setHeader( "Driver f1 name" );
        con2.setOperator( "==" );
        p1.getChildColumns().add( con2 );

        ConditionCol52 con3 = new ConditionCol52();
        con3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
        con3.setFactField( "rating" );
        con3.setHeader( "Driver rating" );
        con3.setOperator( "==" );
        p1.getChildColumns().add( con3 );

        dt.getConditions().add( p1 );

        Pattern52 p2 = new Pattern52();
        p2.setBoundName( "f2" );
        p2.setFactType( "Driver" );

        ConditionCol52 con4 = new ConditionCol52();
        con4.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );
        con4.setHeader( "Driver 2 pimp" );
        con4.setFactField( "(not needed)" );
        p2.getChildColumns().add( con4 );

        dt.getConditions().add( p2 );

        ActionInsertFactCol52 ins = new ActionInsertFactCol52();
        ins.setBoundName( "ins" );
        ins.setFactType( "Cheese" );
        ins.setFactField( "price" );
        ins.setType( SuggestionCompletionEngine.TYPE_NUMERIC );
        dt.getActionCols().add( ins );

        ActionRetractFactCol52 ret = new ActionRetractFactCol52();
        dt.getActionCols().add( ret );

        ActionSetFieldCol52 set = new ActionSetFieldCol52();
        set.setBoundName( "f1" );
        set.setFactField( "goo1" );
        set.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set );

        ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
        set2.setBoundName( "f1" );
        set2.setFactField( "goo2" );
        set2.setDefaultValue( "whee" );
        set2.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set2 );

        dt.setData( upgrader.makeDataLists( new String[][]{
                new String[]{"1", "desc", "42", "33", "michael", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2"},
                new String[]{"2", "desc", "", "39", "bob", "age * 0.3", "age > 7", "6.60", "", "gooVal1", null}
        } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here


    }

    @Test
    public void testInOperator() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableName( "michael" );

        AttributeCol52 attr = new AttributeCol52();
        attr.setAttribute( "salience" );
        attr.setDefaultValue( "66" );
        dt.getAttributeCols().add( attr );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "f1" );
        p1.setFactType( "Driver" );

        ConditionCol52 con = new ConditionCol52();
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con.setFactField( "age" );
        con.setHeader( "Driver f1 age" );
        con.setOperator( "==" );
        p1.getChildColumns().add( con );

        ConditionCol52 con2 = new ConditionCol52();
        con2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con2.setFactField( "name" );
        con2.setHeader( "Driver f1 name" );
        con2.setOperator( "in" );
        p1.getChildColumns().add( con2 );

        ConditionCol52 con3 = new ConditionCol52();
        con3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
        con3.setFactField( "rating" );
        con3.setHeader( "Driver rating" );
        con3.setOperator( "==" );
        p1.getChildColumns().add( con3 );

        ConditionCol52 con4 = new ConditionCol52();
        con4.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );
        con4.setHeader( "Driver 2 pimp" );
        con4.setFactField( "(not needed)" );
        p1.getChildColumns().add( con4 );

        dt.getConditions().add( p1 );

        ActionInsertFactCol52 ins = new ActionInsertFactCol52();
        ins.setBoundName( "ins" );
        ins.setFactType( "Cheese" );
        ins.setFactField( "price" );
        ins.setType( SuggestionCompletionEngine.TYPE_NUMERIC );
        dt.getActionCols().add( ins );

        ActionRetractFactCol52 ret = new ActionRetractFactCol52();
        dt.getActionCols().add( ret );

        ActionSetFieldCol52 set = new ActionSetFieldCol52();
        set.setBoundName( "f1" );
        set.setFactField( "goo1" );
        set.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set );

        ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
        set2.setBoundName( "f1" );
        set2.setFactField( "goo2" );
        set2.setDefaultValue( "whee" );
        set2.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set2 );

        dt.setData( upgrader.makeDataLists( new String[][]{
                new String[]{"1", "desc", "42", "33", "michael, manik", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2"},
                new String[]{"2", "desc", "", "39", "bob, frank", "age * 0.3", "age > 7", "6.60", "", "gooVal1", null}
        } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

    }

    @Test
    public void testInterpolate() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableName( "michael" );

        AttributeCol52 attr = new AttributeCol52();
        attr.setAttribute( "salience" );
        attr.setDefaultValue( "66" );
        dt.getAttributeCols().add( attr );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "f1" );
        p1.setFactType( "Driver" );

        ConditionCol52 con = new ConditionCol52();
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con.setFactField( "age" );
        con.setHeader( "Driver f1 age" );
        con.setOperator( "==" );
        p1.getChildColumns().add( con );

        ConditionCol52 con2 = new ConditionCol52();
        con2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con2.setFactField( "name" );
        con2.setHeader( "Driver f1 name" );
        con2.setOperator( "==" );
        p1.getChildColumns().add( con2 );

        ConditionCol52 con3 = new ConditionCol52();
        con3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );
        con3.setFactField( "rating" );
        con3.setHeader( "Driver rating" );
        con3.setOperator( "==" );
        p1.getChildColumns().add( con3 );

        dt.getConditions().add( p1 );

        Pattern52 p2 = new Pattern52();
        p2.setBoundName( "f2" );
        p2.setFactType( "Driver" );

        ConditionCol52 con4 = new ConditionCol52();
        con4.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );
        con4.setHeader( "Driver 2 pimp" );
        con4.setFactField( "this.hasSomething($param)" );
        p2.getChildColumns().add( con4 );

        dt.getConditions().add( p2 );

        ActionInsertFactCol52 ins = new ActionInsertFactCol52();
        ins.setBoundName( "ins" );
        ins.setFactType( "Cheese" );
        ins.setFactField( "price" );
        ins.setType( SuggestionCompletionEngine.TYPE_NUMERIC );
        dt.getActionCols().add( ins );

        ActionRetractFactCol52 ret = new ActionRetractFactCol52();
        dt.getActionCols().add( ret );

        ActionSetFieldCol52 set = new ActionSetFieldCol52();
        set.setBoundName( "f1" );
        set.setFactField( "goo1" );
        set.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set );

        ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
        set2.setBoundName( "f1" );
        set2.setFactField( "goo2" );
        set2.setDefaultValue( "whee" );
        set2.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( set2 );

        dt.setData( upgrader.makeDataLists( new String[][]{
                new String[]{"1", "desc", "42", "33", "michael", "age * 0.2", "BAM", "6.60", "true", "gooVal1", "f2"},
                new String[]{"2", "desc", "", "39", "bob", "age * 0.3", "BAM", "6.60", "", "gooVal1", null}
        } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

        String[][] expected = new String[][]{
                                             new String[]{"1", "desc", "metar1", "saliencer1", "f1c1r1", "f1c2r1", "f2c1r1", "f2c2r1", "a1r1", "ret1", "a3r1", "a4r1"},
                                             new String[]{"2", "desc", "metar2", "saliencer2", "f1c1r2", "f1c2r2", "f2c1r2", "f2c2r2", "a1r2", "ret1", "a3r2", "a4r2"}
                                             };

        GuidedDecisionTable52 tsdt = upgrader.upgrade( dt );

        assertEquals( "michael",
                      tsdt.getTableName() );

        assertEquals( 1,
                      tsdt.getMetadataCols().size() );
        assertEquals( "legacy",
                      tsdt.getMetadataCols().get( 0 ).getMetadata() );
        assertEquals( "yes",
                      tsdt.getMetadataCols().get( 0 ).getDefaultValue() );

        assertEquals( 1,
                      tsdt.getAttributeCols().size() );
        assertEquals( "salience",
                      tsdt.getAttributeCols().get( 0 ).getAttribute() );
        assertEquals( "66",
                      tsdt.getAttributeCols().get( 0 ).getDefaultValue() );

        assertEquals( 2,
                      tsdt.getConditions().size() );

        assertEquals( "f1",
                      tsdt.getConditionPattern( "f1" ).getBoundName() );
        assertEquals( "Driver",
                      tsdt.getConditionPattern( "f1" ).getFactType() );

        assertEquals( "f2",
                      tsdt.getConditionPattern( "f2" ).getBoundName() );
        assertEquals( "Person",
                      tsdt.getConditionPattern( "f2" ).getFactType() );

        assertEquals( 2,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().size() );

        assertEquals( 2,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().size() );

        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getConstraintValueType() );
        assertEquals( "age",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ) ).getFactType() );
        assertEquals( "Driver f1 age",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_RET_VALUE,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getConstraintValueType() );
        assertEquals( "rating",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ) ).getFactType() );
        assertEquals( "Driver rating",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getConstraintValueType() );
        assertEquals( "name",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getFactField() );
        assertEquals( "Person",
                      tsdt.getPattern( tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ) ).getFactType() );
        assertEquals( "Person f2 name",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_PREDICATE,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 1 ).getConstraintValueType() );
        assertEquals( "(not needed)",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 1 ).getFactField() );
        assertEquals( "Person",
                      tsdt.getPattern( tsdt.getConditionPattern( "f2" ).getChildColumns().get( 1 ) ).getFactType() );
        assertEquals( "Person f2 not needed",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 1 ).getHeader() );
        assertEquals( null,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 1 ).getOperator() );

        assertEquals( 4,
                      tsdt.getActionCols().size() );

        ActionInsertFactCol52 a1 = (ActionInsertFactCol52) tsdt.getActionCols().get( 0 );
        assertEquals( "ins",
                      a1.getBoundName() );
        assertEquals( "Cheese",
                      a1.getFactType() );
        assertEquals( "price",
                      a1.getFactField() );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      a1.getType() );

        ActionRetractFactCol52 a2 = (ActionRetractFactCol52) tsdt.getActionCols().get( 1 );
        assertNotNull( a2 );

        ActionSetFieldCol52 a3 = (ActionSetFieldCol52) tsdt.getActionCols().get( 2 );
        assertEquals( "f1",
                      a3.getBoundName() );
        assertEquals( "goo1",
                      a3.getFactField() );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      a3.getType() );

        ActionSetFieldCol52 a4 = (ActionSetFieldCol52) tsdt.getActionCols().get( 3 );
        assertEquals( "f1",
                      a4.getBoundName() );
        assertEquals( "goo2",
                      a4.getFactField() );
        assertEquals( "whee",
                      a4.getDefaultValue() );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      a4.getType() );

        assertEquals( 2,
                      tsdt.getData().size() );

        for ( int i = 0; i < 2; i++ ) {
            System.out.println( "Row-" + i );
            StringBuilder sb = new StringBuilder();
            for ( DTCellValue52 c : tsdt.getData().get( i ) ) {
                sb.append( c.getStringValue() + ", " );
            }
            sb.delete( sb.lastIndexOf( "," ),
                       sb.length() );
            System.out.println( sb.toString() );
        }

        assertEquals( new BigDecimal( 1 ),
                      tsdt.getData().get( 0 ).get( 0 ).getNumericValue() );
        assertEquals( "desc",
                      tsdt.getData().get( 0 ).get( 1 ).getStringValue() );
        assertEquals( "metar1",
                      tsdt.getData().get( 0 ).get( 2 ).getStringValue() );
        assertEquals( "saliencer1",
                      tsdt.getData().get( 0 ).get( 3 ).getStringValue() );
        assertEquals( "f1c1r1",
                      tsdt.getData().get( 0 ).get( 4 ).getStringValue() );
        assertEquals( "f1c2r1",
                      tsdt.getData().get( 0 ).get( 5 ).getStringValue() );
        assertEquals( "f2c1r1",
                      tsdt.getData().get( 0 ).get( 6 ).getStringValue() );
        assertEquals( "f2c2r1",
                      tsdt.getData().get( 0 ).get( 7 ).getStringValue() );
        assertEquals( "a1r1",
                      tsdt.getData().get( 0 ).get( 8 ).getStringValue() );
        assertEquals( "ret1",
                      tsdt.getData().get( 0 ).get( 9 ).getStringValue() );
        assertEquals( "a3r1",
                      tsdt.getData().get( 0 ).get( 10 ).getStringValue() );
        assertEquals( "a4r1",
                      tsdt.getData().get( 0 ).get( 11 ).getStringValue() );

        assertEquals( new BigDecimal( 2 ),
                      tsdt.getData().get( 1 ).get( 0 ).getNumericValue() );
        assertEquals( "desc",
                      tsdt.getData().get( 1 ).get( 1 ).getStringValue() );
        assertEquals( "metar2",
                      tsdt.getData().get( 1 ).get( 2 ).getStringValue() );
        assertEquals( "saliencer2",
                      tsdt.getData().get( 1 ).get( 3 ).getStringValue() );
        assertEquals( "f1c1r2",
                      tsdt.getData().get( 1 ).get( 4 ).getStringValue() );
        assertEquals( "f1c2r2",
                      tsdt.getData().get( 1 ).get( 5 ).getStringValue() );
        assertEquals( "f2c1r2",
                      tsdt.getData().get( 1 ).get( 6 ).getStringValue() );
        assertEquals( "f2c2r2",
                      tsdt.getData().get( 1 ).get( 7 ).getStringValue() );
        assertEquals( "a1r2",
                      tsdt.getData().get( 1 ).get( 8 ).getStringValue() );
        assertEquals( "ret1",
                      tsdt.getData().get( 1 ).get( 9 ).getStringValue() );
        assertEquals( "a3r2",
                      tsdt.getData().get( 1 ).get( 10 ).getStringValue() );
        assertEquals( "a4r2",
                      tsdt.getData().get( 1 ).get( 11 ).getStringValue() );

        isRowEquivalent( tsdt.getData().get( 0 ),
                         expected[0] );
        isRowEquivalent( tsdt.getData().get( 1 ),
                         expected[1] );

    }
View Full Code Here

    }

    @Test
    public void testRoundTrip() {

        GuidedDecisionTable52 dt = new GuidedDecisionTable52();

        dt.getActionCols().add( new ActionInsertFactCol52() );
        ActionSetFieldCol52 set = new ActionSetFieldCol52();
        set.setFactField( "foo" );
        dt.getActionCols().add( set );

        dt.getMetadataCols().add( new MetadataCol52() );

        dt.getAttributeCols().add( new AttributeCol52() );

        Pattern52 p = new Pattern52();
        ConditionCol52 c = new ConditionCol52();
        p.getChildColumns().add( c );
        dt.getConditions().add( p );

        dt.setData( upgrader.makeDataLists( new String[][]{new String[]{"1", "hola"}} ) );
        dt.setTableName( "blah" );

        String xml = GuidedDTXMLPersistence.getInstance().marshal( dt );
        System.out.println( xml );
        assertNotNull( xml );
        assertEquals( -1,
                      xml.indexOf( "ActionSetField" ) );
        assertEquals( -1,
                      xml.indexOf( "ConditionCol" ) );
        assertEquals( -1,
                      xml.indexOf( "GuidedDecisionTable" ) );

        GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull( dt_ );
        assertEquals( "blah",
                      dt_.getTableName() );
        assertEquals( 1,
                      dt_.getMetadataCols().size() );
        assertEquals( 1,
                      dt_.getAttributeCols().size() );
        assertEquals( 2,
                      dt_.getActionCols().size() );
        assertEquals( 1,
                      dt_.getConditions().size() );
        assertEquals( 1,
                      dt_.getConditions().get( 0 ).getChildColumns().size() );

    }
View Full Code Here

    }

    @Test
    public void testBackwardsCompatability() throws Exception {
        String xml = BRLPersistenceTest.loadResource( "ExistingDecisionTable.xml" );
        GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull( dt_ );
        assertEquals( "blah",
                      dt_.getTableName() );
        assertEquals( 1,
                      dt_.getMetadataCols().size() );
        assertEquals( 1,
                      dt_.getAttributeCols().size() );
        assertEquals( 2,
                      dt_.getActionCols().size() );
        assertEquals( 1,
                      dt_.getConditions().size() );
        assertEquals( 1,
                      dt_.getConditions().get( 0 ).getChildColumns().size() );

        assertTrue( dt_.getActionCols().get( 1 ) instanceof ActionSetFieldCol52 );
        ActionSetFieldCol52 asf = (ActionSetFieldCol52) dt_.getActionCols().get( 1 );
        assertEquals( "foo",
                      asf.getFactField() );
        assertEquals( false,
                      asf.isUpdate() );
    }
View Full Code Here

        String[][] expected = new String[][]{
                                             new String[]{"1", "desc", "metar1", "saliencer1", "c1r1", "c2r1", "c3r1", "c4r1", "a1r1", "ret1", "a3r1", "a4r1"},
                                             new String[]{"2", "desc", "metar2", "saliencer2", "c1r2", "c2r2", "c3r2", "c4r2", "a1r2", "ret1", "a3r2", "a4r2"}
                                             };

        GuidedDecisionTable52 tsdt = upgrader.upgrade( dt );

        assertEquals( "michael",
                      tsdt.getTableName() );

        assertEquals( 1,
                      tsdt.getMetadataCols().size() );
        assertEquals( "legacy",
                      tsdt.getMetadataCols().get( 0 ).getMetadata() );
        assertEquals( "yes",
                      tsdt.getMetadataCols().get( 0 ).getDefaultValue() );

        assertEquals( 1,
                      tsdt.getAttributeCols().size() );
        assertEquals( "salience",
                      tsdt.getAttributeCols().get( 0 ).getAttribute() );
        assertEquals( "66",
                      tsdt.getAttributeCols().get( 0 ).getDefaultValue() );

        assertEquals( 2,
                      tsdt.getConditions().size() );

        assertEquals( "f1",
                      tsdt.getConditionPattern( "f1" ).getBoundName() );
        assertEquals( "Driver",
                      tsdt.getConditionPattern( "f1" ).getFactType() );

        assertEquals( "f2",
                      tsdt.getConditionPattern( "f2" ).getBoundName() );
        assertEquals( "Driver",
                      tsdt.getConditionPattern( "f2" ).getFactType() );

        assertEquals( 3,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().size() );

        assertEquals( 1,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().size() );

        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getConstraintValueType() );
        assertEquals( "age",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ) ).getFactType() );
        assertEquals( "Driver f1 age",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getConstraintValueType() );
        assertEquals( "name",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ) ).getFactType() );
        assertEquals( "Driver f1 name",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_RET_VALUE,
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 2 ).getConstraintValueType() );
        assertEquals( "rating",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 2 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 2 ) ).getFactType() );
        assertEquals( "Driver rating",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 2 ).getHeader() );
        assertEquals( "==",
                      tsdt.getConditionPattern( "f1" ).getChildColumns().get( 2 ).getOperator() );

        assertEquals( BaseSingleFieldConstraint.TYPE_PREDICATE,
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getConstraintValueType() );
        assertEquals( "(not needed)",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getFactField() );
        assertEquals( "Driver",
                      tsdt.getPattern( tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ) ).getFactType() );
        assertEquals( "Driver 2 pimp",
                      tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getHeader() );

        assertEquals( 4,
                      tsdt.getActionCols().size() );

        ActionInsertFactCol52 a1 = (ActionInsertFactCol52) tsdt.getActionCols().get( 0 );
        assertEquals( "ins",
                      a1.getBoundName() );
        assertEquals( "Cheese",
                      a1.getFactType() );
        assertEquals( "price",
                      a1.getFactField() );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      a1.getType() );

        ActionRetractFactCol52 a2 = (ActionRetractFactCol52) tsdt.getActionCols().get( 1 );
        assertNotNull( a2 );

        ActionSetFieldCol52 a3 = (ActionSetFieldCol52) tsdt.getActionCols().get( 2 );
        assertEquals( "f1",
                      a3.getBoundName() );
        assertEquals( "goo1",
                      a3.getFactField() );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      a3.getType() );

        ActionSetFieldCol52 a4 = (ActionSetFieldCol52) tsdt.getActionCols().get( 3 );
        assertEquals( "f1",
                      a4.getBoundName() );
        assertEquals( "goo2",
                      a4.getFactField() );
        assertEquals( "whee",
                      a4.getDefaultValue() );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      a4.getType() );

        assertEquals( 2,
                      tsdt.getData().size() );
        isRowEquivalent( tsdt.getData().get( 0 ),
                         expected[0] );
        isRowEquivalent( tsdt.getData().get( 1 ),
                         expected[1] );

    }
View Full Code Here

                                 42 ) );
    }

    @Test
    public void testNoConstraints() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "x" );
        p1.setFactType( "Context" );

        ConditionCol52 c = new ConditionCol52();
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        p1.getChildColumns().add( c );

        dt.getConditions().add( p1 );

        ActionSetFieldCol52 asf = new ActionSetFieldCol52();
        asf.setBoundName( "x" );
        asf.setFactField( "age" );
        asf.setType( SuggestionCompletionEngine.TYPE_STRING );

        dt.getActionCols().add( asf );

        String[][] data = new String[][]{
                new String[]{"1", "desc", "y", "old"}
        };
        dt.setData( upgrader.makeDataLists( data ) );

        String drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "Context( )" ) > -1 );
        assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) );
        assertFalse( drl.indexOf( "update( x );" ) > -1 );

        dt.setData( upgrader.makeDataLists( new String[][]{
                new String[]{"1", "desc", "", "old"}
            } ) );
        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );
        assertEquals( -1,
                      drl.indexOf( "Context( )" ) );
View Full Code Here

    }

    @Test
    public void testUpdateModify() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "x" );
        p1.setFactType( "Context" );

        ConditionCol52 c = new ConditionCol52();
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        p1.getChildColumns().add( c );
        dt.getConditions().add( p1 );

        ActionSetFieldCol52 asf = new ActionSetFieldCol52();
        asf.setBoundName( "x" );
        asf.setFactField( "age" );
        asf.setType( SuggestionCompletionEngine.TYPE_NUMERIC );
        asf.setUpdate( true );

        dt.getActionCols().add( asf );

        String[][] data = new String[][]{
                new String[]{"1", "desc", "y", "old"}
        };
        dt.setData( upgrader.makeDataLists( data ) );

        String drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "Context( )" ) > -1 );
        assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) );

        dt.setData( upgrader.makeDataLists( new String[][]{
                new String[]{"1", "desc", "", "old"}
            } ) );
        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );
        assertEquals( -1,
                      drl.indexOf( "Context( )" ) );
View Full Code Here

    }

    @Test
    public void testDefaultValue() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "$c" );
        p1.setFactType( "CheeseLover" );

        ConditionCol52 c = new ConditionCol52();
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c.setFactField( "favouriteCheese" );
        c.setDefaultValue( "cheddar" );
        c.setOperator( "==" );
        p1.getChildColumns().add( c );
        dt.getConditions().add( p1 );

        //With provided value
        String[][] data = new String[][]{
                new String[]{"1", "desc", "edam"},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        String drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertFalse( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"edam\" )" ) == -1 );

        //Without provided value #1
        data = new String[][]{
                new String[]{"1", "desc", null},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"cheddar\" )" ) == -1 );

        //Without provided value #2
        data = new String[][]{
                new String[]{"1", "desc", ""},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"cheddar\" )" ) == -1 );
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.dt52.GuidedDecisionTable52

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.