本文整理匯總了Java中org.springframework.test.annotation.DirtiesContext.ClassMode類的典型用法代碼示例。如果您正苦於以下問題:Java ClassMode類的具體用法?Java ClassMode怎麽用?Java ClassMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassMode類屬於org.springframework.test.annotation.DirtiesContext包,在下文中一共展示了ClassMode類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beforeOrAfterTestClass
import org.springframework.test.annotation.DirtiesContext.ClassMode; //導入依賴的package包/類
/**
* Perform the actual work for {@link #beforeTestClass} and {@link #afterTestClass}
* by dirtying the context if appropriate (i.e., according to the required mode).
* @param testContext the test context whose application context should
* potentially be marked as dirty; never {@code null}
* @param requiredClassMode the class mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @throws Exception allows any exception to propagate
* @since 4.2
* @see #dirtyContext
*/
protected void beforeOrAfterTestClass(TestContext testContext, ClassMode requiredClassMode) throws Exception {
Assert.notNull(testContext, "TestContext must not be null");
Assert.notNull(requiredClassMode, "requiredClassMode must not be null");
Class<?> testClass = testContext.getTestClass();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
DirtiesContext dirtiesContext = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
boolean classAnnotated = (dirtiesContext != null);
ClassMode classMode = (classAnnotated ? dirtiesContext.classMode() : null);
if (logger.isDebugEnabled()) {
String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
logger.debug(String.format(
"%s test class: context %s, class annotated with @DirtiesContext [%s] with mode [%s].", phase,
testContext, classAnnotated, classMode));
}
if (classMode == requiredClassMode) {
dirtyContext(testContext, dirtiesContext.hierarchyMode());
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:AbstractDirtiesContextTestExecutionListener.java
示例2: beforeOrAfterTestMethod
import org.springframework.test.annotation.DirtiesContext.ClassMode; //導入依賴的package包/類
/**
* Perform the actual work for {@link #beforeTestMethod} and {@link #afterTestMethod}
* by dirtying the context if appropriate (i.e., according to the required modes).
* @param testContext the test context whose application context should
* potentially be marked as dirty; never {@code null}
* @param requiredMethodMode the method mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @param requiredClassMode the class mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @throws Exception allows any exception to propagate
* @since 4.2
* @see #dirtyContext
*/
protected void beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode,
ClassMode requiredClassMode) throws Exception {
Assert.notNull(testContext, "TestContext must not be null");
Assert.notNull(requiredMethodMode, "requiredMethodMode must not be null");
Assert.notNull(requiredClassMode, "requiredClassMode must not be null");
Class<?> testClass = testContext.getTestClass();
Method testMethod = testContext.getTestMethod();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
DirtiesContext methodAnn = AnnotatedElementUtils.findMergedAnnotation(testMethod, DirtiesContext.class);
DirtiesContext classAnn = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
boolean methodAnnotated = (methodAnn != null);
boolean classAnnotated = (classAnn != null);
MethodMode methodMode = (methodAnnotated ? methodAnn.methodMode() : null);
ClassMode classMode = (classAnnotated ? classAnn.classMode() : null);
if (logger.isDebugEnabled()) {
String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
logger.debug(String.format("%s test method: context %s, class annotated with @DirtiesContext [%s] "
+ "with mode [%s], method annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext,
classAnnotated, classMode, methodAnnotated, methodMode));
}
if ((methodMode == requiredMethodMode) || (classMode == requiredClassMode)) {
HierarchyMode hierarchyMode = (methodAnnotated ? methodAnn.hierarchyMode() : classAnn.hierarchyMode());
dirtyContext(testContext, hierarchyMode);
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:45,代碼來源:AbstractDirtiesContextTestExecutionListener.java
示例3: afterTestMethod
import org.springframework.test.annotation.DirtiesContext.ClassMode; //導入依賴的package包/類
/**
* If the current test method of the supplied {@linkplain TestContext test
* context} is annotated with {@link DirtiesContext @DirtiesContext},
* or if the test class is annotated with {@link DirtiesContext
* @DirtiesContext} and the {@linkplain DirtiesContext#classMode() class
* mode} is set to {@link ClassMode#AFTER_EACH_TEST_METHOD
* AFTER_EACH_TEST_METHOD}, the {@linkplain ApplicationContext application
* context} of the test context will be
* {@linkplain TestContext#markApplicationContextDirty() marked as dirty} and the
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE}
* in the test context will be set to {@code true}.
*/
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
Method testMethod = testContext.getTestMethod();
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
final Class<DirtiesContext> annotationType = DirtiesContext.class;
boolean methodDirtiesContext = testMethod.isAnnotationPresent(annotationType);
boolean classDirtiesContext = testClass.isAnnotationPresent(annotationType);
DirtiesContext classDirtiesContextAnnotation = testClass.getAnnotation(annotationType);
ClassMode classMode = classDirtiesContext ? classDirtiesContextAnnotation.classMode() : null;
if (logger.isDebugEnabled()) {
logger.debug("After test method: context [" + testContext + "], class dirties context ["
+ classDirtiesContext + "], class mode [" + classMode + "], method dirties context ["
+ methodDirtiesContext + "].");
}
if (methodDirtiesContext || (classDirtiesContext && classMode == ClassMode.AFTER_EACH_TEST_METHOD)) {
HierarchyMode hierarchyMode = methodDirtiesContext ? testMethod.getAnnotation(annotationType).hierarchyMode()
: classDirtiesContextAnnotation.hierarchyMode();
dirtyContext(testContext, hierarchyMode);
}
}