use of org.drools.drl.ast.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());
}
use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.
the class RuleParserTest method testAttributes2.
@Test
public void testAttributes2() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "rule_attributes2.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
List<RuleDescr> rules = pkg.getRules();
assertEquals(3, rules.size());
RuleDescr rule = rules.get(0);
assertEquals("rule1", rule.getName());
Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(2, 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());
rule = rules.get(1);
assertEquals("rule2", rule.getName());
attrs = rule.getAttributes();
assertEquals(2, attrs.size());
at = (AttributeDescr) attrs.get("salience");
assertEquals("salience", at.getName());
assertEquals("(Integer.MIN_VALUE)", at.getValue());
at = (AttributeDescr) attrs.get("no-loop");
assertEquals("no-loop", at.getName());
rule = rules.get(2);
assertEquals("rule3", rule.getName());
attrs = rule.getAttributes();
assertEquals(2, attrs.size());
at = (AttributeDescr) attrs.get("enabled");
assertEquals("enabled", at.getName());
assertEquals("(Boolean.TRUE)", at.getValue());
at = (AttributeDescr) attrs.get("activation-group");
assertEquals("activation-group", at.getName());
assertEquals("my_activation_group", at.getValue());
}
use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.
the class PackageBuilderConfigurationTest method testMockDialect.
@Test
public void testMockDialect() {
InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1");
KnowledgeBuilderConfigurationImpl cfg1 = new KnowledgeBuilderConfigurationImpl();
MockDialectConfiguration mockConf = new MockDialectConfiguration();
// cfg1.buildDialectRegistry().addDialect( "mock",
// mockConf.getDialect() );
cfg1.addDialect("mock", mockConf);
cfg1.setDefaultDialect("mock");
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl(pkg, cfg1);
PackageRegistry pkgRegistry = builder.getPackageRegistry(pkg.getName());
DialectCompiletimeRegistry dialectRegistry = pkgRegistry.getDialectCompiletimeRegistry();
MockDialect mockDialect2 = (MockDialect) dialectRegistry.getDialect(cfg1.getDefaultDialect());
assertSame(pkg, mockDialect2.getPkg());
assertNull(mockDialect2.getRuleDescr());
RuleDescr ruleDescr = new RuleDescr("test rule");
ruleDescr.addAttribute(new AttributeDescr("dialect", "mock"));
ruleDescr.setLhs(new AndDescr());
EvalDescr evalDescr = new EvalDescr();
ruleDescr.getLhs().addDescr(evalDescr);
PackageDescr pkgDescr = new PackageDescr("org.pkg1");
pkgDescr.addImport(new ImportDescr("java.util.HashMap"));
FunctionImportDescr functionImportDescr = new FunctionImportDescr();
functionImportDescr.setTarget("java.lang.System.currentTimeMillis");
pkgDescr.addFunctionImport(functionImportDescr);
pkgDescr.addRule(ruleDescr);
builder.addPackage(pkgDescr);
assertSame(ruleDescr, mockDialect2.getRuleDescr());
assertTrue(mockDialect2.getImport().contains("java.util.HashMap"));
assertTrue(mockDialect2.getStaticImport().contains("java.lang.System.currentTimeMillis"));
assertEquals("eval was built", evalDescr.getContent());
assertEquals("consequence was built", ruleDescr.getConsequence());
assertTrue(mockDialect2.isCompileAll());
assertNotNull(pkg.getRule("test rule"));
// make sure there were no other general errors.
assertFalse(builder.hasErrors());
}
use of org.drools.drl.ast.descr.AttributeDescr in project drools by kiegroup.
the class RuleParserTest method testCalendars.
@Test
public void testCalendars() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_calendars_attribute.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("calendars");
assertEquals("calendars", at.getName());
assertEquals("[ \"cal1\" ]", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
use of org.drools.drl.ast.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());
}
Aggregations