org.springframework.test.context.TestContextManager Java Examples
The following examples show how to use
org.springframework.test.context.TestContextManager.
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: PurRepositoryTestBase.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { this.testContextManager = new TestContextManager( getClass() ); this.testContextManager.prepareTestInstance( this ); KettleEnvironment.init(); PentahoSessionHolder.setStrategyName( PentahoSessionHolder.MODE_GLOBAL ); mockVersionManager(); removePentahoRootFolder(); startMicroPlatform(); createSystemUser(); createTester(); createPurRepository(); loginAsTester(); }
Example #2
Source File: SpringJUnit4ClassRunnerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test(expected = Exception.class) public void checkThatExceptionsAreNotSilentlySwallowed() throws Exception { SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass()) { @Override protected TestContextManager createTestContextManager(Class<?> clazz) { return new TestContextManager(clazz) { @Override public void prepareTestInstance(Object testInstance) { throw new RuntimeException( "This RuntimeException should be caught and wrapped in an Exception."); } }; } }; runner.createTest(); }
Example #3
Source File: SpringJUnit4ClassRunnerTests.java From java-technology-stack with MIT License | 6 votes |
@Test(expected = Exception.class) public void checkThatExceptionsAreNotSilentlySwallowed() throws Exception { SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass()) { @Override protected TestContextManager createTestContextManager(Class<?> clazz) { return new TestContextManager(clazz) { @Override public void prepareTestInstance(Object testInstance) { throw new RuntimeException( "This RuntimeException should be caught and wrapped in an Exception."); } }; } }; runner.createTest(); }
Example #4
Source File: SpringJUnit4ClassRunnerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test(expected = Exception.class) public void checkThatExceptionsAreNotSilentlySwallowed() throws Exception { SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass()) { @Override protected TestContextManager createTestContextManager(Class<?> clazz) { return new TestContextManager(clazz) { @Override public void prepareTestInstance(Object testInstance) { throw new RuntimeException( "This RuntimeException should be caught and wrapped in an Exception."); } }; } }; runner.createTest(); }
Example #5
Source File: SpringExtension.java From spring-test-junit5 with Apache License 2.0 | 5 votes |
/** * Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}. * @return the {@code TestContextManager} (never {@code null}) */ private static TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getRequiredTestClass(); Store store = getStore(context); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
Example #6
Source File: FlywayTestExtension.java From flyway-test-extensions with Apache License 2.0 | 5 votes |
/** * Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}. * * @return the {@code TestContextManager} (never {@code null}) */ private static TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getRequiredTestClass(); ExtensionContext.Store store = getStore(context); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
Example #7
Source File: RoleControllerParameterizedIntegrationTest.java From tutorials with MIT License | 5 votes |
@Before public void setup() throws Exception { this.testContextManager = new TestContextManager(getClass()); this.testContextManager.prepareTestInstance(this); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); }
Example #8
Source File: DisabledIfConditionTests.java From java-technology-stack with MIT License | 5 votes |
private ExtensionContext buildExtensionContext(String methodName) { Class<?> testClass = SpringTestCase.class; Method method = ReflectionUtils.findMethod(getClass(), methodName); Store store = mock(Store.class); when(store.getOrComputeIfAbsent(any(), any(), any())).thenReturn(new TestContextManager(testClass)); ExtensionContext extensionContext = mock(ExtensionContext.class); when(extensionContext.getTestClass()).thenReturn(Optional.of(testClass)); when(extensionContext.getElement()).thenReturn(Optional.of(method)); when(extensionContext.getStore(any())).thenReturn(store); return extensionContext; }
Example #9
Source File: SpringMethodRule.java From spring-analysis-note with MIT License | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunBeforeTestMethodCallbacks} statement. * @see RunBeforeTestMethodCallbacks */ private Statement withBeforeTestMethodCallbacks(Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) { return new RunBeforeTestMethodCallbacks( next, testInstance, testMethod, testContextManager); }
Example #10
Source File: SpringMethodRule.java From spring-analysis-note with MIT License | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestMethodCallbacks} statement. * @see RunAfterTestMethodCallbacks */ private Statement withAfterTestMethodCallbacks(Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) { return new RunAfterTestMethodCallbacks( next, testInstance, testMethod, testContextManager); }
Example #11
Source File: SpringExtension.java From tutorials with MIT License | 5 votes |
private TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getTestClass() .get(); ExtensionContext.Store store = context.getStore(namespace); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
Example #12
Source File: SpringProcessEngineTestCase.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public SpringProcessEngineTestCase() { super(); this.testContextManager = new TestContextManager(getClass()); SpringTestHelper testHelper = lookupTestHelper(); testHelper.beforeTestClass(testContextManager); }
Example #13
Source File: SpringMethodRule.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestMethodCallbacks} statement. * @see RunAfterTestMethodCallbacks */ private Statement withAfterTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunAfterTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
Example #14
Source File: SpringMethodRule.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunBeforeTestMethodCallbacks} statement. * @see RunBeforeTestMethodCallbacks */ private Statement withBeforeTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunBeforeTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
Example #15
Source File: DisabledIfConditionTests.java From spring-analysis-note with MIT License | 5 votes |
private ExtensionContext buildExtensionContext(String methodName) { Class<?> testClass = SpringTestCase.class; Method method = ReflectionUtils.findMethod(getClass(), methodName); Store store = mock(Store.class); given(store.getOrComputeIfAbsent(any(), any(), any())).willReturn(new TestContextManager(testClass)); ExtensionContext extensionContext = mock(ExtensionContext.class); given(extensionContext.getTestClass()).willReturn(Optional.of(testClass)); given(extensionContext.getElement()).willReturn(Optional.of(method)); given(extensionContext.getStore(any())).willReturn(store); return extensionContext; }
Example #16
Source File: SpringExtension.java From java-technology-stack with MIT License | 5 votes |
/** * Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}. * @return the {@code TestContextManager} (never {@code null}) */ private static TestContextManager getTestContextManager(ExtensionContext context) { Assert.notNull(context, "ExtensionContext must not be null"); Class<?> testClass = context.getRequiredTestClass(); Store store = getStore(context); return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class); }
Example #17
Source File: SpringMethodRule.java From java-technology-stack with MIT License | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestMethodCallbacks} statement. * @see RunAfterTestMethodCallbacks */ private Statement withAfterTestMethodCallbacks(Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) { return new RunAfterTestMethodCallbacks( next, testInstance, testMethod, testContextManager); }
Example #18
Source File: SpringMethodRule.java From java-technology-stack with MIT License | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunBeforeTestMethodCallbacks} statement. * @see RunBeforeTestMethodCallbacks */ private Statement withBeforeTestMethodCallbacks(Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) { return new RunBeforeTestMethodCallbacks( next, testInstance, testMethod, testContextManager); }
Example #19
Source File: SpringMethodRule.java From java-technology-stack with MIT License | 4 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunPrepareTestInstanceCallbacks} statement. * @see RunPrepareTestInstanceCallbacks */ private Statement withTestInstancePreparation( Statement next, Object testInstance, TestContextManager testContextManager) { return new RunPrepareTestInstanceCallbacks(next, testInstance, testContextManager); }
Example #20
Source File: SpringFlowableTestCase.java From flowable-engine with Apache License 2.0 | 4 votes |
public SpringFlowableTestCase() { this.testContextManager = new TestContextManager(getClass()); }
Example #21
Source File: SpringFlowableTestCase.java From flowable-engine with Apache License 2.0 | 4 votes |
public SpringFlowableTestCase() { this.testContextManager = new TestContextManager(getClass()); }
Example #22
Source File: SpringClassRule.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Apply <em>class-level</em> features of the <em>Spring TestContext * Framework</em> to the supplied {@code base} statement. * <p>Specifically, this method retrieves the {@link TestContextManager} * used by this rule and its associated {@link SpringMethodRule} and * invokes the {@link TestContextManager#beforeTestClass() beforeTestClass()} * and {@link TestContextManager#afterTestClass() afterTestClass()} methods * on the {@code TestContextManager}. * <p>In addition, this method checks whether the test is enabled in * the current execution environment. This prevents classes with a * non-matching {@code @IfProfileValue} annotation from running altogether, * even skipping the execution of {@code beforeTestClass()} methods * in {@code TestExecutionListeners}. * @param base the base {@code Statement} that this rule should be applied to * @param description a {@code Description} of the current test execution * @return a statement that wraps the supplied {@code base} with class-level * features of the Spring TestContext Framework * @see #getTestContextManager * @see #withBeforeTestClassCallbacks * @see #withAfterTestClassCallbacks * @see #withProfileValueCheck * @see #withTestContextManagerCacheEviction */ @Override public Statement apply(Statement base, Description description) { Class<?> testClass = description.getTestClass(); if (logger.isDebugEnabled()) { logger.debug("Applying SpringClassRule to test class [" + testClass.getName() + "]"); } validateSpringMethodRuleConfiguration(testClass); TestContextManager testContextManager = getTestContextManager(testClass); Statement statement = base; statement = withBeforeTestClassCallbacks(statement, testContextManager); statement = withAfterTestClassCallbacks(statement, testContextManager); statement = withProfileValueCheck(statement, testClass); statement = withTestContextManagerCacheEviction(statement, testClass); return statement; }
Example #23
Source File: SpringFlowableTestCase.java From flowable-engine with Apache License 2.0 | 4 votes |
public SpringFlowableTestCase() { this.testContextManager = new TestContextManager(getClass()); }
Example #24
Source File: SpringJUnit4ClassRunner.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Get the {@link TestContextManager} associated with this runner. */ protected final TestContextManager getTestContextManager() { return this.testContextManager; }
Example #25
Source File: SpringRestarter.java From eventeum with Apache License 2.0 | 4 votes |
public void init(TestContextManager testContextManager) { this.testContextManager = testContextManager; }
Example #26
Source File: WSConfigurationHelper.java From jfilter with Apache License 2.0 | 4 votes |
public static void instance(Instance testClass, Object testInstance) throws Exception { TestContextManager testContextManager = new TestContextManager(testClass.className); testContextManager.prepareTestInstance(testInstance); }
Example #27
Source File: SpringActivitiTestCase.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public SpringActivitiTestCase() { this.testContextManager = new TestContextManager(getClass()); }
Example #28
Source File: SpringMethodRule.java From java-technology-stack with MIT License | 4 votes |
/** * Apply <em>instance-level</em> and <em>method-level</em> features of * the <em>Spring TestContext Framework</em> to the supplied {@code base} * statement. * <p>Specifically, this method invokes the * {@link TestContextManager#prepareTestInstance prepareTestInstance()}, * {@link TestContextManager#beforeTestMethod beforeTestMethod()}, and * {@link TestContextManager#afterTestMethod afterTestMethod()} methods * on the {@code TestContextManager}, potentially with Spring timeouts * and repetitions. * <p>In addition, this method checks whether the test is enabled in * the current execution environment. This prevents methods with a * non-matching {@code @IfProfileValue} annotation from running altogether, * even skipping the execution of {@code prepareTestInstance()} methods * in {@code TestExecutionListeners}. * @param base the base {@code Statement} that this rule should be applied to * @param frameworkMethod the method which is about to be invoked on the test instance * @param testInstance the current test instance * @return a statement that wraps the supplied {@code base} with instance-level * and method-level features of the Spring TestContext Framework * @see #withBeforeTestMethodCallbacks * @see #withAfterTestMethodCallbacks * @see #withPotentialRepeat * @see #withPotentialTimeout * @see #withTestInstancePreparation * @see #withProfileValueCheck */ @Override public Statement apply(Statement base, FrameworkMethod frameworkMethod, Object testInstance) { Method testMethod = frameworkMethod.getMethod(); if (logger.isDebugEnabled()) { logger.debug("Applying SpringMethodRule to test method [" + testMethod + "]"); } Class<?> testClass = testInstance.getClass(); TestContextManager testContextManager = SpringClassRule.getTestContextManager(testClass); Statement statement = base; statement = withBeforeTestMethodCallbacks(statement, testMethod, testInstance, testContextManager); statement = withAfterTestMethodCallbacks(statement, testMethod, testInstance, testContextManager); statement = withTestInstancePreparation(statement, testInstance, testContextManager); statement = withPotentialRepeat(statement, testMethod, testInstance); statement = withPotentialTimeout(statement, testMethod, testInstance); statement = withProfileValueCheck(statement, testMethod, testInstance); return statement; }
Example #29
Source File: SpringClassRule.java From java-technology-stack with MIT License | 4 votes |
/** * Get the {@link TestContextManager} associated with the supplied test class. * @param testClass the test class to be managed; never {@code null} */ static TestContextManager getTestContextManager(Class<?> testClass) { Assert.notNull(testClass, "Test Class must not be null"); return testContextManagerCache.computeIfAbsent(testClass, TestContextManager::new); }
Example #30
Source File: SpringActivitiTestCase.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public SpringActivitiTestCase() { this.testContextManager = new TestContextManager(getClass()); }