use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method multipleConstraintLHSNotPatternInclusion.
@Test
public void multipleConstraintLHSNotPatternInclusion() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
Object[] row = new Object[] { "1", "desc", "limburger", "strong" };
Object[][] data = new Object[1][];
data[0] = row;
List<BaseColumn> allColumns = new ArrayList<>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
Pattern52 p1 = new Pattern52();
p1.setBoundName("");
p1.setNegated(true);
p1.setFactType("Cheese");
allPatterns.add(p1);
ConditionCol52 p1col1 = new ConditionCol52();
p1col1.setFactField("name");
p1col1.setOperator("==");
p1col1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(p1col1);
allColumns.add(p1col1);
ConditionCol52 p1col2 = new ConditionCol52();
p1col2.setFactField("smell");
p1col2.setOperator("==");
p1col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(p1col2);
allColumns.add(p1col2);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
RuleModel rm = new RuleModel();
rm.name = "r0";
p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
final String actualRuleModelDrl = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
final String expectedRuleModelDrl = "rule \"r0\"\n" + " dialect \"mvel\"\n" + " when\n" + " not Cheese( name == \"limburger\", smell == \"strong\" )\n" + " then\n" + "end\n";
assertEqualsIgnoreWhitespace(expectedRuleModelDrl, actualRuleModelDrl);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSBindings.
@Test
public void testLHSBindings() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "mike", "33 + 1", "age > 6" };
String[][] data = new String[1][];
data[0] = row;
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Person");
allPatterns.add(p1);
ConditionCol52 col = new ConditionCol52();
col.setFactField("name");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setOperator("==");
col.setBinding("$name");
p1.getChildColumns().add(col);
allColumns.add(col);
ConditionCol52 col2 = new ConditionCol52();
col2.setFactField("age");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
col2.setOperator("<");
col2.setBinding("$age");
p1.getChildColumns().add(col2);
allColumns.add(col2);
ConditionCol52 col3 = new ConditionCol52();
col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
col3.setBinding("$name");
p1.getChildColumns().add(col3);
allColumns.add(col3);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
RuleModel rm = new RuleModel();
p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
assertEquals(1, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
// examine the first pattern
FactPattern person = (FactPattern) rm.lhs[0];
assertEquals(3, person.getConstraintList().getConstraints().length);
SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0);
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
assertEquals("name", cons.getFieldName());
assertEquals("==", cons.getOperator());
assertEquals("mike", cons.getValue());
assertEquals("$name", cons.getFieldBinding());
cons = (SingleFieldConstraint) person.getConstraint(1);
assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType());
assertEquals("age", cons.getFieldName());
assertEquals("<", cons.getOperator());
assertEquals("33 + 1", cons.getValue());
assertEquals("$age", cons.getFieldBinding());
cons = (SingleFieldConstraint) person.getConstraint(2);
assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType());
assertEquals("age > 6", cons.getValue());
assertNull(cons.getFieldBinding());
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testDefaultValue.
@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);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSInOperator.
@Test
public void testLHSInOperator() {
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("in");
p1.getChildColumns().add(cc1);
ConditionCol52 cc2 = new ConditionCol52();
cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
cc2.setFactField("age");
cc2.setOperator("in");
p1.getChildColumns().add(cc2);
dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", "Pupa, Brains, \"John, Snow\"", "55, 66" }, new Object[] { 2l, "desc", "", "" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
int index = -1;
index = drl.indexOf("Smurf( name in ( \"Pupa\", \"Brains\", \"John, Snow\" ) , age in ( 55, 66 ) )");
assertTrue(index > -1);
index = drl.indexOf("Smurf( )", index + 1);
assertFalse(index > -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testInOperator.
@Test
public void testInOperator() {
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("in");
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);
ConditionCol52 con4 = new ConditionCol52();
con4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
con4.setHeader("Driver 2 pimp");
con4.setFactField("(not needed)");
p1.getChildColumns().add(con4);
dt.getConditions().add(p1);
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, manik", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "", "39", "bob, frank", "age * 0.3", "age > 7", "6.60", "", "gooVal1", null } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("name in ( \"michael\",") > 0);
}
Aggregations