Package org.drools.workbench.models.guided.dtable.shared.model

Examples of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52


                                 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( DataType.TYPE_STRING );

        dt.getActionCols().add( asf );

        String[][] data = new String[][]{
                new String[]{ "1", "desc", "y", "old" }
        };
        dt.setData( DataUtilities.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( DataUtilities.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( DataType.TYPE_NUMERIC_INTEGER );
        asf.setUpdate( true );

        dt.getActionCols().add( asf );

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

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

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

        dt.setData( DataUtilities.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( new DTCellValue52( "cheddar" ) );
        c.setOperator( "==" );
        p1.getChildColumns().add( c );
        dt.getConditions().add( p1 );

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

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

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

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

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

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

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

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

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

    }

    @Test
    public void testLimitedEntryAttributes() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

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

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "100" },
                new String[]{ "2", "desc", "200" }
        } ) );

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

    }

    @Test
    public void testLimitedEntryMetadata() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        MetadataCol52 md = new MetadataCol52();
        md.setMetadata( "metadata" );
        dt.getMetadataCols().add( md );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "md1" },
                new String[]{ "2", "desc", "md2" }
        } ) );

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

    }

    @Test
    public void testLimitedEntryConditionsNoConstraints() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        // This is a hack consistent with how the Expanded Form decision table
        // works. I wouldn't be too surprised if this changes at some time, but
        // GuidedDTDRLPersistence.marshal does not support empty patterns at
        // present.
        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setValue( new DTCellValue52( "y" ) );
        p1.getChildColumns().add( cc1 );

        dt.setData( DataUtilities.makeDataLists( new Object[][]{
                new Object[]{ 1l, "desc", true },
                new Object[]{ 2l, "desc", false }
        } ) );

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

    }

    @Test
    public void testLimitedEntryConditionsConstraints1() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setFieldType( DataType.TYPE_STRING );
        cc1.setFactField( "name" );
        cc1.setOperator( "==" );
        cc1.setValue( new DTCellValue52( "Pupa" ) );
        p1.getChildColumns().add( cc1 );

        dt.setData( DataUtilities.makeDataLists( new Object[][]{
                new Object[]{ 1l, "desc", true },
                new Object[]{ 2l, "desc", false }
        } ) );

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

    }

    @Test
    public void testLimitedEntryConditionsConstraints2() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setFieldType( DataType.TYPE_STRING );
        cc1.setFactField( "name" );
        cc1.setOperator( "==" );
        cc1.setValue( new DTCellValue52( "Pupa" ) );
        p1.getChildColumns().add( cc1 );

        LimitedEntryConditionCol52 cc2 = new LimitedEntryConditionCol52();
        cc2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc2.setFieldType( DataType.TYPE_STRING );
        cc2.setFactField( "name" );
        cc2.setOperator( "==" );
        cc2.setValue( new DTCellValue52( "Smurfette" ) );
        p1.getChildColumns().add( cc2 );

        LimitedEntryConditionCol52 cc3 = new LimitedEntryConditionCol52();
        cc3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc3.setFieldType( DataType.TYPE_STRING );
        cc3.setFactField( "colour" );
        cc3.setOperator( "==" );
        cc3.setValue( new DTCellValue52( "Blue" ) );
        p1.getChildColumns().add( cc3 );

        dt.setData( DataUtilities.makeDataLists( new Object[][]{
                new Object[]{ 1l, "desc", true, false, true },
                new Object[]{ 2l, "desc", false, true, true },
                new Object[]{ 3l, "desc", false, false, true }
        } ) );
View Full Code Here

    }

    @Test
    public void testLimitedEntryActionSet() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setFieldType( DataType.TYPE_BOOLEAN );
        cc1.setFactField( "isSmurf" );
        cc1.setOperator( "==" );
        cc1.setValue( new DTCellValue52( "true" ) );
        p1.getChildColumns().add( cc1 );

        LimitedEntryActionSetFieldCol52 asf1 = new LimitedEntryActionSetFieldCol52();
        asf1.setBoundName( "p1" );
        asf1.setFactField( "colour" );
        asf1.setValue( new DTCellValue52( "Blue" ) );

        dt.getActionCols().add( asf1 );

        dt.setData( DataUtilities.makeDataLists( new Object[][]{
                new Object[]{ 1l, "desc", true, true },
                new Object[]{ 2l, "desc", true, false }
        } ) );

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

    }

    @Test
    @SuppressWarnings("serial")
    public void testRowExpansionWithValuesListAndDefaultValues() {
        GuidedDecisionTable52 model = new GuidedDecisionTable52();

        final ProjectDataModelOracle projectLoader = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addFact( "Driver" )
                .addField( new ModelField( "age",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_NUMERIC_INTEGER ) )
                .addField( new ModelField( "name",
                                           String.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_STRING ) )
                .addField( new ModelField( "dateOfBirth",
                                           Boolean.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_DATE ) )
                .end()
                .build();

        //Emulate server-to-client conversions
        final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl();
        final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
        dataModel.setModelFields( projectLoader.getProjectModelFields() );
        populateDataModelOracle( mock( Path.class ),
                                 model,
                                 oracle,
                                 dataModel );

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

        ConditionCol52 c1 = new ConditionCol52();
        c1.setFactField( "name" );
        c1.setOperator( "==" );
        c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c1.setValueList( "c1a,c1b" );
        c1.setDefaultValue( new DTCellValue52( "c1default" ) );
        p1.getChildColumns().add( c1 );
        model.getConditions().add( p1 );

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

        ConditionCol52 c2 = new ConditionCol52();
        c2.setFactField( "age" );
        c2.setOperator( "==" );
        c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c2.setValueList( "c2a,c2b" );
        c2.setDefaultValue( new DTCellValue52( "c2default" ) );
        p2.getChildColumns().add( c2 );
        model.getConditions().add( p2 );

        Pattern52 p3 = new Pattern52();
        p3.setBoundName( "c3" );
        p3.setFactType( "Driver" );

        ConditionCol52 c3 = new ConditionCol52();
        c3.setFactField( "dateOfBirth" );
        c3.setOperator( "==" );
        c3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c3.setDefaultValue( new DTCellValue52( "c3default" ) );
        p3.getChildColumns().add( c3 );
        model.getConditions().add( p3 );

        RowExpander re = new RowExpander( model,
                                          oracle );

        assertEquals( 5,
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.guided.dtable.shared.model.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.