in deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java [637:721]
private void startScopes(CdiContainer container,
Class testClass,
Method testMethod,
Class<? extends Annotation>... restrictedScopes)
{
try
{
automaticScopeHandlingActive.set(TRUE);
ContextControl contextControl = container.getContextControl();
List<Class<? extends Annotation>> scopeClasses = new ArrayList<Class<? extends Annotation>>();
Collections.addAll(scopeClasses, this.testControl.startScopes());
if (scopeClasses.isEmpty())
{
addScopesForDefaultBehavior(scopeClasses);
}
else
{
List<TestControlValidator> testControlValidatorList =
ServiceUtils.loadServiceImplementations(TestControlValidator.class);
for (TestControlValidator testControlValidator : testControlValidatorList)
{
if (testControlValidator instanceof TestAware)
{
if (testMethod != null)
{
((TestAware)testControlValidator).setTestMethod(testMethod);
}
((TestAware)testControlValidator).setTestClass(testClass);
}
try
{
testControlValidator.validate(this.testControl);
}
finally
{
if (testControlValidator instanceof TestAware)
{
((TestAware)testControlValidator).setTestClass(null);
((TestAware)testControlValidator).setTestMethod(null);
}
}
}
}
for (Class<? extends Annotation> scopeAnnotation : scopeClasses)
{
if (this.parent != null && this.parent.isScopeStarted(scopeAnnotation))
{
continue;
}
if (isRestrictedScope(scopeAnnotation, restrictedScopes))
{
continue;
}
try
{
//force a clean context - TODO discuss onScopeStopped call
contextControl.stopContext(scopeAnnotation);
contextControl.startContext(scopeAnnotation);
this.startedScopes.add(scopeAnnotation);
onScopeStarted(scopeAnnotation);
}
catch (RuntimeException e)
{
Logger logger = Logger.getLogger(CdiTestRunner.class.getName());
logger.setLevel(Level.SEVERE);
logger.log(Level.SEVERE, "failed to start scope @" + scopeAnnotation.getName(), e);
}
}
}
finally
{
automaticScopeHandlingActive.set(null);
automaticScopeHandlingActive.remove();
}
}