| HI, I am currently upgrading multiple libraries from JEE 6 standard to JEE 7 standard. This includes upgrading CDI 1.0 to CDI 1.1. The weld version I am using is the one that comes bundled in weblogic 12.2.1.2, this means 2.3.2.Final. For some integration tests, that use weld-se-core container, we need to disable producers that would work in the container under normal circumstances. Because they depend on contianer resources, such as the JNDI environment. While investigating some tests that fail, I have noticed that the @Priority annotation is not effective when bundled inside of a stereotype. Productive code pattern pulic class BusinessLogic { @Inject @WhateverFolderQualifier String whateverFolderPath; } The above business logic CDI bean would be injected the string through a producer that does a JNDI lookup. public class WhateverFolderPathProcuder{ @Produces @WhateverFolderQualifier public String whateverFolderPathProcuder(InjectionPoint ip) { return someJndiLookupThattWilFailOutsideOfTheCOntianer; } } h1. Integration tests want to override container behavior When we want to test the business logic component, we want that string field injected with some unit test mock string. So we want to get weld to ignore the default producer. So I would have somehting like a @Alternative @Prioiry(Test) public class WhateverFolderPathTestProcuder{ @Produces @WhateverFolderQualifier public String whateverFolderPathProcuder(InjectionPoint ip){ return someJndiLookupThattWilFailOutsideOfTheCOntianer; } } And in addition the beans.xml will have the <alternatives><class>WhateverFolderPathTestProcuder</class><alternatives> Declared. So if the code is written exactly as above. My produtive business logic gets injected with the Alternative without a problem. It is as if the producer for production environment is dead. Which is just as I want it to be. However, the original code used to make use of a "Test" steortype. So that @Alternative qualifier, would normally be called a: @TestAlternative. This @TestAlternative sterotype now was augmented to contain as well the @Priority annotation within it. In the hope that this steortype can both: (a) flag an alternative as being a test alternative which can be quickly identified by doing a source code search (b) made the test alternative globaly available. The behavior of weld when the @Priority annotation is in the TestAlternative sterotype is exactly as if it were not there. That means, my TestProducer will be used to inject the String into src/test/java that want the string. But the code in src/main/java cotinues using the real producer for the CDI container. As a work-around, I countinue using the steotype to get the @Alternative annotation into the test producer. And I duplicate the @Prioity annotation in the stereotype directly into the test producer, to make sure that the priority annotation is effective. This is of course a bug of minimal priority. There is a work around for this. Many thanks for taking a look. Kind regards. |