-
Notifications
You must be signed in to change notification settings - Fork 31
Description
I understand the need to have a standalone Weld container when doing unit tests, as weld-testing provides. But if you run integration tests for -say- a stateless EJB, you still have a junit test, but the test executes inside the JakartaEE container. Not all stateless services have a REST API. In that case you want the CDI of the container injecting things into the tests, so basically weld-junit5 without the weld-se context, but with wildfly's weld context.
I have been able to get a one level injection going, so an @Inject in a junit test is resolved. But the injected class does not have its @Inject resolved, those references are all null. I cannot seem to figure out how to make inject recursive.
This is a bit out of scope, but I dare to ask: any suggestions? 😄
BTW, this code does a one level deep injection:
BeanManager beanManager = CDI.current().getBeanManager();
CreationalContext<Object> ctx = beanManager.createCreationalContext(null);
InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) beanManager
.getInjectionTargetFactory(beanManager.createAnnotatedType(test.getClass()))
.createInjectionTarget(null);
injectionTarget.inject(test, ctx);I have to admit that why this works is not obvious to me. For example InjectionTarget? It is injecting, so hardly a target of injection. Injector seems a more logical name. Alas.