Search in sources :

Example 21 with RuleAttribute

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

Example 22 with RuleAttribute

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

Example 23 with RuleAttribute

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);
}
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 24 with RuleAttribute

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);
}
Also used : 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 25 with RuleAttribute

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);
}
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