1 Reply Latest reply on Feb 21, 2011 11:19 AM by Aslak Knutsen

    Problem with @EJB in a TestCase that extends abstract class

    dashy Newbie

      Hi,

       

      i started building some TestClasses that all share some code, like the @Deployment,...

      My Problem now is that when the TestCase is started all Beans annotated with @EJB are null.

       

      Arquillian Version 1.0.0 Alpha4 with openejb 3.1

       

      Here is the Code:

       

      @RunWith(Arquillian.class)

      public abstract class AbstractTestContext

      {

           @EJB
           protected BeanOne beanOne;

          

           @EJB

           protected BeanTwo beanTwo;

       

           @Deployment
           public static JavaArchive getContextDeployment()
           {
                return ShrinkWrap.create(JavaArchive.class, "test.jar")
                     .addPackages(true, RootClass.class.getPackage())
                     .addManifestResource("persistence.xml");
           }
      }

       

      public class MyTest extends AbstractTestContext
      {
           @Test
           public void testBeanOne()
           {
                Assert.assertNotNull(beanOne);
           }

          

           @Test
           public void testBeanOne()
           {
                Assert.assertNotNull(beanOne);
           }
      }

       

      After searching the Arquillian code i found the code for my problem in the Class:

       

      org.jboss.arquillian.testenricher.ejb.SecurityActions

       

      static List<Field> getFieldsWithAnnotation(final Class<?> source, final Class<? extends Annotation> annotationClass)

      {

           List<Field> declaredAccessableFields = AccessController.doPrivileged(new PrivilegedAction<List<Field>>()

           {

                public List<Field> run()

                {

                     List<Field> foundFields = new ArrayList<Field>();

                     for(Field field : source.getDeclaredFields()) //<--------- there it is, it just ge the fields in upper class

                     {

                          if(field.isAnnotationPresent(annotationClass))

                          {

                               if(!field.isAccessible())

                               {

                                    field.setAccessible(true);

                               }

                               foundFields.add(field);

                          }

                     }

                     return foundFields;

                }

           });

           return declaredAccessableFields;

      }

       

      Is there a reason for that or is this a bug ?

       

      thx,

      Leopold Odenthal