use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class DescrResourceSetTest method drlFilesTest.
@Test
public void drlFilesTest() throws Exception {
Set<File> drlFiles = getDrlFiles();
for (File drl : drlFiles) {
final DrlParser parser = new DrlParser(((KnowledgeBuilderConfigurationImpl) conf).getLanguageLevel());
InputStreamResource resource = new InputStreamResource(new FileInputStream(drl));
PackageDescr pkgDescr = parser.parse(resource);
if (parser.hasErrors()) {
continue;
}
visitor.visit(pkgDescr);
}
logger.debug(drlFiles.size() + " drl tested.");
}
use of org.drools.drl.ast.descr.PackageDescr 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.PackageDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method createLiteralRule.
private void createLiteralRule(final BaseDescr descr) {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr = new PackageDescr("p1");
final RuleDescr ruleDescr = new RuleDescr("rule-1");
packageDescr.addRule(ruleDescr);
final AndDescr lhs = new AndDescr();
ruleDescr.setLhs(lhs);
final PatternDescr pattern = new PatternDescr(Primitives.class.getName());
lhs.addDescr(pattern);
pattern.addConstraint(descr);
ruleDescr.setConsequence("");
builder.addPackage(packageDescr);
assertLength(0, builder.getErrors().getErrors());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method testWarnings.
@Test
public void testWarnings() {
System.setProperty("drools.kbuilder.severity." + DuplicateRule.KEY, "WARNING");
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr1 = createBasicPackageWithOneRule(11, 1);
final PackageDescr packageDescr2 = createBasicPackageWithOneRule(22, 2);
builder.addPackage(packageDescr1);
builder.addPackage(packageDescr2);
assertFalse(builder.hasErrors());
assertTrue(builder.hasWarnings());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method testResetWarningsButNotErrors.
@Test
public void testResetWarningsButNotErrors() throws DroolsParserException, IOException {
System.setProperty("drools.kbuilder.severity." + DuplicateRule.KEY, "WARNING");
System.setProperty("drools.kbuilder.severity." + DuplicateFunction.KEY, "ERROR");
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr1 = createBasicPackageWithOneRule(11, 1);
final PackageDescr packageDescr2 = createBasicPackageWithOneRule(22, 2);
builder.addPackage(packageDescr1);
builder.addPackage(packageDescr2);
builder.addPackageFromDrl(new StringReader("package foo \n rule ORB"));
builder.addPackageFromDrl(new StringReader("package org.drools\n" + "function boolean testIt() {\n" + " return true;\n" + "}\n"));
builder.addPackageFromDrl(new StringReader("package org.drools\n" + "function boolean testIt() {\n" + " return false;\n" + "}\n"));
assertTrue(builder.hasWarnings());
assertTrue(builder.hasErrors());
builder.resetWarnings();
assertFalse(builder.hasWarnings());
assertTrue(builder.hasErrors());
}
Aggregations