The bug is here:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=12446.
The use case is as follows: I start the embedded GF so that we can test our beans. For EJBs it is very simple - I look them up using the protable 'java:global' namespace, and it works. However, not all of our beans are actually EJBs - many of them are simpler, managed beans (CDI beans), that don't need the EJB services - transactions, security, pooling and so on. So, in the tests, we can look up EJB, but there is no way for us to look up the CDI beans.
I was hoping that if I get hold of BeanManager I will be able to use it to get references to CDI beans. Also, I created a simple class that performs injection on a given object (which is an uninjected CDI bean, possibly created not by CDI, but someone else) using a BeanManager. We are using it for our simple tests with TestNG - our tests are actually CDI beans according to the specs, and they use @Inject and other goodies. However, they are not created by CDI, but by TestNG, so we use a @BeforeClass method to perform injection on the test instance using the BeanManager. It all works very nice with Weld SE, and I was hoping to have the same for tests that include GF embedded.
I found a workaround for this, but it fails in two ways. For one, see
https://glassfish.dev.java.net/issues/show_bug.cgi?id=12489; for the other, there is no bug or post yet, but once I finally get the BeanManager and try to perform injection on the test instance, I get some "Java EE environment not available" or similar. I am not sure what causes that, as I don't get it using Weld SE (as mentioned earlier), and it's the same BeanManagerImpl that comes from Weld that is used. Maybe the one that I look up is a child BeanManager that has some different settings, I haven't found out yet.
Another workaround for the "Java EE environment not available" and not being able to perform injection could be to create an EJB that has the stuff injected into, and provide getters for the beans. This could work, but requires a lot of dummy EJBs / getter methods, and (read below)...
I don't think it is critical to get BeanManager and have CDI beans injected, as we can performs tests on them using Weld SE, and we can use GF embedded only for real fully-fledged EJB tests. However, the behaviour is a little inconsistent (as mentioned in the bug and the post, UserTransaction is available) and maybe someone wanted to look into this.
[Message sent by forum member 'szczyp']
http://forums.java.net/jive/thread.jspa?messageID=476845