Search in sources :

Example 36 with FactPattern

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

the class RuleModelTest method testAllVariableBindings.

@Test
public void testAllVariableBindings() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[2];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.setBoundName("boundFact");
    SingleFieldConstraint sfc = new SingleFieldConstraint("q");
    x.addConstraint(sfc);
    sfc.setFieldBinding("field1");
    SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
    x.addConstraint(sfc2);
    sfc2.setFieldBinding("field2");
    model.lhs[1] = new CompositeFactPattern();
    List vars = model.getAllVariables();
    assertEquals(3, vars.size());
    assertEquals("boundFact", vars.get(0));
    assertEquals("field1", vars.get(1));
    assertEquals("field2", vars.get(2));
    assertTrue(model.isVariableNameUsed("field2"));
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) List(java.util.List) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 37 with FactPattern

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

the class RuleModelTest method testScopedVariablesWithCompositeFact.

@Test
public void testScopedVariablesWithCompositeFact() {
    RuleModel m = new RuleModel();
    FactPattern p = new FactPattern();
    CompositeFieldConstraint cf = new CompositeFieldConstraint();
    cf.addConstraint(new SingleFieldConstraint("x"));
    p.addConstraint(cf);
    SingleFieldConstraint sf = new SingleFieldConstraint("q");
    sf.setFieldBinding("abc");
    p.addConstraint(sf);
    SingleFieldConstraint sf2 = new SingleFieldConstraint("q");
    sf2.setFieldBinding("qed");
    cf.addConstraint(sf2);
    m.addLhsItem(p);
    List vars = m.getAllVariables();
    assertEquals(1, vars.size());
    assertEquals("abc", vars.get(0));
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) List(java.util.List) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 38 with FactPattern

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

the class RuleModelTest method testIsDSLEnhanced.

@Test
public void testIsDSLEnhanced() throws Exception {
    RuleModel m = new RuleModel();
    assertFalse(m.hasDSLSentences());
    m.addLhsItem(new FactPattern());
    assertFalse(m.hasDSLSentences());
    m.addRhsItem(new ActionSetField("q"));
    assertFalse(m.hasDSLSentences());
    m.addLhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());
    m.addRhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());
    m = new RuleModel();
    m.addLhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());
    m = new RuleModel();
    m.addRhsItem(new DSLSentence());
    assertTrue(m.hasDSLSentences());
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 39 with FactPattern

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

the class RuleModelTest method testRemoveItemLhs.

@Test
public void testRemoveItemLhs() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[3];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.setBoundName("x");
    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.setBoundName("y");
    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;
    assertEquals(3, model.lhs.length);
    assertEquals(x, model.lhs[0]);
    model.removeLhsItem(0);
    assertEquals(2, model.lhs.length);
    assertEquals(y, model.lhs[0]);
}
Also used : FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 40 with FactPattern

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

the class RuleModelDRLPersistenceUnmarshallingTest method testReciprocal_CompositeFactPatternWithOr.

@Test
public void testReciprocal_CompositeFactPatternWithOr() {
    // This is the inverse of "CompositeFactPatternWithOr"
    String drl = "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "( Person( age == 42 ) or Person( age == 43 ) )\n" + "then\n" + "end";
    RuleModel m = new RuleModel();
    m.name = "rule1";
    // LHS Patterns
    CompositeFactPattern cfp = new CompositeFactPattern();
    cfp.setType(CompositeFactPattern.COMPOSITE_TYPE_OR);
    // LHS sub-patterns
    FactPattern fp1 = new FactPattern();
    fp1.setFactType("Person");
    SingleFieldConstraint cfp_sfp1 = new SingleFieldConstraint();
    cfp_sfp1.setFactType("Person");
    cfp_sfp1.setFieldName("age");
    cfp_sfp1.setOperator("==");
    cfp_sfp1.setValue("42");
    cfp_sfp1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cfp_sfp1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp1.addConstraint(cfp_sfp1);
    cfp.addFactPattern(fp1);
    FactPattern fp2 = new FactPattern();
    fp2.setFactType("Person");
    SingleFieldConstraint cfp_sfp2 = new SingleFieldConstraint();
    cfp_sfp2.setFactType("Person");
    cfp_sfp2.setFieldName("age");
    cfp_sfp2.setOperator("==");
    cfp_sfp2.setValue("43");
    cfp_sfp2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cfp_sfp2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp2.addConstraint(cfp_sfp2);
    cfp.addFactPattern(fp2);
    m.addLhsItem(cfp);
    String actualDrl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertEqualsIgnoreWhitespace(drl, actualDrl);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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