Search in sources :

Example 36 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.

the class GuidedDTXMLPersistenceTest method testRoundTrip.

@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());
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Example 37 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceFirstHitPolicyTest method setUp.

@Before
public void setUp() throws Exception {
    dtable = new GuidedDecisionTable52();
    dtable.setTableName("First hit policy table");
    dtable.setHitPolicy(GuidedDecisionTable52.HitPolicy.FIRST_HIT);
    dtable.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1, "desc-row1" }, new Object[] { 2, "desc-row2" }, new Object[] { 3, "desc-row3" } }));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Before(org.junit.Before)

Example 38 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceResolvedHitPolicyTest method setUp.

@Before
public void setUp() throws Exception {
    dtable = new GuidedDecisionTable52();
    dtable.setTableName("Resolved hit policy table");
    dtable.setHitPolicy(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT);
    dtable.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1, "desc-row1" }, new Object[] { 2, "desc-row2" }, new Object[] { 3, "desc-row3" } }));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Before(org.junit.Before)

Example 39 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testUpdateModifyMultipleFields.

@Test
public void testUpdateModifyMultipleFields() {
    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 asf1 = new ActionSetFieldCol52();
    asf1.setBoundName("x");
    asf1.setFactField("age");
    asf1.setType(DataType.TYPE_NUMERIC_INTEGER);
    asf1.setUpdate(true);
    dt.getActionCols().add(asf1);
    ActionSetFieldCol52 asf2 = new ActionSetFieldCol52();
    asf2.setBoundName("x");
    asf2.setFactField("name");
    asf2.setType(DataType.TYPE_STRING);
    asf2.setUpdate(true);
    dt.getActionCols().add(asf2);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", 55l, "Fred" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected1 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setAge( 55 ), \n" + "    setName( \"Fred\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected1, drl);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", null, "Fred" } }));
    drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected2 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setName( \"Fred\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected2, drl);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", 55l, null } }));
    drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected3 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setAge( 55 ) \n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected3, drl);
}
Also used : LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Example 40 with GuidedDecisionTable52

use of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testLHSIsNullOperator.

@Test
public void testLHSIsNullOperator() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    dt.setTableName("extended-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    dt.getConditions().add(p1);
    ConditionCol52 cc1 = new ConditionCol52();
    cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc1.setFieldType(DataType.TYPE_STRING);
    cc1.setFactField("name");
    cc1.setOperator("== null");
    p1.getChildColumns().add(cc1);
    ConditionCol52 cc2 = new ConditionCol52();
    cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cc2.setFactField("age");
    cc2.setOperator("== null");
    p1.getChildColumns().add(cc2);
    ConditionCol52 cc3 = new ConditionCol52();
    cc3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc3.setFieldType(DataType.TYPE_DATE);
    cc3.setFactField("dateOfBirth");
    cc3.setOperator("== null");
    p1.getChildColumns().add(cc3);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true, true, true }, new Object[] { 2l, "desc", false, false, false } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    int index = -1;
    index = drl.indexOf("Smurf( name == null , age == null , dateOfBirth == null )");
    assertTrue(index > -1);
    index = drl.indexOf("Smurf( )", index + 1);
    assertFalse(index > -1);
}
Also used : LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Aggregations

GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)262 Test (org.junit.Test)193 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)92 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)74 Path (org.uberfire.backend.vfs.Path)52 ArrayList (java.util.ArrayList)51 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)51 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)47 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)39 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)37 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)35 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)33 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)33 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)33 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)32 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)31 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)27 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)26 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26