use of org.drools.compiler.lang.descr.ExistsDescr in project drools by kiegroup.
the class RuleParserTest method testNotExistWithBrackets.
@Test
public void testNotExistWithBrackets() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "not_exist_with_brackets.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(2, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
final ExistsDescr ex = (ExistsDescr) lhs.getDescrs().get(1);
assertEquals(1, ex.getDescrs().size());
final PatternDescr exPattern = (PatternDescr) ex.getDescrs().get(0);
assertEquals("Foo", exPattern.getObjectType());
}
use of org.drools.compiler.lang.descr.ExistsDescr in project drools by kiegroup.
the class CEDescrBuilderImpl method exists.
/**
* {@inheritDoc}
*/
public CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists() {
CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists = new CEDescrBuilderImpl<CEDescrBuilder<P, T>, ExistsDescr>(this, new ExistsDescr());
((ConditionalElementDescr) descr).addDescr(exists.getDescr());
return exists;
}
use of org.drools.compiler.lang.descr.ExistsDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method testExists.
@Test
public void testExists() throws Exception {
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
// Make sure we can't accessa variable bound inside the not node
RuleImpl rule = createRule(new ExistsDescr(), builder, "update(stilton);");
assertTrue(builder.hasErrors());
builder = new KnowledgeBuilderImpl();
rule = createRule(new ExistsDescr(), builder, "");
assertEquals(0, builder.getErrors().getErrors().length);
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement exists = (GroupElement) lhs.getChildren().get(0);
assertLength(1, exists.getChildren());
final Pattern pattern = (Pattern) exists.getChildren().get(0);
}
use of org.drools.compiler.lang.descr.ExistsDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseExists.
@Test
public void testParseExists() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseExists.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
Object existdescr = obj.getLhs().getDescrs().get(0);
assertTrue(existdescr instanceof ExistsDescr);
Object patternDescriptor = ((ExistsDescr) existdescr).getDescrs().get(0);
assertTrue(patternDescriptor instanceof PatternDescr);
assertEquals(((PatternDescr) patternDescriptor).getObjectType(), "Person");
Object notDescr = obj.getLhs().getDescrs().get(1);
assertEquals(notDescr.getClass().getName(), NotDescr.class.getName());
existdescr = ((NotDescr) notDescr).getDescrs().get(0);
patternDescriptor = ((ExistsDescr) existdescr).getDescrs().get(0);
assertTrue(patternDescriptor instanceof PatternDescr);
assertEquals(((PatternDescr) patternDescriptor).getObjectType(), "Cheese");
}
use of org.drools.compiler.lang.descr.ExistsDescr 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;
}
Aggregations