use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class RuleBuilderTest method testInvalidDialect.
@Test
public void testInvalidDialect() throws Exception {
final PackageDescr pkgDescr = new PackageDescr("org.drools");
final RuleDescr ruleDescr = new RuleDescr("Test Rule");
ruleDescr.addAttribute(new AttributeDescr("dialect", "mvl"));
ruleDescr.setConsequence("");
pkgDescr.addRule(ruleDescr);
final KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl();
kBuilder.addPackage(pkgDescr);
assertFalse(kBuilder.getErrors().toString(), kBuilder.getErrors().isEmpty());
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class MVELConsequenceBuilderTest method setupTest.
private void setupTest(String consequence, Map<String, Object> namedConsequences) {
builder = new MVELConsequenceBuilder();
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.drools.compiler.test");
pkg.addImport(new ImportDeclaration(Cheese.class.getCanonicalName()));
KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg, conf);
ruleDescr = new RuleDescr("test consequence builder");
ruleDescr.setConsequence(consequence);
ruleDescr.addAttribute(new AttributeDescr("dialect", "mvel"));
for (Entry<String, Object> entry : namedConsequences.entrySet()) {
ruleDescr.addNamedConsequences(entry.getKey(), entry.getValue());
}
RuleImpl rule = new RuleImpl(ruleDescr.getName());
rule.addPattern(new Pattern(0, new ClassObjectType(Cheese.class), "$cheese"));
rule.addPattern(new Pattern(0, new ClassObjectType(Map.class), "$map"));
PackageRegistry pkgRegistry = pkgBuilder.getPackageRegistry(pkg.getName());
DialectCompiletimeRegistry reg = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
context = new RuleBuildContext(pkgBuilder, ruleDescr, reg, pkg, reg.getDialect(pkgRegistry.getDialect()));
context.getDeclarationResolver().pushOnBuildStack(rule.getLhs());
context.getDialect().getConsequenceBuilder().build(context, RuleImpl.DEFAULT_CONSEQUENCE_NAME);
for (String name : namedConsequences.keySet()) {
context.getDialect().getConsequenceBuilder().build(context, name);
}
context.getDialect().addRule(context);
pkgRegistry.getPackage().addRule(context.getRule());
pkgBuilder.compileAll();
pkgBuilder.reloadAll();
if (pkgBuilder.hasErrors()) {
fail(pkgBuilder.getErrors().toString());
}
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class RuleParserTest method testRuleFlowGroup.
@Test
public void testRuleFlowGroup() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "ruleflowgroup.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
assertEquals("rule1", rule.getName());
final AttributeDescr att = (AttributeDescr) rule.getAttributes().get("ruleflow-group");
assertEquals("a group", att.getValue());
assertEquals("ruleflow-group", att.getName());
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class RuleParserTest method testEnabledExpression.
@Test
public void testEnabledExpression() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_enabled_expression.drl");
assertEquals("simple_rule", rule.getName());
assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(3, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("enabled");
assertEquals("enabled", at.getName());
assertEquals("( 1 + 1 == 2 )", at.getValue());
at = (AttributeDescr) attrs.get("salience");
assertEquals("salience", at.getName());
assertEquals("( 1+2 )", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class RuleParserTest method testDurationExpression.
@Test
public void testDurationExpression() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_duration_expression.drl");
assertEquals("simple_rule", rule.getName());
assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(2, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("duration");
assertEquals("duration", at.getName());
assertEquals("1h30m", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
Aggregations