4 Replies Latest reply on Sep 29, 2011 10:33 AM by iapazmino

    Exceptions are being wrapped

    iapazmino

      Hello,

       

      I've a class which throws and exception and in it's client is catching. That's production code.

      When test is run with arquillian (1.0.0.Alpha5) the catch method in the client class is not being run and the exception is thrown again as a javax.ejb.EJBTransactionRolledbackException

       

      Is there anything is should consider to avoid this behavior?

       

      Thanks in advance.

        • 1. Re: Exceptions are being wrapped
          aslak

          Could you provide a simple example ? EJBs + testclass

          • 2. Re: Exceptions are being wrapped
            iapazmino

            Hello Aslak, thank you for your reply. The following is a simple code which depicts the case.

             

            I've got an eao which looks for something and throws an exception if its not found.

             

            public class EmployeeEAO {

                ...

                public Employee searchById(Long id) throws EntidadNoExisteException {

                    ...

                    try {

                         return em.createQuery(query).getSingleResult();

                    }  catch (NoResultException e) {

                        throw new EntidadNoExisteException("No existe un empleado con el id [" + id + "]");

                    }

                }

            }

             

            The exception is just in order to translate actually...

             

            public class EntidadNoExisteException extends RuntimeException {

                ...

            }

             

            The client when invokes this method catches the exception and manage it

             

            public class ClientClass  {

                ...

                @EJB

                private EmployeeEAO emp;

                private PersonEAO per;

                ...

                public Person getThisPerson(Long id) throws EntidadNoExisteException {

                    Person person = null;

                    try {

                        person = emp.searchById(id);

                    } catch (EntidadNoExisteException e) {

                        // This block is never reached

                        person = per.searchById(id); // This invocation might throw EntidadNoExisteException too

                    }

                    return person;

                }

            }

             

            After the test is run the error line reads

             

            Time elapsed: 0.391 sec  <<< ERROR!

            javax.ejb.EJBTransactionRolledbackException: No existe un empleado con el id [0234154789001]

             

            I also put some logging in my disbelieve which confirmed it never reaches the catch block.

             

            The test is really simple, it just invokes the client method in the test case and that's it.

            • 3. Re: Exceptions are being wrapped
              aslak

              Your injecting ClientClass in your TestClass, and it's the Exception between ClientClass and EmployeeDAO that does not work..?

              • 4. Re: Exceptions are being wrapped
                iapazmino

                Yes, the TestClass has an injected reference to the ClientClass, but the block not being executed is the catch inside ClientClass.getThisPerson. It never reaches that block and the exception is wrapped inside the EJBTransactionRolledbackException