Search in sources :

Example 56 with RuleModel

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

the class RuleModelTest method testAddItemRhs.

@Test
public void testAddItemRhs() {
    final RuleModel model = new RuleModel();
    final IAction a0 = new ActionSetField();
    final IAction a1 = new ActionSetField();
    model.addRhsItem(a0);
    assertEquals(1, model.rhs.length);
    model.addRhsItem(a1);
    assertEquals(2, model.rhs.length);
    assertEquals(a0, model.rhs[0]);
    assertEquals(a1, model.rhs[1]);
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 57 with RuleModel

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

the class RuleModelTest method testAllVariableBindings2.

@Test
public void testAllVariableBindings2() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[1];
    final FactPattern fp = new FactPattern("Car");
    model.lhs[0] = fp;
    fp.setBoundName("$c");
    SingleFieldConstraint sfc = new SingleFieldConstraintEBLeftSide("make");
    sfc.getExpressionValue().appendPart(new ExpressionField("make", "java.lang.String", "String"));
    sfc.setFieldBinding("$m");
    fp.addConstraint(sfc);
    List<String> vars = model.getAllVariables();
    assertEquals(2, vars.size());
    assertEquals("$c", vars.get(0));
    assertEquals("$m", vars.get(1));
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 58 with RuleModel

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

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

use of org.drools.workbench.models.datamodel.rule.RuleModel 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)

Aggregations

RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)384 Test (org.junit.Test)352 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)223 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)216 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)215 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)201 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)201 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)145 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)134 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)91 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)85 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)63 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)47 ArrayList (java.util.ArrayList)44 IAction (org.drools.workbench.models.datamodel.rule.IAction)31 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)29 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)29 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)27 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)25 List (java.util.List)24