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());
}
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" } }));
}
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" } }));
}
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);
}
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);
}
Aggregations