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

Examples of org.drools.ide.common.client.modeldriven.dt.GuidedDecisionTable


    }

    @Test
    public void testNoConstraints() {
        GuidedDecisionTable dt = new GuidedDecisionTable();
        ConditionCol c = new ConditionCol();
        c.setBoundName( "x" );
        c.setFactType( "Context" );
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c );
        ActionSetFieldCol asf = new ActionSetFieldCol();
        asf.setBoundName( "x" );
        asf.setFactField( "age" );
        asf.setType( "String" );

        dt.getActionCols().add( asf );

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

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

        // System.err.println(drl);

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

        dt.setData( 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() {
        GuidedDecisionTable dt = new GuidedDecisionTable();
        ConditionCol c = new ConditionCol();
        c.setBoundName( "x" );
        c.setFactType( "Context" );
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c );
        ActionSetFieldCol asf = new ActionSetFieldCol();
        asf.setBoundName( "x" );
        asf.setFactField( "age" );
        asf.setType( "String" );
        asf.setUpdate( true );

        dt.getActionCols().add( asf );

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

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

        System.err.println( drl );

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

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

public class GuidedDTDRLPersistenceTest extends TestCase {


  public void test2Rules() throws Exception {
    GuidedDecisionTable dt = new GuidedDecisionTable();
    dt.tableName = "michael";

    AttributeCol attr = new AttributeCol();
    attr.attr = "salience";
        attr.defaultValue = "66";
View Full Code Here

  }


    public void testInterpolate() {
        GuidedDecisionTable dt = new GuidedDecisionTable();
        dt.tableName = "michael";

        AttributeCol attr = new AttributeCol();
        attr.attr = "salience";
        attr.defaultValue = "66";
View Full Code Here

       
    }


    public void testInOperator() {
        GuidedDecisionTable dt = new GuidedDecisionTable();
        dt.tableName = "michael";

        AttributeCol attr = new AttributeCol();
        attr.attr = "salience";
        attr.defaultValue = "66";
View Full Code Here


  }

  public void testNoConstraints() {
    GuidedDecisionTable dt = new GuidedDecisionTable();
    ConditionCol c = new ConditionCol();
    c.boundName = "x";
    c.factType = "Context";
    c.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
    dt.conditionCols.add(c);
View Full Code Here


  }

  public void testUpdateModify() {
    GuidedDecisionTable dt = new GuidedDecisionTable();
    ConditionCol c = new ConditionCol();
    c.boundName = "x";
    c.factType = "Context";
    c.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
    dt.conditionCols.add(c);
View Full Code Here

    GuidedDTXMLPersistence.getInstance();
  }

  public void testRoundTrip() {

    GuidedDecisionTable dt = new GuidedDecisionTable();

    dt.actionCols.add(new ActionInsertFactCol());
    ActionSetFieldCol set = new ActionSetFieldCol();
    set.factField = "foo";
    dt.actionCols.add(set);

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

    dt.attributeCols.add(new AttributeCol());

    dt.conditionCols.add(new ConditionCol());

    dt.data = new String[][] {
        new String[] {"hola"}
    };
    dt.tableName = "blah";
    dt.descriptionWidth = 42;


    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"));

    GuidedDecisionTable dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml);
    assertNotNull(dt_);
    assertEquals(42, dt_.descriptionWidth);
    assertEquals("blah", dt_.tableName);
    assertEquals(1, dt_.getMetadataCols().size());
    assertEquals(1, dt_.attributeCols.size());
    assertEquals(2, dt_.actionCols.size());
    assertEquals(1, dt_.conditionCols.size());

  }
View Full Code Here

  }

  public void testBackwardsCompatability() throws Exception {
    String xml = BRLPersistenceTest.loadResource("ExistingDecisionTable.xml");
    GuidedDecisionTable dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml);
    assertNotNull(dt_);
    assertEquals(42, dt_.descriptionWidth);
    assertEquals("blah", dt_.tableName);
    assertEquals(1, dt_.getMetadataCols().size());
    assertEquals(1, dt_.attributeCols.size());
    assertEquals(2, dt_.actionCols.size());
    assertEquals(1, dt_.conditionCols.size());

    assertTrue(dt_.actionCols.get(1) instanceof ActionSetFieldCol );
