|
Mantis - Resin
|
|||||
| Viewing Issue Advanced Details | |||||
|
|
|||||
| ID: | Category: | Severity: | Reproducibility: | Date Submitted: | Last Update: |
| 4501 | minor | always | 04-13-11 12:03 | 04-26-11 17:48 | |
|
|
|||||
| Reporter: | reza | Platform: | |||
| Assigned To: | ferg | OS: | |||
| Priority: | normal | OS Version: | |||
| Status: | closed | Product Version: | 4.0.17 | ||
| Product Build: | Resolution: | fixed | |||
| Projection: | none | ||||
| ETA: | none | Fixed in Version: | 4.0.18 | ||
|
|
|||||
| 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. |
||||
| Steps To Reproduce: | |||||
| Additional Information: | |||||
| Relationships | |||||
| Attached Files: | |||||
| Notes | |||||
|
|
|||||
|
|
||||