users@glassfish.java.net

Re: Obtain embedded EJB container EntityManager in TestNG test

From: <glassfish_at_javadesktop.org>
Date: Sat, 27 Feb 2010 06:42:40 PST

Maybe this is an option; include an EJB in your test package (then you will also need an ejb-jar.xml in your test JAR). The EJB is managed by the embedded container and an entity manager can be injected into it. You can then test the results inside the EJB. Look up this EJB as you do with the others. To get the entity manager you need a helper function, or provide it as parameter to your code.

@Stateless
public class TestEJB {
@PersistenceContext
EntityManager em;

public Object verifyTest(VerifyTestUnit vtu) {
   return vtu.run(em);
}

public interface VerifyTestUnit<V> {
  V run(EntityManager em);
}

}

Implement the interface VerifyTestUnit and call the EJB which will execute your code.
[Message sent by forum member 'sisirhc' (chriswesdorp_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=389101