Search in sources :

Example 6 with RuleAttribute

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);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 7 with RuleAttribute

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);
}
Also used : ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Example 8 with RuleAttribute

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);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 9 with RuleAttribute

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);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 10 with RuleAttribute

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);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)33 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)25 Test (org.junit.Test)24 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)14 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)14 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)12 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)12 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)12 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)11 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)11 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)9 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)7 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)4 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)4 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)4 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)4 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)3 ActionFieldFunction (org.drools.workbench.models.datamodel.rule.ActionFieldFunction)3 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3