3 Replies Latest reply on Aug 17, 2007 10:38 AM by larshuber

    EntityController not testable?


      It seems that testing of classes derived from EntityController is impossible if a logger or faces messages are in use.

      Good news: EntityController has method setEntityManager

      Bad news: similar methods for logger and faces messages are missing.

      For example calling this.addFacesMessage("some text") throws the following:

      java.lang.IllegalStateException: No active conversation context
       at org.jboss.seam.core.FacesMessages.instance(FacesMessages.java:417)
       at org.jboss.seam.framework.Controller.getFacesMessages(Controller.java:76)
       at org.jboss.seam.framework.Controller.addFacesMessage(Controller.java:98)

      For example calling this.info("some text") throws the following:

       at org.jboss.seam.framework.Controller.info(Controller.java:213)

      Is there any solution or workaround?

      I'm using Seam 1.2.1 GA

        • 1. Re: EntityController not testable?

          Run it inside a SeamTest.

          • 2. Re: EntityController not testable?


            "christian.bauer@jboss.com" wrote:
            Run it inside a SeamTest.

            Does your answer mean that EntityController subclasses can be tested in an integration test, but not in a unit test if they rely on a logger or faces messages?

            public class MyEntityControllerTest extends SeamTest
             public void testEntityController()
             new FacesRequest()
             protected void invokeApplication()
             assert invokeMethod("#{myEntityController.save}").equals("OK");
             } catch (Exception e)

            • 3. Re: EntityController not testable?

              For unit testing you can user field setting. I tried it with the logger, but not with faces messages.

              setField(obj, "log", org.jboss.seam.log.Logging.getLog(obj.getClass().getName()));

              obj is an instance of EntityController subclass.