Search in sources :

Example 11 with ExpressionUnboundFact

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

the class RuleModelDRLPersistenceTest method testLHSExpressionNumber.

@Test
public void testLHSExpressionNumber() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsNumber";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("field1", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER));
    con.setOperator("==");
    con.setValue("55");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsNumber\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == 55 )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) 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) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 12 with ExpressionUnboundFact

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

the class RuleModelDRLPersistenceTest method testLHSExpressionNestedJavaEnum.

@Test
public void testLHSExpressionNestedJavaEnum() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsNestedJavaEnum";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("favouriteCheese", "Cheese", DataType.TYPE_OBJECT));
    con.getExpressionLeftSide().appendPart(new ExpressionField("genericName", "CHEESE", DataType.TYPE_COMPARABLE));
    con.setOperator("==");
    con.setValue("CHEESE.Cheddar");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsNestedJavaEnum\"" + "\tdialect \"mvel\"\n when " + "     Person( favouriteCheese.genericName == CHEESE.Cheddar )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) 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) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 13 with ExpressionUnboundFact

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

the class RuleModelDRLPersistenceTest method testLHSFormula.

@Test
public void testLHSFormula() {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1087690
    RuleModel m = new RuleModel();
    m.name = "test";
    FactPattern p = new FactPattern("Number");
    m.addLhsItem(p);
    SingleFieldConstraint con1 = new SingleFieldConstraint();
    con1.setValue("true");
    con1.setConstraintValueType(SingleFieldConstraint.TYPE_PREDICATE);
    p.addConstraint(con1);
    SingleFieldConstraintEBLeftSide con2 = new SingleFieldConstraintEBLeftSide();
    con2.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con2.getExpressionLeftSide().appendPart(new ExpressionMethod("intValue", "int", DataType.TYPE_NUMERIC_INTEGER));
    con2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    con2.setOperator("==");
    con2.setValue("0");
    p.addConstraint(con2);
    String expected = "rule \"test\"\n" + "dialect \"mvel\"\n" + "when\n" + "Number( eval( true ), intValue() == 0 )\n" + "then\n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) 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) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 14 with ExpressionUnboundFact

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

the class RuleModelDRLPersistenceTest method testLHSExpressionBoolean.

@Test
public void testLHSExpressionBoolean() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsBoolean";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con.getExpressionLeftSide().appendPart(new ExpressionField("field1", "java.lang.Boolean", DataType.TYPE_BOOLEAN));
    con.setOperator("==");
    con.setValue("true");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsBoolean\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == true )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) 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) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 15 with ExpressionUnboundFact

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

the class RuleModelDRLPersistenceTest method testLHSReturnType.

@Test
public void testLHSReturnType() {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1087690
    RuleModel m = new RuleModel();
    m.name = "test";
    FactPattern p = new FactPattern("Number");
    m.addLhsItem(p);
    SingleFieldConstraint con1 = new SingleFieldConstraint();
    con1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    con1.setFieldName("this");
    con1.setOperator("!= null");
    con1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con1);
    SingleFieldConstraintEBLeftSide con2 = new SingleFieldConstraintEBLeftSide();
    con2.getExpressionLeftSide().appendPart(new ExpressionUnboundFact(p.getFactType()));
    con2.getExpressionLeftSide().appendPart(new ExpressionMethod("intValue", "int", DataType.TYPE_NUMERIC_INTEGER));
    con2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    con2.setOperator("==");
    con2.setValue("0");
    p.addConstraint(con2);
    String expected = "rule \"test\"\n" + "dialect \"mvel\"\n" + "when\n" + "Number( this != null, intValue() == 0 )\n" + "then\n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) 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) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Aggregations

ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)27 Test (org.junit.Test)25 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)24 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)24 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)24 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)24 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)24 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)24 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)21 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)12 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)9 HashMap (java.util.HashMap)3 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 ExpressionCollection (org.drools.workbench.models.datamodel.rule.ExpressionCollection)2 ExpressionMethodParameter (org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter)2 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)2