View Full Code Here

//
//
//
//  }
    public void testValueLists() {
        GuidedDecisionTable dt = new GuidedDecisionTable();

        //add cols for LHS
        ConditionCol c1 = new ConditionCol();
        c1.boundName = "c1";
        c1.factType = "Driver";
        c1.factField = "name";
        c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
        dt.conditionCols.add(c1);

        ConditionCol c1_ = new ConditionCol();
        c1_.boundName = "c1";
        c1_.factType = "Driver";
        c1_.factField = "name";
        c1_.constraintValueType = ISingleFieldConstraint.TYPE_RET_VALUE;

        dt.conditionCols.add(c1_);

        ConditionCol c1__ = new ConditionCol();
        c1__.boundName = "c1";
        c1__.factType = "Driver";
        c1__.factField = "name";
        c1__.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
        c1__.valueList = "one,two,three";
        dt.conditionCols.add(c1__);

        ConditionCol c2 = new ConditionCol();
        c2.boundName = "c2";
        c2.factType = "Driver";
        c2.factField = "nothing";
        c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
        dt.conditionCols.add(c2);


        ActionSetFieldCol asf = new ActionSetFieldCol();
        asf.boundName = "c1";
        asf.factField = "name";
        dt.actionCols.add(asf);

        ActionInsertFactCol ins = new ActionInsertFactCol();
        ins.boundName = "x";
        ins.factField = "rating";
        ins.factType = "Person";
        dt.actionCols.add(ins);

        ActionInsertFactCol ins_ = new ActionInsertFactCol();
        ins_.boundName = "x";
        ins_.factField = "rating";
        ins_.factType = "Person";
        ins_.valueList = "one,two,three";
        dt.actionCols.add(ins_);

        ActionSetFieldCol asf_ = new ActionSetFieldCol();
        asf_.boundName = "c1";
        asf_.factField = "goo";
        dt.actionCols.add(asf_);

        ActionSetFieldCol asf__ = new ActionSetFieldCol();
        asf__.boundName = "c1";
        asf__.factField = "goo";
        asf__.valueList = "one,two,three";
        dt.actionCols.add(asf__);


        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
        sce.putDataEnumList("Driver.name", new String[]{"bob", "michael"});
        sce.putDataEnumList("Person.rating", new String[]{"1", "2"});




        String[] r = dt.getValueList(c1, sce);
        assertEquals(2, r.length);
        assertEquals("bob", r[0]);
        assertEquals("michael", r[1]);

        assertEquals(0, dt.getValueList(c1_, sce).length);

        r = dt.getValueList(c1__, sce);
        assertEquals(3, r.length);
        assertEquals("one", r[0]);
        assertEquals("two", r[1]);
        assertEquals("three", r[2]);

        assertEquals(0, dt.getValueList(c2, sce).length);

        r = dt.getValueList(asf, sce);
        assertEquals(2, r.length);
        assertEquals("bob", r[0]);
        assertEquals("michael", r[1]);

        r = dt.getValueList(ins, sce);
        assertEquals(2, r.length);
        assertEquals("1", r[0]);
        assertEquals("2", r[1]);

        r = dt.getValueList(ins_, sce);
        assertEquals(3, r.length);
        assertEquals("one", r[0]);
        assertEquals("two", r[1]);
        assertEquals("three", r[2]);

        assertEquals(0, dt.getValueList(asf_, sce).length);


        r = dt.getValueList(asf__, sce);
        assertEquals(3, r.length);
        assertEquals("one", r[0]);
        assertEquals("two", r[1]);
        assertEquals("three", r[2]);

        AttributeCol at = new AttributeCol();
        at.attr = "no-loop";
        dt.attributeCols.add(at);

        r = dt.getValueList(at, sce);
        assertEquals(2, r.length);
        assertEquals("true", r[0]);
        assertEquals("false", r[1]);

        at.attr = "enabled";
        assertEquals(2, dt.getValueList(at, sce).length);

        at.attr = "salience";
        assertEquals(0, dt.getValueList(at, sce).length);

    }
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.dt.GuidedDecisionTable

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.