use of org.drools.workbench.models.datamodel.rule.CompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testValidateCompositeFactPatternFalse.
@Test
public void testValidateCompositeFactPatternFalse() throws Exception {
CompositeFactPattern not = new CompositeFactPattern();
not.setType("not");
model.addLhsItem(not);
assertFalse(validator.isValid());
assertTrue(validator.getErrors().get(0).equals(MISSING_FACT_PATTERN));
}
use of org.drools.workbench.models.datamodel.rule.CompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testMissingValueWhenOperatorExistsInCompositePattern.
@Test
public void testMissingValueWhenOperatorExistsInCompositePattern() throws Exception {
FactPattern pattern = new FactPattern("Person");
SingleFieldConstraint constraint = new SingleFieldConstraint("age");
constraint.setOperator("==");
pattern.addConstraint(constraint);
CompositeFactPattern not = new CompositeFactPattern();
not.setType("not");
not.addFactPattern(pattern);
model.lhs = new IPattern[] { not };
assertFalse(validator.isValid());
assertEquals(1, validator.getErrors().size());
assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));
verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Person", "age");
}
use of org.drools.workbench.models.datamodel.rule.CompositeFactPattern in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method parseExistentialElementDescr.
private CompositeFactPattern parseExistentialElementDescr(final RuleModel m, final ConditionalElementDescr conditionalDescr, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
CompositeFactPattern comp;
if (conditionalDescr instanceof NotDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
} else if (conditionalDescr instanceof OrDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
} else if (conditionalDescr instanceof ExistsDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
} else {
throw new IllegalArgumentException("Unknown conditional descr type: " + conditionalDescr);
}
addPatternToComposite(m, conditionalDescr, comp, isJavaDialect, boundParams, dmo);
IFactPattern[] patterns = comp.getPatterns();
return patterns != null && patterns.length > 0 ? comp : null;
}
use of org.drools.workbench.models.datamodel.rule.CompositeFactPattern in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testOrComposite.
@Test
public void testOrComposite() throws Exception {
RuleModel m = new RuleModel();
m.name = "or";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sf1 = new SingleFieldConstraint("age");
sf1.setOperator("==");
sf1.setValue("42");
p1.addConstraint(sf1);
cp.addFactPattern(p1);
FactPattern p2 = new FactPattern("Person");
SingleFieldConstraint sf2 = new SingleFieldConstraint("age");
sf2.setOperator("==");
sf2.setValue("43");
p2.addConstraint(sf2);
cp.addFactPattern(p2);
m.addLhsItem(cp);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
assertTrue(result.indexOf("( Person( age == 42 ) or Person( age == 43 ) )") > 0);
checkMarshalling(result, m);
}
use of org.drools.workbench.models.datamodel.rule.CompositeFactPattern in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testSingleExists.
@Test
public void testSingleExists() throws Exception {
RuleModel m = new RuleModel();
m.name = "or";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sf1 = new SingleFieldConstraint("age");
sf1.setOperator("==");
sf1.setValue("42");
p1.addConstraint(sf1);
cp.addFactPattern(p1);
m.addLhsItem(cp);
String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
logger.debug(result);
assertTrue(result.indexOf("exists (Person( age == 42 )) ") > 0);
checkMarshalling(result, m);
}
Aggregations