Search in sources :

Example 26 with AttributeDescr

use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testDialect.

@Test
public void testDialect() throws Exception {
    final String source = "dialect 'mvel'";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    AttributeDescr attr = (AttributeDescr) pkg.getAttributes().get(0);
    assertEquals("dialect", attr.getName());
    assertEquals("mvel", attr.getValue());
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Example 27 with AttributeDescr

use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_attributes.drl");
    assertEquals("simple_rule", rule.getName());
    assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
    final Map<String, AttributeDescr> attrs = rule.getAttributes();
    assertEquals(6, attrs.size());
    AttributeDescr at = (AttributeDescr) attrs.get("salience");
    assertEquals("salience", at.getName());
    assertEquals("42", at.getValue());
    at = (AttributeDescr) attrs.get("agenda-group");
    assertEquals("agenda-group", at.getName());
    assertEquals("my_group", at.getValue());
    at = (AttributeDescr) attrs.get("no-loop");
    assertEquals("no-loop", at.getName());
    assertEquals("true", at.getValue());
    at = (AttributeDescr) attrs.get("duration");
    assertEquals("duration", at.getName());
    assertEquals("42", at.getValue());
    at = (AttributeDescr) attrs.get("activation-group");
    assertEquals("activation-group", at.getName());
    assertEquals("my_activation_group", at.getValue());
    at = (AttributeDescr) attrs.get("lock-on-active");
    assertEquals("lock-on-active", at.getName());
    assertEquals("true", at.getValue());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Example 28 with AttributeDescr

use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testAttributeRefract.

@Test
public void testAttributeRefract() throws Exception {
    final String source = "rule Test refract when Person() then end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals("Test", rule.getName());
    Map<String, AttributeDescr> attributes = rule.getAttributes();
    assertEquals(1, attributes.size());
    AttributeDescr refract = attributes.get("refract");
    assertNotNull(refract);
    assertEquals("true", refract.getValue());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Example 29 with AttributeDescr

use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testDialect2.

@Test
public void testDialect2() throws Exception {
    final String source = "dialect \"mvel\"";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    AttributeDescr attr = pkg.getAttributes().get(0);
    assertEquals("dialect", attr.getName());
    assertEquals("mvel", attr.getValue());
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Example 30 with AttributeDescr

use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testPackageAttributes.

@Test
public void testPackageAttributes() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "package_attributes.drl");
    AttributeDescr at = (AttributeDescr) pkg.getAttributes().get(0);
    assertEquals("agenda-group", at.getName());
    assertEquals("x", at.getValue());
    at = (AttributeDescr) pkg.getAttributes().get(1);
    assertEquals("dialect", at.getName());
    assertEquals("java", at.getValue());
    assertEquals(2, pkg.getRules().size());
    assertEquals(2, pkg.getImports().size());
    RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals("bar", rule.getName());
    at = (AttributeDescr) rule.getAttributes().get("agenda-group");
    assertEquals("agenda-group", at.getName());
    assertEquals("x", at.getValue());
    at = (AttributeDescr) rule.getAttributes().get("dialect");
    assertEquals("dialect", at.getName());
    assertEquals("java", at.getValue());
    rule = (RuleDescr) pkg.getRules().get(1);
    assertEquals("baz", rule.getName());
    at = (AttributeDescr) rule.getAttributes().get("dialect");
    assertEquals("dialect", at.getName());
    assertEquals("mvel", at.getValue());
    at = (AttributeDescr) rule.getAttributes().get("agenda-group");
    assertEquals("agenda-group", at.getName());
    assertEquals("x", at.getValue());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr) Test(org.junit.Test)

Aggregations

AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)34 RuleDescr (org.drools.drl.ast.descr.RuleDescr)26 Test (org.junit.Test)21 PackageDescr (org.drools.drl.ast.descr.PackageDescr)13 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)6 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)5 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Pattern (org.drools.core.rule.Pattern)3 AndDescr (org.drools.drl.ast.descr.AndDescr)3 FunctionImportDescr (org.drools.drl.ast.descr.FunctionImportDescr)3 ImportDescr (org.drools.drl.ast.descr.ImportDescr)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)2