Skip to content

Instantly share code, notes, and snippets.

@tsurdilo
Forked from pmuir/gist:579315
Created September 14, 2010 16:38
Show Gist options
  • Save tsurdilo/579321 to your computer and use it in GitHub Desktop.
Save tsurdilo/579321 to your computer and use it in GitHub Desktop.
@RunWith(Arquillian.class)
public class KSessionTest
{
@Deployment
public static JavaArchive createTestArchive()
{
String pkgPath = KSessionTest.class.getPackage().getName().replaceAll("\\.", "/");
JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class)
.addPackages(true, new DroolsModuleFilter("ksession"), KnowledgeBaseProducer.class.getPackage())
.addClass(KSessionTestRules.class)
.addClass(KSessionTestProducer.class)
.addResource(pkgPath + "/ksessiontest.drl", ArchivePaths.create("ksessiontest.drl"))
.addResource(pkgPath + "/kbuilderconfig.properties", ArchivePaths.create("kbuilderconfig.properties"))
.addResource(pkgPath + "/kbaseconfig.properties", ArchivePaths.create("kbaseconfig.properties"))
.addManifestResource(pkgPath + "/KSessionTest-beans.xml", ArchivePaths.create("beans.xml"))
.addManifestResource("META-INF/services/javax.enterprise.inject.spi.Extension", ArchivePaths.create("services/javax.enterprise.inject.spi.Extension"));
//System.out.println(archive.toString(Formatters.VERBOSE));
return archive;
}
@Test
public void testKSession(@DefaultConfig @Default StatefulKnowledgeSession ksession)
{
assertNotNull(ksession);
assertTrue(ksession.getId() >= 0);
}
}
@DroolsConfig(kbuilderConfigFile = "kbuilderconfig.properties",
kbaseConfigFile = "kbaseconfig.properties",
ruleResources = {
@RuleResource( location="classpath", path="kbasetest.drl", type="DRL", templateDataProvider="forkbasetest")
})
@Produces
@DefaultConfig
KnowledgeBaseProducer producer;
@Dependent
@Generic(DroolsConfig.class)
public class KnowledgeBaseProducer implements Serializable
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseProducer.class);
@Inject
BeanManager manager;
@Inject
ResourceProvider resourceProvider;
@Inject
DroolsExtension droolsExtension;
@Inject
DroolsConfig config;
@Inject
@GenericBean
DroolsConfigUtil configUtils;
@Produces
@ApplicationScoped
@Default
public KnowledgeBase produceKnowledgeBase() throws Exception
{...}
...}
@Dependent
@Generic(DroolsConfig.class)
public class KnowledgeSessionProducer implements Serializable
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeSessionProducer.class);
@Inject
BeanManager manager;
@Inject
DroolsExtension droolsExtension;
@Inject
ResourceProvider resourceProvider;
@Inject
SeamDelegate delegate;
@Inject
DroolsConfig config;
@Inject
DroolsConfigUtil configUtils;
@Inject
@GenericProduct
KnowledgeBase kbase;
@Inject
@Scanned
@GenericProduct
KnowledgeBase scannedKbase;
@Produces
@Default
@RequestScoped
public StatefulKnowledgeSession produceStatefulSession() throws Exception
{...}
...}
-------------------------------------------------------------------------------
Test set: org.jboss.seam.drools.test.ksession.KSessionTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.56 sec <<< FAILURE!
testKSession(org.jboss.seam.drools.test.ksession.KSessionTest) Time elapsed: 0.04 sec <<< ERROR!
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve managed beans for Types: [interface org.drools.KnowledgeBase]; Bindings: [@org.jboss.weld.extensions.util.Synthetic(index=0, namespace="org.jboss.weld.extensions.bean.generic.product")]
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:807)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:793)
at org.jboss.weld.extensions.bean.generic.GenericManagedBean.create(GenericManagedBean.java:54)
at org.jboss.weld.context.DependentContext.get(DependentContext.java:62)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:709)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:735)
at org.jboss.weld.extensions.bean.generic.AbstractGenericProducerBean.getReceiver(AbstractGenericProducerBean.java:65)
at org.jboss.weld.extensions.bean.generic.AbstractGenericProducerBean.create(AbstractGenericProducerBean.java:50)
at org.jboss.weld.extensions.bean.generic.GenericProducerMethod.create(GenericProducerMethod.java:15)
at org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:143)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:100)
at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
at org.drools.runtime.CommandExecutor_$$_javassist_11.toString(CommandExecutor_$$_javassist_11.java)
at java.lang.String.valueOf(String.java:2826)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at org.jboss.seam.drools.test.ksession.KSessionTest.testKSession(KSessionTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:233)
at org.jboss.arquillian.protocol.local.LocalMethodExecutor.invoke(LocalMethodExecutor.java:40)
at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:50)
at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:40)
at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:117)
at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:228)
at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:191)
at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:209)
at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:272)
at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:205)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:152)
"or
@tsurdilo
Copy link
Author

@dependent
@Generic(DroolsConfig.class)
public class KnowledgeBaseProducer implements Serializable
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseProducer.class);

@Inject
BeanManager manager;

@Inject
ResourceProvider resourceProvider;

@Inject
DroolsExtension droolsExtension;

@Inject
DroolsConfig config;

@Inject
@GenericBean
DroolsConfigUtil configUtils;

@produces
@ApplicationScoped
@default
public KnowledgeBase produceKnowledgeBase() throws Exception
{ ...}
...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment