4 Replies Latest reply on Nov 15, 2011 11:33 AM by tvibes

    EJB - Injection did not work with JavaArchive

    arakasi69

      Hello,

       

      my environment is jboss as 7.0.2 and arqullian 1.0.0.CR1.

       

      I've written a little test with some jpa entities and a session bean as a crud service. The test failed because the injected crud bean was null. I figured out, that the test is running if i create WebArchive.

       

       

      import java.util.HashSet;
      import java.util.Set;
      
      import javax.ejb.EJB;
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.shrinkwrap.api.Archive;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.JavaArchive;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Assert;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      @RunWith(Arquillian.class)
      public class PersistAccountTest {
          
      
          @EJB
          GenericCRUDControl<LocationEntity> locationCRUDControl;
          @EJB
          GenericCRUDControl<PersonEntity> personCRUDControl;
          
          @Deployment
          public static Archive<?> create(){
              
              return ShrinkWrap.create(JavaArchive.class, "server.ja").addClasses(PersonEntity.class,RoleEntity.class,RightEntity.class,LocationEntity.class,GenericCRUDControl.class).addAsManifestResource("persistence.xml", "persistence.xml");
          }
      
      
          @Test
          public void testCreatingSimpleAccount(){
              
              RoleEntity roleEntity  = new RoleEntity();
              roleEntity.setName("admin");
              PersonEntity personEntity = new PersonEntity();
              personEntity.setName("Thomas");
              personEntity.setRoleEntity(roleEntity);
              
              Set<RoleEntity> roles = new HashSet<RoleEntity>();
              roles.add(roleEntity);
              
              LocationEntity locationEntity = new LocationEntity();
              locationEntity.setInheritanceDepth(20);
              locationEntity.setName("Root");
              locationEntity.setRoles(roles);
              
              Assert.assertNotNull("The location crud control must not be null", locationCRUDControl);
              Assert.assertNotNull("The person crud control must not be null", personCRUDControl);
              
              locationCRUDControl.create(locationEntity);
              personCRUDControl.create(personEntity);
              
          }
      }
      

       

      I've run the test in managed container and aso in remote container. The remote container was started with the standalone configuration and also with the standalone-preview configuration.

       

      Has anybody a hint, how to get running the test in a java archive without failures ?

       

      Kind regards, Thomas