Spring Framework AbstractTestExecutionListener - 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 AbstractTestExecutionListener class.

This code example shows how to use the following methods:
package org.springframework.test.context; 
 
import org.springframework.test.annotation.DirtiesContext; 
import org.springframework.test.context.support.AbstractTestExecutionListener;
 
public class CleanContextCacheTestExecutionListener extends AbstractTestExecutionListener {
 
    @Override 
    public void beforeTestClass(TestContext testContext) throws Exception {
        super.beforeTestClass(testContext);
        testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
    } 
 
    @Override 
    public void afterTestMethod(TestContext testContext) throws Exception {
        testContext.markApplicationContextDirty(DirtiesContext.HierarchyMode.EXHAUSTIVE);
        super.afterTestMethod(testContext);
    } 
 
    @Override 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
/** 
 * Provides reset to pre-test state behavior for global enable/disable of JMX 
 * support in Camel through the use of {@link DisableJmx}. 
 * Tries to ensure that the pre-test value is restored. 
 */ 
public class DisableJmxTestExecutionListener extends AbstractTestExecutionListener {
 
    @Override 
    public void afterTestClass(TestContext testContext) throws Exception {
        if (CamelSpringTestHelper.getOriginalJmxDisabled() == null) { 
            System.clearProperty(JmxSystemPropertyKeys.DISABLED);
        } else { 
            System.setProperty(JmxSystemPropertyKeys.DISABLED, CamelSpringTestHelper.getOriginalJmxDisabled());
        } 
    } 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 * the Spring context. 
 * <p/> 
 * Implemented as a listener as the state can be set on a {@code ThreadLocal} and we are pretty sure 
 * that the same thread will be used to initialize the Spring context. 
 */ 
public class CamelSpringTestContextLoaderTestExecutionListener extends AbstractTestExecutionListener {
 
    /** 
     * The default implementation returns {@link org.springframework.core.Ordered#LOWEST_PRECEDENCE}, 
     * thereby ensuring that custom listeners are ordered after default 
     * listeners supplied by the framework. Can be overridden by subclasses 
     * as necessary. 
     */ 
    @Override 
    public int getOrder() { 
        //set Camel first 
        return Ordered.HIGHEST_PRECEDENCE;
    } 
 
    @Override 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 * 
 * @author Rob Winch 
 * @since 4.0 
 */ 
@Order(1000) 
public class WithSecurityContextTestExecutionListener extends 
        AbstractTestExecutionListener {
 
    /** 
     * Sets up the {@link SecurityContext} for each test method. First the 
     * specific method is inspected for a {@link WithSecurityContext} or {@link Annotation} 
     * that has {@link WithSecurityContext} on it. If that is not found, the class is 
     * inspected. If still not found, then no {@link SecurityContext} is 
     * populated. 
     */ 
    @Override 
    public void beforeTestMethod(TestContext testContext) throws Exception {
        Annotation[] methodAnnotations = AnnotationUtils
                .getAnnotations(testContext.getTestMethod());
        ApplicationContext context = testContext.getApplicationContext();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
import org.springframework.test.context.support.AbstractTestExecutionListener;
 
/** 
 * An execution listener that simulates the timing output built in to {@link org.apache.camel.test.junit4.CamelTestSupport}. 
 */ 
public class StopWatchTestExecutionListener extends AbstractTestExecutionListener {
     
    protected static ThreadLocal<StopWatch> threadStopWatch = new ThreadLocal<StopWatch>();
     
    /** 
     * Exists primarily for testing purposes, but allows for access to the underlying stop watch instance for a test. 
     */ 
    public static StopWatch getStopWatch() { 
        return threadStopWatch.get();
    } 
     
    @Override 
    public void beforeTestMethod(TestContext testContext) throws Exception {
        StopWatch stopWatch = new StopWatch();
        threadStopWatch.set(stopWatch);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
 
public class DBSetupExecutionListener extends AbstractTestExecutionListener {
 
	private static Logger LOG = Logger
			.getLogger(DBSetupExecutionListener.class);
 
	private Connection conn;
 
	@Override 
	public void beforeTestClass(TestContext testContext) throws Exception {
		if (LOG.isDebugEnabled())
			LOG.debug("starting beforeTestClass");
		// startup H2 DB 
		Class.forName("org.h2.Driver");
		conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "");
		Resource resource = new ClassPathResource(
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 * associated action in the {@link BaseContextSensitiveTest#setupDatabaseWithStandardData()} method 
 *  
 * @see SkipBaseSetup 
 * @see BaseContextSensitiveTest 
 */ 
public class SkipBaseSetupAnnotationExecutionListener extends AbstractTestExecutionListener {
	 
	/** 
	 * This method is run before all "@Before" methods thanks to Spring and the 
	 * "@TestExecutionListeners" annotation on the {@link BaseContextSensitiveTest} class. 
	 *  
	 * @see org.springframework.test.context.support.AbstractTestExecutionListener#beforeTestMethod(org.springframework.test.context.TestContext) 
	 */ 
	@Override 
	public void beforeTestMethod(TestContext testContext) throws Exception {
		Method testMethod = testContext.getTestMethod();
		 
		Annotation skipBaseSetup = testMethod.getAnnotation(SkipBaseSetup.class);
		 
		// if the method doesn't have the annotation, check the class 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
/** 
 * This listener will inject the {@link TestContext} into a test if it 
 * supports the {@link TestContextAware} interface. 
 */ 
public class TestContextAwareExecutionListener extends AbstractTestExecutionListener {
 
	@Override 
	public void beforeTestMethod(TestContext testContext) throws Exception {
		// FIXME: Is there a better way to inject the instance into the test class? 
		if (testContext.getTestInstance() instanceof TestContextAware) {
			System.err.println("injecting TestContext into TestContextAware test: "
					+ testContext.getTestInstance().getClass().getSimpleName() + "."
					+ testContext.getTestMethod().getName());
			((TestContextAware) testContext.getTestInstance()).setTestContext(testContext);
		} 
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 *  
 * Backup any alert belonging to provider testApp_provider before runs any test. This backup allows 
 * to restore catalog state after runs all tests. 
 *  
 */ 
public class BackupAlertsCollectionHook extends AbstractTestExecutionListener {
 
  static String PROVIDER_ID = "testApp_provider";
 
  protected PlatformClientOperations platformTemplate;
 
  private List<CatalogAlert> alertsBackup;
 
  public void beforeTestClass(TestContext testContext) throws Exception {
    final CatalogAlertInputMessage message = new CatalogAlertInputMessage();
    // message.setIdentityToken(tokenApp); 
    final CatalogAlertOutputMessage outputMessage = getPlatformTemplate(testContext).getCatalogOps().getAuthorizedAlerts(message);
    alertsBackup = outputMessage.getAlerts();
  } 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
import org.springframework.test.context.support.AbstractTestExecutionListener;
 
/** 
 * @author Petter Holmström (petter@vaadin.com) 
 */ 
class VaadinTestExecutionListener extends AbstractTestExecutionListener {
 
    public static final String SET_UP_SCOPES_ATTRIBUTE = Conventions.getQualifiedAttributeName(
            VaadinTestExecutionListener.class, "setUpScopes"); 
    private static final Logger logger = LoggerFactory.getLogger(VaadinTestExecutionListener.class); 
 
    @Override 
    public void prepareTestInstance(TestContext testContext) throws Exception {
        setUpVaadinScopesIfNecessary(testContext);
    } 
 
    @Override 
    public void beforeTestMethod(TestContext testContext) throws Exception {
        setUpVaadinScopesIfNecessary(testContext);
    } 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java