2 Replies Latest reply on Sep 19, 2011 10:44 AM by tobias81

    SessionContext.getInvokedBusinessInterface() returns unexpected class

    tobias81

      Hi,

       

      I have a very simple EJB which is accessible by a local interface as well as a no-interface view.

       

      public interface SimpleService {

        Class invoker();

      }

       

      @Stateless

      @LocalBean

      @Local(SimpleService.class)

      public class SimpleServiceEJB implements SimpleService {

       

         @Resource

         private SessionContext sessionContext;

       

         @Override

         public Class invoker() {

           Class result = sessionContext.getInvokedBusinessInterface();

           return result;

         }

      }

       

       

      The EJB contains only one simple method which returns the result of SessionContext.getInvokedBusinessInterface(). The JSR 318 specification defines: “The getInvokedBusinessInterface method returns the session bean business interface or no-interface view(bean class) type through which the bean was invoked.”

       

      So I write a simple Arquillian based unit test and invoke the EJB by its local interface and by its no-interface view.

       

      @RunWith(Arquillian.class)

      public class SimpleServiceTest {

       

         @Inject

         private SimpleService simpleService;

       

         @Inject

         private SimpleServiceEJB simpleServiceEJB;

       

       

        @Deployment

        public static Archive<?> createTestArchive() {

          return ShrinkWrap.create(WebArchive.class, "test.war").addClasses(SimpleService.class, SimpleServiceEJB.class)

             .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

        }

       

        @Test

        public void testInvoker() {

          assertEquals(SimpleServiceEJB.class, simpleServiceEJB.invoker());

          assertEquals(SimpleService.class, simpleService.invoker());

        }

      }

       

       

      I deploy and run this on JBoss 7.0.1.Final and the getInvokedBusinessInterface always returns the SimpleServiceEJB.class, also when I invoke the EJB by its local interface. So the second assertEquals() in my unit test fails because of an expected SimpleService class it but was SimpleServiceEJB.

       

      Cheers,

      Tobias

       

       

       

      My system setup:

      Ubuntu 11.04 (x86_64)

      Java(TM) SE Runtime Environment (build 1.7.0-b147)

      JBoss AS 7.0.1.Final