Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] 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 Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 4.0.18 Product Version 4.0.17
  Product Build
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
Attached Files

- Relationships

- Notes
(0005208)
ferg
04-26-11 17:48

ioc/5012, ioc/5013
 

- Issue History
Date Modified Username Field Change
04-13-11 12:03 reza New Issue
04-26-11 17:48 ferg Note Added: 0005208
04-26-11 17:48 ferg Assigned To  => ferg
04-26-11 17:48 ferg Status new => closed
04-26-11 17:48 ferg Resolution open => fixed
04-26-11 17:48 ferg Fixed in Version  => 4.0.18


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker