Search in sources :

Example 6 with AttributeDescr

use of org.drools.compiler.lang.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.compiler.lang.descr.RuleDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 7 with AttributeDescr

use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testNoLoop.

@Test
public void testNoLoop() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "no-loop.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertNotNull(rule);
    assertEquals("rule1", rule.getName());
    final AttributeDescr att = (AttributeDescr) rule.getAttributes().get("no-loop");
    assertEquals("false", att.getValue());
    assertEquals("no-loop", att.getName());
}
Also used : RuleDescr(org.drools.compiler.lang.descr.RuleDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 8 with AttributeDescr

use of org.drools.compiler.lang.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.compiler.lang.descr.PackageDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 9 with AttributeDescr

use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.

the class RuleParserTest method testCalendars2.

@Test
public void testCalendars2() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_calendars_attribute2.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    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("calendars");
    assertEquals("calendars", at.getName());
    assertEquals("[ \"cal 1\", \"cal 2\", \"cal 3\" ]", at.getValue());
    at = (AttributeDescr) attrs.get("lock-on-active");
    assertEquals("lock-on-active", at.getName());
    assertEquals("true", at.getValue());
}
Also used : RuleDescr(org.drools.compiler.lang.descr.RuleDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 10 with AttributeDescr

use of org.drools.compiler.lang.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.compiler.lang.descr.PackageDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Aggregations

AttributeDescr (org.drools.compiler.lang.descr.AttributeDescr)35 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)23 Test (org.junit.Test)20 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)11 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)6 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)5 RecognitionException (org.antlr.runtime.RecognitionException)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 DrlParser (org.drools.compiler.compiler.DrlParser)2 DroolsError (org.drools.compiler.compiler.DroolsError)2 AndDescr (org.drools.compiler.lang.descr.AndDescr)2 FunctionImportDescr (org.drools.compiler.lang.descr.FunctionImportDescr)2 ImportDescr (org.drools.compiler.lang.descr.ImportDescr)2