Anonymous | Login | Signup for a new account | 12-17-2024 10:34 PST |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ View Advanced ] [ Issue History ] [ Print ] | ||||||||
ID | Category | Severity | Reproducibility | Date Submitted | Last Update | ||||
0004501 | [Resin] | minor | always | 04-13-11 12:03 | 04-26-11 17:48 | ||||
Reporter | reza | View Status | public | ||||||
Assigned To | ferg | ||||||||
Priority | normal | Resolution | fixed | ||||||
Status | closed | Product Version | 4.0.17 | ||||||
Summary | 0004501: Specifying @Alternatives in beans.xml overrides do not work | ||||||||
Description |
Specifying alternatives in beans.xml overrides do not work. For example, the following code will cause "hit()" instead of "mock-hit()" to be printed out: ================================================================================ package qa; public interface Test { public void hit(); } ================================================================================ ================================================================================ package qa; public class TestBean implements Test { public void hit() { System.out.println("hit()"); } } ================================================================================ ================================================================================ <beans xmlns="http://java.sun.com/xml/ns/javaee"> [^] <alternatives> <class>qa.MockTestBean</class> </alternatives> </beans> ================================================================================ ================================================================================ package qa; import javax.enterprise.inject.Alternative; @Alternative public class MockTestBean implements Test { public void hit() { System.out.println("mock-hit()"); } } ================================================================================ ================================================================================ package qa; import javax.inject.Inject; import org.junit.Test; import org.junit.runner.RunWith; import com.caucho.junit.ResinBeanConfiguration; import com.caucho.junit.ResinBeanContainerRunner; @RunWith(ResinBeanContainerRunner.class) @ResinBeanConfiguration(beansXml = { "classpath:META-INF/beans.xml" }) public class JUnitTest { @Inject private qa.Test bean; @Test public void test() { bean.hit(); } } ================================================================================ This definitely appears to be a timing issue in that the underlying CDI context gets processed/bootstrapped before the beans.xml overrides are processed. For example, the following will work because no XML override is specified although the exact same META-INF/beans.xml will be loaded (via the default bootstrap as opposed to an override): ================================================================================ package qa; import javax.inject.Inject; import org.junit.Test; import org.junit.runner.RunWith; import com.caucho.junit.ResinBeanContainerRunner; @RunWith(ResinBeanContainerRunner.class) public class JUnitTest { @Inject private qa.Test bean; @Test public void test() { bean.hit(); } } ================================================================================ This is a pretty big problem since most developers are likely to use alternatives for mock objects in unit tests used through XML overrides rather than in production using the default beans.xml. |
||||||||
Additional Information | |||||||||
Attached Files | |||||||||
|
Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed. 26 unique queries executed. |