Search in sources :

Example 21 with EvalCondition

use of org.drools.core.rule.EvalCondition in project drools by kiegroup.

the class PackageCompilationDataTest method testCodeSourceUrl.

@Test
public void testCodeSourceUrl() throws Exception {
    final String className = TestEvalExpression.class.getName();
    KnowledgeBaseImpl kBase = new KnowledgeBaseImpl("xxx", null);
    InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.drools");
    pkg.setClassLoader(Thread.currentThread().getContextClassLoader());
    JavaDialectRuntimeData data = new JavaDialectRuntimeData();
    data.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
    pkg.getDialectRuntimeRegistry().setDialectData("java", data);
    kBase.addPackage(pkg);
    final JavaDialectRuntimeData pcData = (JavaDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("java");
    final EvalCondition invoker = new EvalCondition(null);
    pcData.putInvoker(className, invoker);
    final InputStream is = getClass().getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class");
    try {
        pcData.write(className.replace('.', '/') + ".class", read(is));
    } finally {
        is.close();
    }
    pcData.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
    pcData.onBeforeExecute();
    Class cls = kBase.getRootClassLoader().loadClass("org.drools.mvel.rule.PackageCompilationDataTest$TestEvalExpression");
    final CodeSource codeSource = invoker.getEvalExpression().getClass().getProtectionDomain().getCodeSource();
    assertNotNull(codeSource.getLocation());
}
Also used : InputStream(java.io.InputStream) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) CodeSource(java.security.CodeSource) EvalCondition(org.drools.core.rule.EvalCondition) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Aggregations

EvalCondition (org.drools.core.rule.EvalCondition)21 Test (org.junit.Test)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 Declaration (org.drools.core.rule.Declaration)6 Pattern (org.drools.core.rule.Pattern)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)4 LeftTuple (org.drools.core.reteoo.LeftTuple)4 EvalDescr (org.drools.compiler.lang.descr.EvalDescr)3 EvalExpression (org.drools.core.spi.EvalExpression)3 EvalDescr (org.drools.drl.ast.descr.EvalDescr)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Cheese (org.drools.compiler.Cheese)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)2 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)2 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)2