use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testLiteralBigDecimalMvel.
@Test
public void testLiteralBigDecimalMvel() {
RuleModel m = new RuleModel();
m.name = "test literal bigdecimal";
m.addAttribute(new RuleAttribute("dialect", "mvel"));
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 \"mvel\"\n when \n" + " Person(field1 == 44B) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( 55B ); \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 testBasics2.
@Test
public void testBasics2() {
final RuleModelPersistence p = RuleModelDRLPersistenceImpl.getInstance();
final 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"));
ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd();
ag.setFactName("x");
ag.setGlobalName("g");
m.addRhsItem(ag);
m.name = "my rule";
final String drl = p.marshal(m);
assertTrue(drl.indexOf("Person( )") > -1);
assertTrue(drl.indexOf("Accident( )") > -1);
assertTrue(drl.indexOf("no-loop true") > -1);
assertTrue(drl.indexOf("org.kie") == -1);
assertTrue(drl.indexOf("g.add( x );") > -1);
PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
RuleModel rm_ = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
assertEquals(2, rm_.rhs.length);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testAttr.
@Test
public void testAttr() {
RuleModel m = new RuleModel();
m.attributes = new RuleAttribute[1];
m.attributes[0] = new RuleAttribute("enabled", "true");
final String drl = ruleModelPersistence.marshal(m);
assertTrue(drl.indexOf("enabled true") > 0);
}
use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testLiteralBigIntegerJava.
@Test
public void testLiteralBigIntegerJava() {
RuleModel m = new RuleModel();
m.name = "test literal biginteger";
m.addAttribute(new RuleAttribute("dialect", "java"));
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 \"java\"\n when \n" + " Person(field1 == 44I ) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( new java.math.BigInteger( \"55\" ) ); \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 testCalendars.
@Test
public void testCalendars() {
// 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