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