7 Replies Latest reply on Jul 18, 2011 12:09 PM by m1ckey

    Can Arquillian inject my @PersistenceContext?

    m1ckey

      Hi guys, this is a possible feature request.

       

      I would like Arquillian to inject my @PersistenceContext. Example:

       

       

      @RunWith(Arquillian.class)
      public class SongDaoImplIT {
      
          @Inject
          private SongDaoImpl songDaoImpl;
      
          @Deployment
          public static Archive<?> createTestArchive()
                  throws IllegalArgumentException, IOException {
              return ShrinkWrap
                      .create(SongDaoImplIT.class.getSimpleName() + ".jar",
                              JavaArchive.class)
                      .addManifestResource(
                              new File("src/test/resources/META-INF/persistence.xml"),
                              ArchivePaths.create("persistence.xml"))
                      .addClasses(Artist.class, NullEntitiesFactory.class,
                              SongDaoImpl.class);
          }
      
          @Test
          public void testCanPersistUserObject() {
              EntityManagerFactory emf = Persistence
                      .createEntityManagerFactory("testPu");
              EntityManager em = emf.createEntityManager();
              assertNotNull(songDaoImpl.getArtist("Dio"));
          }
      

       

      And the DAO:

       

      @ApplicationScoped
      public class SongDaoImpl implements SongDao {
      
          @PersistenceContext
          private EntityManager entityManager;
      

       

      What I would like Arquillian to call and inject is this:

       

      EntityManagerFactory emf = Persistence
                      .createEntityManagerFactory("testPu");
      EntityManager em = emf.createEntityManager();
      

       

      Perhaps I could specify the persistence unit name in my @Deployment method...

       

      Thoughts?