[jboss-dev-forums] [QA of JBoss Portal] - JBoss Unit integration with JBoss MC

julien@jboss.com do-not-reply at jboss.com
Thu Oct 4 09:41:59 EDT 2007


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.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4091518#4091518

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4091518



More information about the jboss-dev-forums mailing list