Search in sources :

Example 46 with ActionInsertFact

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);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) 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 47 with ActionInsertFact

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

Example 48 with ActionInsertFact

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);
}
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 49 with ActionInsertFact

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);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) 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 50 with ActionInsertFact

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

Aggregations

ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)78 Test (org.junit.Test)64 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)48 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)47 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)43 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)42 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)39 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)34 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)34 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)34 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)32 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)24 IAction (org.drools.workbench.models.datamodel.rule.IAction)17 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)13 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 ArrayList (java.util.ArrayList)11 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)10 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10