use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method test2Rules.
@Test
public void test2Rules() throws Exception {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableName("michael");
AttributeCol52 attr = new AttributeCol52();
attr.setAttribute("salience");
attr.setDefaultValue(new DTCellValue52("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(DataType.TYPE_NUMERIC_INTEGER);
dt.getActionCols().add(ins);
ActionRetractFactCol52 ret = new ActionRetractFactCol52();
dt.getActionCols().add(ret);
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("f1");
set.setFactField("goo1");
set.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set);
ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
set2.setBoundName("f1");
set2.setFactField("goo2");
set2.setDefaultValue(new DTCellValue52("whee"));
set2.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "42", "33", "michael", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "66", "39", "bob", "age * 0.3", "age > 7", "6.60", "", "gooVal1", "whee" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("from row number") > -1);
assertTrue(drl.indexOf("rating == ( age * 0.2 )") > 0);
assertTrue(drl.indexOf("f2 : Driver( eval( age > 7 ))") > 0);
assertTrue(drl.indexOf("rating == ( age * 0.3 )") > drl.indexOf("rating == ( age * 0.2 )"));
assertTrue(drl.indexOf("f1.setGoo2( \"whee\" )") > 0);
assertTrue(drl.indexOf("salience 66") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testNoConstraints.
@Test
public void testNoConstraints() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
dt.setTableName("no-constraints");
Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");
ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
c.setFieldType(DataType.TYPE_STRING);
c.setFactField("name");
c.setOperator("==");
p1.getChildColumns().add(c);
dt.getConditions().add(p1);
ActionSetFieldCol52 asf = new ActionSetFieldCol52();
asf.setBoundName("x");
asf.setFactField("age");
asf.setType(DataType.TYPE_NUMERIC_INTEGER);
dt.getActionCols().add(asf);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "Fred", 75l } }));
String drl1 = GuidedDTDRLPersistence.getInstance().marshal(dt);
String expected1 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 no-constraints\"\n" + " dialect \"mvel\"\n" + " when\n" + " x : Context( name == \"Fred\" )\n" + " then\n" + " x.setAge( 75 );\n" + "end";
assertEqualsIgnoreWhitespace(expected1, drl1);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", null, 75l } }));
String drl2 = GuidedDTDRLPersistence.getInstance().marshal(dt);
String expected2 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 no-constraints\"\n" + " dialect \"mvel\"\n" + " when\n" + " then\n" + " x.setAge( 75 );\n" + "end";
assertEqualsIgnoreWhitespace(expected2, drl2);
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testInterpolate.
@Test
public void testInterpolate() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableName("michael");
AttributeCol52 attr = new AttributeCol52();
attr.setAttribute("salience");
attr.setDefaultValue(new DTCellValue52("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(DataType.TYPE_NUMERIC_INTEGER);
dt.getActionCols().add(ins);
ActionRetractFactCol52 ret = new ActionRetractFactCol52();
dt.getActionCols().add(ret);
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("f1");
set.setFactField("goo1");
set.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set);
ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
set2.setBoundName("f1");
set2.setFactField("goo2");
set2.setDefaultValue(new DTCellValue52("whee"));
set2.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "42", "33", "michael", "age * 0.2", "BAM", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "66", "39", "bob", "age * 0.3", "BAM", "6.60", "", "gooVal1", "whee" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("from row number") > -1);
assertTrue(drl.indexOf("rating == ( age * 0.2 )") > 0);
assertTrue(drl.indexOf("f2 : Driver( eval( this.hasSomething(BAM) ))") > 0);
assertTrue(drl.indexOf("rating == ( age * 0.3 )") > drl.indexOf("rating == ( age * 0.2 )"));
assertTrue(drl.indexOf("f1.setGoo2( \"whee\" )") > 0);
assertTrue(drl.indexOf("salience 66") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testUpdateModifySingleField.
@Test
public void testUpdateModifySingleField() {
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);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "y", "old" } }));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
assertTrue(drl.indexOf("Context( )") > -1);
assertTrue(drl.indexOf("modify( x ) {") > drl.indexOf("Context( )"));
assertTrue(drl.indexOf("setAge(") > drl.indexOf("modify( x ) {"));
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", null, "old" } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
assertEquals(-1, drl.indexOf("Context( )"));
assertTrue(drl.indexOf("modify( x ) {") > -1);
assertTrue(drl.indexOf("setAge(") > drl.indexOf("modify( x ) {"));
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", null, null } }));
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
assertEquals(-1, drl.indexOf("Context( )"));
assertEquals(-1, drl.indexOf("modify( x ) {"));
assertEquals(-1, drl.indexOf("setAge("));
}
use of org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testUpdateModifyMultipleFieldsUpdateOneModifyTheOther.
@Test
public void testUpdateModifyMultipleFieldsUpdateOneModifyTheOther() {
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(false);
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" + "}\n" + "x.setName( \"Fred\" );\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" + "x.setName( \"Fred\" );\n" + "end\n";
assertEqualsIgnoreWhitespace(expected2, drl);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", 55l, "" } }));
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);
}
Aggregations