|
|
|
@ -26,11 +26,13 @@ import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
import org.springframework.core.annotation.AnnotationAttributes; |
|
|
|
import org.springframework.test.context.MetaAnnotationUtils.AnnotationDescriptor; |
|
|
|
import org.springframework.test.context.MetaAnnotationUtils.*; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.test.context.MetaAnnotationUtils.*; |
|
|
|
import static org.springframework.test.context.MetaAnnotationUtils.*; |
|
|
|
@ -159,8 +161,7 @@ public class TestContextManager { |
|
|
|
* registered for this {@code TestContextManager} in reverse order. |
|
|
|
* registered for this {@code TestContextManager} in reverse order. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<TestExecutionListener> getReversedTestExecutionListeners() { |
|
|
|
private List<TestExecutionListener> getReversedTestExecutionListeners() { |
|
|
|
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>( |
|
|
|
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(getTestExecutionListeners()); |
|
|
|
getTestExecutionListeners()); |
|
|
|
|
|
|
|
Collections.reverse(listenersReversed); |
|
|
|
Collections.reverse(listenersReversed); |
|
|
|
return listenersReversed; |
|
|
|
return listenersReversed; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -234,9 +235,9 @@ public class TestContextManager { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (NoClassDefFoundError err) { |
|
|
|
catch (NoClassDefFoundError err) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. " |
|
|
|
logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. " + |
|
|
|
+ "Specify custom listener classes or make the default listener classes " |
|
|
|
"Specify custom listener classes or make the default listener classes " + |
|
|
|
+ "(and their dependencies) available.", listenerClass.getName())); |
|
|
|
"(and their dependencies) available.", listenerClass.getName())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -252,15 +253,15 @@ public class TestContextManager { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() { |
|
|
|
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() { |
|
|
|
Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<Class<? extends TestExecutionListener>>(); |
|
|
|
Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<Class<? extends TestExecutionListener>>(); |
|
|
|
|
|
|
|
ClassLoader cl = getClass().getClassLoader(); |
|
|
|
for (String className : DEFAULT_TEST_EXECUTION_LISTENER_CLASS_NAMES) { |
|
|
|
for (String className : DEFAULT_TEST_EXECUTION_LISTENER_CLASS_NAMES) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
defaultListenerClasses.add((Class<? extends TestExecutionListener>) getClass().getClassLoader().loadClass( |
|
|
|
defaultListenerClasses.add((Class<? extends TestExecutionListener>) ClassUtils.forName(className, cl)); |
|
|
|
className)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable t) { |
|
|
|
catch (Throwable ex) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Could not load default TestExecutionListener class [" + className |
|
|
|
logger.debug("Could not load default TestExecutionListener class [" + className + |
|
|
|
+ "]. Specify custom listener classes or make the default listener classes available.", t); |
|
|
|
"]. Specify custom listener classes or make the default listener classes available.", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -281,7 +282,7 @@ public class TestContextManager { |
|
|
|
* @see #getTestExecutionListeners() |
|
|
|
* @see #getTestExecutionListeners() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void beforeTestClass() throws Exception { |
|
|
|
public void beforeTestClass() throws Exception { |
|
|
|
final Class<?> testClass = getTestContext().getTestClass(); |
|
|
|
Class<?> testClass = getTestContext().getTestClass(); |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace("beforeTestClass(): class [" + testClass + "]"); |
|
|
|
logger.trace("beforeTestClass(): class [" + testClass + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -292,8 +293,8 @@ public class TestContextManager { |
|
|
|
testExecutionListener.beforeTestClass(getTestContext()); |
|
|
|
testExecutionListener.beforeTestClass(getTestContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener + |
|
|
|
+ "] to process 'before class' callback for test class [" + testClass + "]", ex); |
|
|
|
"] to process 'before class' callback for test class [" + testClass + "]", ex); |
|
|
|
throw ex; |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -325,8 +326,8 @@ public class TestContextManager { |
|
|
|
testExecutionListener.prepareTestInstance(getTestContext()); |
|
|
|
testExecutionListener.prepareTestInstance(getTestContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
logger.error("Caught exception while allowing TestExecutionListener [" + testExecutionListener |
|
|
|
logger.error("Caught exception while allowing TestExecutionListener [" + testExecutionListener + |
|
|
|
+ "] to prepare test instance [" + testInstance + "]", ex); |
|
|
|
"] to prepare test instance [" + testInstance + "]", ex); |
|
|
|
throw ex; |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -362,9 +363,9 @@ public class TestContextManager { |
|
|
|
testExecutionListener.beforeTestMethod(getTestContext()); |
|
|
|
testExecutionListener.beforeTestMethod(getTestContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener + |
|
|
|
+ "] to process 'before' execution of test method [" + testMethod + "] for test instance [" |
|
|
|
"] to process 'before' execution of test method [" + testMethod + "] for test instance [" + |
|
|
|
+ testInstance + "]", ex); |
|
|
|
testInstance + "]", ex); |
|
|
|
throw ex; |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -410,9 +411,9 @@ public class TestContextManager { |
|
|
|
testExecutionListener.afterTestMethod(getTestContext()); |
|
|
|
testExecutionListener.afterTestMethod(getTestContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener + |
|
|
|
+ "] to process 'after' execution for test: method [" + testMethod + "], instance [" |
|
|
|
"] to process 'after' execution for test: method [" + testMethod + "], instance [" + |
|
|
|
+ testInstance + "], exception [" + exception + "]", ex); |
|
|
|
testInstance + "], exception [" + exception + "]", ex); |
|
|
|
if (afterTestMethodException == null) { |
|
|
|
if (afterTestMethodException == null) { |
|
|
|
afterTestMethodException = ex; |
|
|
|
afterTestMethodException = ex; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -438,7 +439,7 @@ public class TestContextManager { |
|
|
|
* @see #getTestExecutionListeners() |
|
|
|
* @see #getTestExecutionListeners() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void afterTestClass() throws Exception { |
|
|
|
public void afterTestClass() throws Exception { |
|
|
|
final Class<?> testClass = getTestContext().getTestClass(); |
|
|
|
Class<?> testClass = getTestContext().getTestClass(); |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace("afterTestClass(): class [" + testClass + "]"); |
|
|
|
logger.trace("afterTestClass(): class [" + testClass + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -452,8 +453,8 @@ public class TestContextManager { |
|
|
|
testExecutionListener.afterTestClass(getTestContext()); |
|
|
|
testExecutionListener.afterTestClass(getTestContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener |
|
|
|
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener + |
|
|
|
+ "] to process 'after class' callback for test class [" + testClass + "]", ex); |
|
|
|
"] to process 'after class' callback for test class [" + testClass + "]", ex); |
|
|
|
if (afterTestClassException == null) { |
|
|
|
if (afterTestClassException == null) { |
|
|
|
afterTestClassException = ex; |
|
|
|
afterTestClassException = ex; |
|
|
|
} |
|
|
|
} |
|
|
|
|