Search in sources :

Example 6 with JavaDialectConfiguration

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());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) JavaDialectConfiguration(org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration) Test(org.junit.Test)

Example 7 with JavaDialectConfiguration

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);
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) JavaDialectConfiguration(org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration) Test(org.junit.Test)

Aggregations

JavaDialectConfiguration (org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration)7 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)5 Test (org.junit.Test)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EclipseJavaCompiler (org.drools.compiler.commons.jci.compilers.EclipseJavaCompiler)1 JaninoJavaCompiler (org.drools.compiler.commons.jci.compilers.JaninoJavaCompiler)1 JavaCompiler (org.drools.compiler.commons.jci.compilers.JavaCompiler)1 NativeJavaCompiler (org.drools.compiler.commons.jci.compilers.NativeJavaCompiler)1 DiskResourceReader (org.drools.compiler.commons.jci.readers.DiskResourceReader)1 ResourceReader (org.drools.compiler.commons.jci.readers.ResourceReader)1 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 Dialect (org.drools.compiler.compiler.Dialect)1 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)1 PMMLCompiler (org.drools.compiler.compiler.PMMLCompiler)1 PMMLResource (org.drools.compiler.compiler.PMMLResource)1