Search in sources :

Example 56 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceTest method testReturnValueConstraint.

@Test
public void testReturnValueConstraint() {
    RuleModel m = new RuleModel();
    m.name = "yeah";
    FactPattern p = new FactPattern("Goober");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setConstraintValueType(SingleFieldConstraint.TYPE_RET_VALUE);
    con.setValue("someFunc(x)");
    con.setOperator("==");
    con.setFieldName("goo");
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Goober( goo == ( someFunc(x) ) )" + " then " + "end";
    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 57 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceTest method testRHSDateModifyAction.

@Test
public void testRHSDateModifyAction() {
    String oldValue = System.getProperty("drools.dateformat");
    try {
        System.setProperty("drools.dateformat", "dd-MMM-yyyy");
        RuleModel m = new RuleModel();
        m.name = "RHS Date";
        FactPattern p = new FactPattern("Person");
        p.setBoundName("$p");
        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setFieldType(DataType.TYPE_DATE);
        con.setFieldName("dateOfBirth");
        con.setOperator("==");
        con.setValue("31-Jan-2000");
        con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
        p.addConstraint(con);
        m.addLhsItem(p);
        ActionUpdateField am = new ActionUpdateField("$p");
        am.addFieldValue(new ActionFieldValue("dob", "31-Jan-2000", DataType.TYPE_DATE));
        m.addRhsItem(am);
        String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
        assertTrue(result.indexOf("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");") != -1);
        assertTrue(result.indexOf("setDob( sdf.parse(\"31-Jan-2000\"") != -1);
        assertTrue(result.indexOf("modify( $p ) {") != -1);
        checkMarshalling(null, m);
    } finally {
        if (oldValue == null) {
            System.clearProperty("drools.dateformat");
        } else {
            System.setProperty("drools.dateformat", oldValue);
        }
    }
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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)

Example 58 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceTest method testFieldsDeclaredButNoConstraints.

@Test
public void testFieldsDeclaredButNoConstraints() {
    RuleModel m = new RuleModel();
    m.name = "boo";
    FactPattern p = new FactPattern("Person");
    // this isn't an effective constraint, so it should be ignored.
    p.addConstraint(new SingleFieldConstraint("field1"));
    m.addLhsItem(p);
    String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    String expected = "rule \"boo\" \tdialect \"mvel\"\n when Person() then end";
    checkMarshalling(expected, m);
    SingleFieldConstraint con = (SingleFieldConstraint) p.getConstraintList().getConstraint(0);
    con.setFieldBinding("q");
    // now it should appear, as we are binding a var to it
    expected = "rule \"boo\" dialect \"mvel\" when Person(q : field1) then end";
    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 59 with SingleFieldConstraint

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

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

the class RuleModelDRLPersistenceTest method testInOperatorStringCommaInside.

@Test
public void testInOperatorStringCommaInside() {
    final RuleModel model = new RuleModel();
    model.name = "in";
    final FactPattern pattern = new FactPattern("Person");
    final SingleFieldConstraint constraint = new SingleFieldConstraint();
    constraint.setFieldType(DataType.TYPE_STRING);
    constraint.setFieldName("field1");
    constraint.setOperator("in");
    constraint.setValue("value1, \"value2, value3\"");
    constraint.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    pattern.addConstraint(constraint);
    model.addLhsItem(pattern);
    final String expected = "rule \"in\" \n" + "dialect \"mvel\" \n" + "when \n" + "     Person(field1 in ( \"value1\", \"value2, value3\" ) ) \n" + " then \n" + "end";
    checkMarshalling(expected, model);
}
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)

Aggregations

SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)278 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)250 Test (org.junit.Test)242 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)236 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)218 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)199 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)148 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)142 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)138 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)73 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)65 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)64 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)62 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)28 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)25 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)21 ArrayList (java.util.ArrayList)20