use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSSetMethodCallsMethodJava.
@Test
public void testRHSSetMethodCallsMethodJava() {
String oldValue = System.getProperty("drools.dateformat");
try {
System.setProperty("drools.dateformat", "dd-MMM-yyyy");
RuleModel m = new RuleModel();
m.name = "RHS SetMethodCallsMethod";
m.addAttribute(new RuleAttribute("dialect", "java"));
FactPattern p = new FactPattern("Person");
p.setBoundName("$p");
m.addLhsItem(p);
ActionCallMethod acm = new ActionCallMethod();
acm.setMethodName("method");
acm.setVariable("$p");
acm.addFieldValue(new ActionFieldFunction("f1", "String", DataType.TYPE_STRING));
acm.addFieldValue(new ActionFieldFunction("f2", "true", DataType.TYPE_BOOLEAN));
acm.addFieldValue(new ActionFieldFunction("f3", "31-Jan-2012", DataType.TYPE_DATE));
acm.addFieldValue(new ActionFieldFunction("f4", "100", DataType.TYPE_NUMERIC_INTEGER));
acm.addFieldValue(new ActionFieldFunction("f5", "100", DataType.TYPE_NUMERIC_BIGDECIMAL));
m.addRhsItem(acm);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
assertTrue(result.indexOf("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");") != -1);
assertTrue(result.indexOf("$p.method( \"String\", true, sdf.parse(\"31-Jan-2012\"), 100, new java.math.BigDecimal(\"100\") );") != -1);
checkMarshalling(null, m);
} finally {
if (oldValue == null) {
System.clearProperty("drools.dateformat");
} else {
System.setProperty("drools.dateformat", oldValue);
}
}
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testRHSFactBindingZeroBound.
@Test
public void testRHSFactBindingZeroBound() {
RuleModel m = new RuleModel();
m.addAttribute(new RuleAttribute("dialect", "mvel"));
m.name = "test";
ActionInsertFact ai0 = new ActionInsertFact("Person");
ai0.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_LONG));
ActionInsertFact ai1 = new ActionInsertFact("Person");
ai1.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_LONG));
m.addRhsItem(ai0);
m.addRhsItem(ai1);
String expected = "rule \"test\" \n" + "dialect \"mvel\"\n" + "when" + "then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( 55 ); \n" + "insert( fact0 ); \n" + "Person fact1 = new Person(); \n" + "fact1.setField1( 55 ); \n" + "insert( fact1 ); \n" + "end";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testLiteralBigIntegerMvel.
@Test
public void testLiteralBigIntegerMvel() {
RuleModel m = new RuleModel();
m.name = "test literal biginteger";
m.addAttribute(new RuleAttribute("dialect", "mvel"));
FactPattern p = new FactPattern("Person");
SingleFieldConstraint con = new SingleFieldConstraint();
con.setFieldType(DataType.TYPE_NUMERIC_BIGINTEGER);
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_BIGINTEGER));
m.addRhsItem(ai);
String expected = "rule \"test literal biginteger\" \n" + "\tdialect \"mvel\"\n when \n" + " Person(field1 == 44I ) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( 55I ); \n" + "insert( fact0 ); \n" + "end";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testBasics.
@Test
public void testBasics() {
String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n";
RuleModel m = new RuleModel();
m.addLhsItem(new FactPattern("Person"));
m.addLhsItem(new FactPattern("Accident"));
m.addAttribute(new RuleAttribute("no-loop", "true"));
m.addRhsItem(new ActionInsertFact("Report"));
m.name = "my rule";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCalendarsWithQuotesAroundWholeValue.
@Test
public void testCalendarsWithQuotesAroundWholeValue() {
// BZ1059232 - Guided rule editor: calendars attribute is broken when a list of calendars is used
RuleModel m = new RuleModel();
m.attributes = new RuleAttribute[1];
m.attributes[0] = new RuleAttribute("calendars", "\"a, b\"");
final String drl = ruleModelPersistence.marshal(m);
assertTrue(drl.indexOf("calendars \"a\", \"b\"") > 0);
}
Aggregations