Search in sources :

Example 96 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testIncompleteFieldConstraintNonStringWithNull.

@Test
public void testIncompleteFieldConstraintNonStringWithNull() {
    String expected = "" + "rule \"rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    Message()\n" + "  then\n" + "end\n";
    final RuleModel m = new RuleModel();
    m.name = "rule";
    final FactPattern pat = new FactPattern("Message");
    m.addLhsItem(pat);
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldName("number");
    con.setOperator("==");
    con.setValue(null);
    con.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    pat.addConstraint(con);
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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 97 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testEnumNoType.

@Test
public void testEnumNoType() {
    // 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 == \"CheeseType.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("CheeseType.CHEDDAR");
    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 98 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern 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 99 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeOrConstraintsComplex.

@Test
public void testCompositeOrConstraintsComplex() {
    RuleModel m = new RuleModel();
    m.name = "or composite complex";
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFactType("Goober");
    sfc1.setFieldName("gooField");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc1.setValue("gooValue");
    sfc1.setOperator("==");
    comp.addConstraint(sfc1);
    final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setFactType("Goober");
    sfc2.setFieldName("fooField");
    sfc2.setFieldType(DataType.TYPE_OBJECT);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc2.setOperator("!= null");
    comp.addConstraint(sfc2);
    final SingleFieldConstraint sfc3 = new SingleFieldConstraint();
    sfc3.setFactType("Bar");
    sfc3.setFieldName("barField");
    sfc3.setParent(sfc2);
    sfc3.setFieldType(DataType.TYPE_STRING);
    sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc3.setValue("barValue");
    sfc3.setOperator("==");
    comp.addConstraint(sfc3);
    final SingleFieldConstraint sfc4 = new SingleFieldConstraint();
    sfc4.setFactType("Goober");
    sfc4.setFieldName("zooField");
    sfc4.setFieldType(DataType.TYPE_STRING);
    sfc4.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    sfc4.setValue("zooValue");
    sfc4.setOperator("==");
    p.addConstraint(sfc4);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String expected = "rule \"or composite complex\"" + "dialect \"mvel\"\n" + "when\n" + "Goober( gooField == \"gooValue\" || fooField != null || fooField.barField == \"barValue\", zooField == \"zooValue\" )\n" + "then\n" + "insert( new Whee() );\n" + "end";
    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) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 100 with FactPattern

use of org.drools.workbench.models.datamodel.rule.FactPattern in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsModifyBoth.

@Test
public void testRHSChangeMultipleFieldsModifyBoth() {
    String expected = "" + "rule \"my rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    $p : Person()\n" + "  then\n" + "    modify( $p ) {\n" + "      setName( \"Fred\" ),\n" + "      setAge( 55 )\n" + "    }\n" + "end\n";
    final RuleModel m = new RuleModel();
    FactPattern factPattern = new FactPattern();
    factPattern.setFactType("Person");
    factPattern.setBoundName("$p");
    m.lhs = new IPattern[] { factPattern };
    ActionUpdateField auf = new ActionUpdateField();
    auf.setVariable("$p");
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setField("name");
    afv1.setType(DataType.TYPE_STRING);
    afv1.setNature(FieldNatureType.TYPE_LITERAL);
    afv1.setValue("Fred");
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setField("age");
    afv2.setType(DataType.TYPE_NUMERIC_INTEGER);
    afv2.setNature(FieldNatureType.TYPE_LITERAL);
    afv2.setValue("55");
    auf.setFieldValues(new ActionFieldValue[] { afv1, afv2 });
    m.rhs = new IAction[] { auf };
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) 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)

Aggregations

FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)399 Test (org.junit.Test)360 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)335 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)315 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)255 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)249 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)230 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)222 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)221 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)120 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)94 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)89 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)71 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)55 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)42 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)37 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)30 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)30 IAction (org.drools.workbench.models.datamodel.rule.IAction)28 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)24