Weld and test-jar

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?

Answers


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...


Need Your Help

IE9 Scrolling bug (border line repeated on screen)

html css internet-explorer-9 dhtml

I'm doing a DHTML popup where there is a UL with left floated LI's, that show a list of embroidery designs. In ie9 (does not effect <=IE8) when you scroll down in the UL all of these lines start

WideCharToMultiByte doesn't work in Wine

c++ c++11 winapi wine

I'm trying to use WideCharToMultiByte in order to convert std::wstring to utf8 std::string. Here is my code: