use of org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration in project drools by kiegroup.
the class PackageBuilderConfigurationTest method testProgramaticProperties2.
@Test
public void testProgramaticProperties2() {
JavaDialectConfiguration javaConf = new JavaDialectConfiguration();
javaConf.init(new KnowledgeBuilderConfigurationImpl());
javaConf.setCompiler(JavaDialectConfiguration.CompilerType.ECLIPSE);
KnowledgeBuilderConfigurationImpl cfg = new KnowledgeBuilderConfigurationImpl();
cfg.setDialectConfiguration("java", javaConf);
JavaDialectConfiguration javaConf2 = (JavaDialectConfiguration) cfg.getDialectConfiguration("java");
assertSame(javaConf, javaConf2);
assertEquals(JavaDialectConfiguration.CompilerType.ECLIPSE, javaConf2.getCompiler());
javaConf = new JavaDialectConfiguration();
javaConf.init(new KnowledgeBuilderConfigurationImpl());
javaConf.setCompiler(JavaDialectConfiguration.CompilerType.JANINO);
cfg = new KnowledgeBuilderConfigurationImpl();
cfg.setDialectConfiguration("java", javaConf);
javaConf2 = (JavaDialectConfiguration) cfg.getDialectConfiguration("java");
assertSame(javaConf, javaConf2);
assertEquals(JavaDialectConfiguration.CompilerType.JANINO, javaConf2.getCompiler());
}
use of org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration in project drools by kiegroup.
the class ParserTest method testErrorLineNumbers.
@Test
public void testErrorLineNumbers() throws Exception {
// this test aims to test semantic errors
// parser errors are another test case
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("errors_in_rule.drl", getClass()), ResourceType.DRL);
final KnowledgeBuilderError[] errors = kbuilder.getErrors().toArray(new KnowledgeBuilderError[0]);
assertEquals(3, errors.length);
final DescrBuildError stiltonError = (DescrBuildError) errors[0];
assertTrue(stiltonError.getMessage().contains("Stilton"));
assertNotNull(stiltonError.getDescr());
assertTrue(stiltonError.getLine() != -1);
// check that its getting it from the ruleDescr
assertEquals(stiltonError.getLine(), stiltonError.getDescr().getLine());
// check the absolute error line number (there are more).
assertEquals(26, stiltonError.getLine());
final DescrBuildError poisonError = (DescrBuildError) errors[1];
assertTrue(poisonError.getMessage().contains("Poison"));
assertEquals(28, poisonError.getLine());
final KnowledgeBuilderConfigurationImpl cfg = new KnowledgeBuilderConfigurationImpl();
final JavaDialectConfiguration javaConf = (JavaDialectConfiguration) cfg.getDialectConfiguration("java");
switch(javaConf.getCompiler()) {
case NATIVE:
assertTrue(errors[2].getMessage().contains("illegal"));
break;
case ECLIPSE:
assertTrue(errors[2].getMessage().contains("add"));
break;
case JANINO:
assertTrue(errors[2].getMessage().contains("Unexpected"));
break;
default:
fail("Unknown compiler used");
}
// now check the RHS, not being too specific yet, as long as it has the
// rules line number, not zero
final DescrBuildError rhsError = (DescrBuildError) errors[2];
assertTrue(rhsError.getLine() >= 23 && rhsError.getLine() <= 32);
}
Aggregations