Question

We have a maven multi-module project with the following modules:

  • prj-srv
  • prj-client

The srv project contains EJBs. In prj-srv/src/test, we have @Alternative implementations of the EJBs, specified in the alternatives section of beans.xml. This works.

The project prj-client has prj-srv as a dependency. In addition, it has a dependency on prj-srv of type test-jar, scope test, so that it can use the alternative EJB implementations for tests. This works, too.

Now then: in prj-client/src/main/java, we have local implementations of the EJB interfaces (so that we can cache the data) annotated with our qualifier @Cacheable. What I would like to do, is setup the tests in prj-client/src/test/java so that they use my test implementations from prj-srv (the ones that aren't cacheable, but who cares since it's for testing).

I have tried:

  • Creating a class with producer methods (@Produces @Alternative @Cacheable) in prj-client/src/test/java, but I don't know how to configure beans.xml to set this up as the alternative

  • Creating classes in prj-srv/src/test/java that extend the test EJBs, annotated @Alternative @Cacheable, and put them in src/test/resources/META-INF/beans.xml in the alternatives section, but weld still injects the "real" @Cacheable beans from src/main/java.

Is there some problem mixing @Alternative with qualifiers? How can I get my tests to use alternate implementations of a qualified class?

Was it helpful?

Solution

Just found it: I had forgotten to mark the constructors of the @Cacheable implementations with @Inject. Apparently, even though it was marked as an alternative in beans.xml, since Weld didn't know how to initialize it, instead of throwing an error, it just silently decided to ignore the alternative...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top