0 Replies Latest reply on Nov 26, 2013 1:46 AM by arko maity

    Arquillian persistance -Entitymanager null

    arko maity Newbie

      Hi i am new to Arquillian .I want to test some business logic in my program but entity manager is null.I am running the test in standalone mode.I am using jboss 7.1

       

      My persistance.xml  is as follows:-

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

          version="2.0">

          

          <persistence-unit name="abcd">

       

       

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

              <jta-data-source>java:jboss/datasources/ORACLEDS</jta-data-source>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />

       

                  <property name="hibernate.format_sql" value="true" />

                  <property name="hibernate.max_fetch_depth" value="3" />

                  <property name="hibernate.default_schema" value="COPY" />

                  <property name="hibernate.jdbc.batch_size" value="650" />

                  <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />

                  <property name="hibernate.connection.url"

                      value="....." />

                  <property name="hibernate.connection.username" value="abcd" />

                  <property name="hibernate.connection.password" value="123" />

                            

              </properties>

          </persistence-unit>

       

      </persistence>

      My testing class:-

       

      @RunWith(Arquillian.class)

      public class BusinessDefTest {      

       

          @Deployment

          public static JavaArchive createDeployment() {

          

                    

                      return ShrinkWrap.create(JavaArchive.class)                      

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

                              .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")

                              .addPackages(false,getCorePackages());              

                 

          }

        

          public static Package[] getCorePackages() {

              return new Package[]{......

                    

              };

          }

       

          @PersistenceContext(unitName="abcd")

          @Produces

          @Default

          EntityManager em;

       

                   

          @Before

          public void preparePersistenceTest() throws Exception {

                     startTransaction();

          }

        

      @Inject

          UserTransaction utx;

       

          private void startTransaction() throws Exception {

              utx.begin();

         

          }

        

          @Test

          public void IsEmpty() {

            

             System.out.println("Entity Manager :"+em);

          

                      try {

                

                  assertNotNull(em);

                

                       } catch (Exception e) {

              

                  e.printStackTrace();

              }

          }

        

          @After

          public void commitTransaction() throws Exception {

              utx.commit();

          }

      }