3 Replies Latest reply on Jan 22, 2012 6:31 PM by Aslak Knutsen

    Injection of @PersistenceContext in CDI/Weld-Container

    Gunnar Hilling Newbie



      I think this has been asked previously but the documentation seems not to be completely up-to-date and arquillian seems to evolve quite fast ...

      So maybe in the meantime I can get the following scenario to work:


      I want to test my CDI-Beans including JPA-Entities with arquillian. To have my unit-tests running fast I'd like to use the weld-ee-container (

      arquillian-weld-ee-embedded-1.1). With JBoss-7-remote everything works fine.


      Is this possible now and how do I have to setup my test container? The @PersistenceContext-Annotation will just be ignored. No error but also no EntityManager.


      Kind Regards,




      Bean Code:


      public class MathProvider {


                PowerProvider power;



                EntityManager entityManager;


        public double power(double d, double e) {

                          Person person = new Person();




                          return power.power(d,e);




      Test Code:



      public class MathTest extends EntityEnabledTest {

        private static final double TINY_DELTA = 10E-10;



                private MathProvider math;



                public static Archive<?> createTestArchive()


                          return ShrinkWrap.create(JavaArchive.class, "test.jar")

                                              .addClasses(MathProvider.class, PowerProvider.class)

                                              .addAsManifestResource(new ByteArrayAsset("<beans/>".getBytes()),


                                              .addAsManifestResource("META-INF/persistence.xml", "META-INF/persistence.xml");





                public void testPower() {

                          assertEquals(27.0, math.power(3.0, 3.0), TINY_DELTA);

                          List<Person> result = proxyEntityManager.createQuery("select p from person p").getResultList();

                          assertEquals(1, result.size());

                          assertEquals("Gunnar", result.get(0).getName());