Java Code Examples for org.springframework.test.annotation.DirtiesContext#classMode()
The following examples show how to use
org.springframework.test.annotation.DirtiesContext#classMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDirtiesContextTestExecutionListener.java From spring-analysis-note with MIT License | 6 votes |
/** * 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()); } }
Example 2
Source File: AbstractDirtiesContextTestExecutionListener.java From java-technology-stack with MIT License | 6 votes |
/** * 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()); } }
Example 3
Source File: AbstractDirtiesContextTestExecutionListener.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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()); } }
Example 4
Source File: AbstractDirtiesContextTestExecutionListener.java From spring-analysis-note with MIT License | 5 votes |
/** * 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); } }
Example 5
Source File: AbstractDirtiesContextTestExecutionListener.java From java-technology-stack with MIT License | 5 votes |
/** * 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); } }
Example 6
Source File: AbstractDirtiesContextTestExecutionListener.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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); } }