Description methodDescription = describeChild( method );
// Ok, ready to run the test
try
{
DirectoryService directoryService = null;
// Set the revision to 0, we will revert only if it's set to another value
long revision = 0L;
// Check if this method has a dedicated DSBuilder
DirectoryService methodDS = DSAnnotationProcessor.getDirectoryService( methodDescription );
// give #1 priority to method level DS if present
if ( methodDS != null )
{
// Apply all the LDIFs
DSAnnotationProcessor.applyLdifs( suiteDescription, methodDS );
DSAnnotationProcessor.applyLdifs( classDescription, methodDS );
DSAnnotationProcessor.applyLdifs( methodDescription, methodDS );
directoryService = methodDS;
}
// we don't support method level LdapServer so
// we check for the presence of Class level LdapServer first
else if ( classLdapServer != null )
{
directoryService = classLdapServer.getDirectoryService();
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
else if ( classKdcServer != null )
{
directoryService = classKdcServer.getDirectoryService();
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
else if ( classDS != null )
{
directoryService = classDS;
// apply the method LDIFs, and tag for reversion
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
else if ( suite != null )
{
directoryService = suite.getDirectoryService();
// apply the method LDIFs, and tag for reversion
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
// At this point, we know which service to use.
// Inject it into the class
Field dirServiceField = getTestClass().getJavaClass().getField( DIRECTORY_SERVICE_FIELD_NAME );
dirServiceField.set( getTestClass().getJavaClass(), directoryService );
// if we run this class in a suite, tell it to the test
Field runInSuiteField = getTestClass().getJavaClass().getField( IS_RUN_IN_SUITE_FIELD_NAME );
runInSuiteField.set( getTestClass().getJavaClass(), suite != null );
Field ldapServerField = getTestClass().getJavaClass().getField( LDAP_SERVER_FIELD_NAME );
dirServiceField.set( getTestClass().getJavaClass(), directoryService );
if ( classLdapServer != null )
{
// setting the directoryService is required to inject the correct level DS instance in the class or suite level LdapServer
classLdapServer.setDirectoryService( directoryService );
ldapServerField.set( getTestClass().getJavaClass(), classLdapServer );
}
else if ( classKdcServer != null )
{
// setting the directoryService is required to inject the correct level DS instance in the class or suite level KdcServer
classKdcServer.setDirectoryService( directoryService );
Field kdcServerField = getTestClass().getJavaClass().getField( KDC_SERVER_FIELD_NAME );
kdcServerField.set( getTestClass().getJavaClass(), classKdcServer );
}
// Run the test
super.runChild( method, notifier );
// Cleanup the methodDS if it has been created
if ( methodDS != null )
{
LOG.debug( "Shuting down DS for {}", methodDS.getInstanceId() );
methodDS.shutdown();
FileUtils.deleteDirectory( methodDS.getWorkingDirectory() );
}
else
{
// We use a class or suite DS, just revert the current test's modifications
revert( directoryService, revision );