-
1. Re: Can Arquillian inject my @PersistenceContext?
kpiwko Jul 7, 2011 8:27 AM (in response to m1ckey)Hi Michal,
have you tried the following? It does work for CDI, which is likely your environment (@ApplicationScoped, @Inject annotations)
@RunWith(Arquillian.class) public class AuctionManagerTest { @Deployment public static Archive<?> jar() { return ...; } @PersistenceContext(unitName = "jeelabPU") @Produces @Default EntityManager em; @EJB AuctionManager auctionManager; @Test public void retrieveAuctions() { // here it the auctionManager is using jeelabPU } }
See https://github.com/kpiwko/auction/blob/red-hat-dev-conf/src/test/java/org/jboss/lectures/auction/ejb/AuctionManagerTest.java for full example.
-
2. Re: Can Arquillian inject my @PersistenceContext?
m1ckey Jul 7, 2011 8:44 AM (in response to kpiwko)Hi Karel, thanks for your reply. I will try it when I get home, but:
- In the test method, am I using the em field directly?
- Does it have to be an EJB?
-
3. Re: Can Arquillian inject my @PersistenceContext?
kpiwko Jul 7, 2011 9:03 AM (in response to m1ckey)In the test method, am I using the em field directly?
No, this is not required. Your DAO will have correct EM injected.
Does it have to be an EJB?
I haven't tried it. That's up to you.
-
4. Re: Can Arquillian inject my @PersistenceContext?
aslak Jul 7, 2011 9:24 AM (in response to kpiwko)I think the missing piece of information in the original post is: Michal wants this in a pure CDI Container, e.g. Weld.
-
5. Re: Can Arquillian inject my @PersistenceContext?
m1ckey Jul 7, 2011 9:39 AM (in response to aslak)Yeah. Thanks Aslak.
-
6. Re: Can Arquillian inject my @PersistenceContext?
lexsoto Jul 15, 2011 10:50 AM (in response to m1ckey)Does it work for testing EJB3 also?
-
7. Re: Can Arquillian inject my @PersistenceContext?
m1ckey Jul 18, 2011 12:09 PM (in response to lexsoto)Hi Alex, at the moment nothing works. My changes are not committed yet. I would expect it to work for EJB as well.