4 Replies Latest reply on Mar 23, 2014 8:22 AM by Daniel Tschan

    Enhancement: CDI in SwitchYard Unit Tests

    Daniel Tschan Newbie

      Hi

       

      When using the CDIMixIn in a SwitchYard unit test I expected to be able to use CDI within the unit test too, e.g. to inject a test error listener and run assertions on the exceptions it caught. But this is not the case because the CDIMixIn initializes and starts the CDI container after the unit test is instantiated, i.e. unit test instances are not managed by CDI and CDI annotations therefore not processed.

      However one can ask the CDI container to inject CDI beans into unmanaged objects and run their lifecycle callbacks as described here: http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html#d0e4972 . I extended the CDIMixIn accordingly: https://github.com/dtschan/components/commit/cbeac65360117b69fee9d97c223729c45035e286 .

       

      With this enhancement any CDI bean can be injected into a SwitchYard unit test. With the help of a JpaInjectionServices and ResourceInjectionServices Implementation injection of EntityManager, EntityManagerFactory and UserTransaction objects are also possible. Please tell me what you think about the enhancement. If nothing speaks against it I'll open a Jira Issue with pull request.

       

      Kind regards

        Daniel