有人用过“PowerMock + Drools + JBoss”的组合吗?
当我运行尝试在 JUnit 测试(JUnit 4.10)中使用单元测试 drools 规则时,我加载了 drl 规则知识 kobtext:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("com/mycompany/myproject/rooles.drl"), ResourceType.DRL);
它工作正常。org.drools.io.impl.ClassPathResource 包含 3 个类加载器:
- java.net.FactoryURLClassLoader
- org.jboss.mx.loading.UnifiedClassLoader
- sun.misc.Launcher
但是当我添加
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
到单元测试 org.drools.io.impl.ClassPathResource 包含 2 个类加载器:
- org.powermock.core.classloader.MockClassLoader
- sun.misc.Launcher
并且测试因 java.io.FileNotFoundException 而失败:
java.lang.RuntimeException: java.io.FileNotFoundException: 'com/mycompany/myproject/rooles.drl' cannot be opened because it does not exist
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:638)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
...
Caused by: java.io.FileNotFoundException: 'com/wiley/cms/jqa/service/lifecycle/lifecycle.drl' cannot be opened because it does not exist
at org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:128)
at org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:109)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
...
谁能建议如何避免这个问题?