0 Replies Latest reply on Oct 4, 2007 9:41 AM by julien1

    JBoss Unit integration with JBoss MC

      I have been able to prototype an integration of the current JBoss Unit + JBoss MC which makes trivial the parametrization of complex test cases that required services, here is just a simple example:

      @Test
      @Bootstrap("/mytest/jboss-beans.xml");
      public class MyTest
      {
      
       private String dataSourceName;
       private DataSource dataSource;
      
       public String getDataSourceName()
       {
       return dataSourceName;
       }
      
       @Parameter
       public void setDataSourceName(String dataSourceName)
       {
       this.dataSourceName = dataSourceName;
       }
      
       @Inject(bean="DataSource")
       public void setDataSource(DataSource dataSource)
       {
       this.dataSource = dataSource;
       }
      
       @Test
       public void test()
       {
       // use data source here
       }
      }
      


      so we annotate the test case to be a parameterized test case with the dataSourceName parameter and to refer to an MC bean deployment + the injection of one of those beans in the test case.

      jboss-beans.xml looks like:

      <deployment>
      
       <bean name="DataSource" class="javax.sql.DataSource">
       <constructor>
       <factory name="some factory">
       <parameter><inject bean="TestCase" property="dataSourceName" state="Instantiated"/></parameter>
       </factory>
       </constructor>
       </bean>
      
      </deployment>
      


      here we define some factory for a data source object we need and we configure it to use the "implicit" TestCase bean, making usage of one of its parameterized properties.