Spring Framework TestContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework TestContext class.

This code example shows how to use the following methods:getApplicationContext, getTestClass, getTestInstance, getAttribute, removeAttribute
	 * {@link #prepareTestInstance(TestContext) prepareTestInstance()}; 
	 * otherwise, this method will have no effect. 
	 */ 
	@Override 
	public void beforeTestMethod(final TestContext testContext) throws Exception {
		if (Boolean.TRUE.equals(testContext.getAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE))) {
			if (logger.isDebugEnabled()) {
				logger.debug("Reinjecting dependencies for test context [" + testContext + "].");
			} 
			injectDependencies(testContext);
		} 
	} 
 
	/** 
	 * Performs dependency injection and bean initialization for the supplied 
	 * {@link TestContext} as described in 
	 * {@link #prepareTestInstance(TestContext) prepareTestInstance()}. 
	 * <p>The {@link #REINJECT_DEPENDENCIES_ATTRIBUTE} will be subsequently removed 
	 * from the test context, regardless of its value. 
	 * @param testContext the test context for which dependency injection should 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getApplicationContext, getTestClass, getAttribute, setAttribute
		testContext.removeAttribute(POPULATED_REQUEST_CONTEXT_HOLDER_ATTRIBUTE); 
		testContext.removeAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE); 
	} 
 
	private boolean notAnnotatedWithWebAppConfiguration(TestContext testContext) { 
		return AnnotationUtils.findAnnotation(testContext.getTestClass(), WebAppConfiguration.class) == null; 
	} 
 
	private boolean alreadyPopulatedRequestContextHolder(TestContext testContext) { 
		return Boolean.TRUE.equals(testContext.getAttribute(POPULATED_REQUEST_CONTEXT_HOLDER_ATTRIBUTE)); 
	} 
 
	private void setUpRequestContextIfNecessary(TestContext testContext) { 
		if (notAnnotatedWithWebAppConfiguration(testContext) || alreadyPopulatedRequestContextHolder(testContext)) { 
			return; 
		} 
 
		ApplicationContext context = testContext.getApplicationContext(); 
 
		if (context instanceof WebApplicationContext) { 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:markApplicationContextDirty, setAttribute
	 * @param hierarchyMode the context cache clearing mode to be applied if the 
	 * context is part of a hierarchy; may be {@code null} 
	 * @since 3.2.2 
	 */ 
	protected void dirtyContext(TestContext testContext, HierarchyMode hierarchyMode) {
		testContext.markApplicationContextDirty(hierarchyMode);
		testContext.setAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE, Boolean.TRUE);
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTestClass, getTestMethod
		private final String name;
 
 
		public TestContextTransactionAttribute(TransactionAttribute targetAttribute, TestContext testContext) {
			super(targetAttribute);
			this.name = testContext.getTestClass().getName() + "." + testContext.getTestMethod().getName();
		} 
 
		@Override 
		public String getName() {
			return this.name;
		} 
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTestClass
	 * @return the TransactionConfigurationAttributes instance for this listener, 
	 * potentially cached 
	 */ 
	TransactionConfigurationAttributes retrieveConfigurationAttributes(TestContext testContext) { 
		if (this.configurationAttributes == null) { 
			Class<?> clazz = testContext.getTestClass(); 
 
			AnnotationAttributes annAttrs = AnnotatedElementUtils.getAnnotationAttributes(clazz, 
				TransactionConfiguration.class.getName()); 
			if (logger.isDebugEnabled()) { 
				logger.debug(String.format("Retrieved @TransactionConfiguration attributes [%s] for test class [%s].", 
					annAttrs, clazz)); 
			} 
 
			String transactionManagerName; 
			boolean defaultRollback; 
			if (annAttrs != null) { 
				transactionManagerName = annAttrs.getString("transactionManager"); 
				defaultRollback = annAttrs.getBoolean("defaultRollback"); 
			} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework TestContext Methods: