use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testEnumTypeComparable.
@Test
public void testEnumTypeComparable() {
// Java 1.5+ "true" enums are of type Comparable
String expected = "rule \"my rule\"\n\tdialect \"mvel\"\n\twhen\n\t\tCheese( type == Cheese.CHEDDAR )\n" + "\tthen\n\t\tinsert( new Report() );\nend\n";
final RuleModel m = new RuleModel();
final FactPattern pat = new FactPattern("Cheese");
m.addLhsItem(pat);
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldName("type");
con.setOperator("==");
con.setValue("Cheese.CHEDDAR");
con.setFieldType(DataType.TYPE_COMPARABLE);
con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_ENUM);
pat.addConstraint(con);
m.addRhsItem(new ActionInsertFact("Report"));
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testAssertWithDSL.
@Test
public void testAssertWithDSL() throws Exception {
RuleModel m = new RuleModel();
DSLSentence sen = new DSLSentence();
sen.setDefinition("I CAN HAS DSL");
m.addRhsItem(sen);
ActionInsertFact ins = new ActionInsertFact("Shizzle");
ActionFieldValue val = new ActionFieldValue("goo", "42", "Numeric");
ins.setFieldValues(new ActionFieldValue[1]);
ins.getFieldValues()[0] = val;
m.addRhsItem(ins);
ActionInsertLogicalFact insL = new ActionInsertLogicalFact("Shizzle");
ActionFieldValue valL = new ActionFieldValue("goo", "42", "Numeric");
insL.setFieldValues(new ActionFieldValue[1]);
insL.getFieldValues()[0] = valL;
m.addRhsItem(insL);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
assertTrue(result.indexOf(">insert") > -1);
assertTrue(result.indexOf(">insertLogical") > -1);
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testLiteralBigDecimalJava.
@Test
public void testLiteralBigDecimalJava() {
RuleModel m = new RuleModel();
m.name = "test literal bigdecimal";
m.addAttribute(new RuleAttribute("dialect", "java"));
FactPattern p = new FactPattern("Person");
SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldType(DataType.TYPE_NUMERIC_BIGDECIMAL);
con.setFieldName("field1");
con.setOperator("==");
con.setValue("44");
con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
p.addConstraint(con);
m.addLhsItem(p);
ActionInsertFact ai = new ActionInsertFact("Person");
ai.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_BIGDECIMAL));
m.addRhsItem(ai);
String expected = "rule \"test literal bigdecimal\" \n" + "\tdialect \"java\"\n when \n" + " Person(field1 == 44B) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( new java.math.BigDecimal( \"55\" ) ); \n" + "insert( fact0 ); \n" + "end";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testEnumTypeStringInOperator.
@Test
public void testEnumTypeStringInOperator() {
// A legacy "Guvnor" enums (i.e pick-list of underlying field data-type)
String expected = "rule \"my rule\"\n" + "\tdialect \"mvel\"\n" + "\twhen\n" + "\t\tCheese( type in ( \"CHEDDAR\", \"STILTON\" ) )\n" + "\tthen\n" + "\t\tinsert( new Report() );\n" + "end\n";
final RuleModel m = new RuleModel();
final FactPattern pat = new FactPattern("Cheese");
m.addLhsItem(pat);
final SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldName("type");
con.setOperator("in");
con.setValue("( \"CHEDDAR\",\"STILTON\" )");
con.setFieldType(DataType.TYPE_STRING);
con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_ENUM);
pat.addConstraint(con);
m.addRhsItem(new ActionInsertFact("Report"));
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ActionInsertFact in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSFactBindingLastBound.
@Test
public void testRHSFactBindingLastBound() {
RuleModel m = new RuleModel();
m.name = "test";
ActionInsertFact ai0 = new ActionInsertFact("Person");
ai0.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_LONG));
ActionInsertFact ai1 = new ActionInsertFact("Person");
ai1.setBoundName("fact0");
ai1.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_LONG));
m.addRhsItem(ai0);
m.addRhsItem(ai1);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
String expected = "rule \"test\" \n" + "dialect \"mvel\"\n" + "when" + "then \n" + "Person fact1 = new Person(); \n" + "fact1.setField1( 55 ); \n" + "insert( fact1 ); \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( 55 ); \n" + "insert( fact0 ); \n" + "end";
checkMarshalling(expected, m);
}
Aggregations