Semantic Module Testing

Drools has a test suite to ensure SMF compatibility with each semantic implementation; this is located in the compile time dependency module drools-smftest. This class acts as as a base class which each semantic module must extend. The Semantic module needs to do nothing other than override the setup method to specify the semantic type, which is uses to get the SemanticModule URL:

public class JavaSemanticTest extends SMFTestFrameWork
{
    public JavaSemanticTest( String name )
    {
        super( name );
    }

    public void setUp( ) throws Exception
    {
        Importer importer = new DefaultImporter( );
        importer.addImport( new BaseImportEntry( "java.math.*" ) );
        importer.addImport( new BaseImportEntry( "org.drools.smf.SMFTestFrameWork" ) );
        super.setUp( "java",
                     importer );
    }
}

Each semantic module that extends SMFTestFrameWork must create two data files and place them in the classpath as a resource:

  • conditions.data
  • consequences.data

A List of the tests is extracted from each file using the delimiter <!--drools-test--!>.

The SMFTestFramework then uses these known tests to confirm compliance. Some of the things that it tests for are:

  • Blocks and expressions are correctly parsed and compiled.
  • Required declarations are made available and their types imported.
  • Application Data is correctly bound to the given variable name and works in conditions, extractors and consequences with the correct types imported.

Example condition tests:

stilton.getBitesLeft() != camembert.getBitesLeft()
<!--drools-test--!> 
stilton.getBitesLeft() == bites.intValue()
<!--drools-test--!>
stilton.equals(favouriteCheese)

Example consequence tests:

int i = 0;
i++;
<!--drools-test--!>
SMFTestFrameWork.Cheese brie = new SMFTestFrameWork.Cheese("brie");
drools.assertObject(brie);
<!--drools-test--!>
camembert.eatCheese();
SMFTestFrameWork.Cheese brie = new SMFTestFrameWork.Cheese("brie");
drools.assertObject(brie);
brie.eatCheese();
drools.modifyObject(brie);
stilton.eatCheese();
stilton.eatCheese();

Labels

 
(None)