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]);
}
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));
}
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"));
}
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));
}
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());
}
Aggregations