Class AbstractSpringContextTests

  • Direct Known Subclasses:
    AbstractSingleSpringContextTests

    @Deprecated
    public abstract class AbstractSpringContextTests
    extends org.junit.Assert
    Deprecated.
    as of Spring 3.0, in favor of using the listener-based test context framework (org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests)

    Superclass for JUnit 3.8 test cases using Spring ApplicationContexts.

    Maintains a static cache of contexts by key. This has significant performance benefit if initializing the context would take time. While initializing a Spring context itself is very quick, some beans in a context, such as a LocalSessionFactoryBean for working with Hibernate, may take some time to initialize. Hence it often makes sense to do that initializing once.

    Any ApplicationContext created by this class will be asked to register a JVM shutdown hook for itself. Unless the context gets closed early, all context instances will be automatically closed on JVM shutdown. This allows for freeing external resources held by beans within the context, e.g. temporary files.

    Normally you won't extend this class directly but rather one of its subclasses.

    Since:
    1.1.1
    Author:
    Rod Johnson, Juergen Hoeller, Sam Brannen
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.logging.Log logger
      Deprecated.
      Logger available to subclasses
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractSpringContextTests()
      Deprecated.
      Default constructor for AbstractSpringContextTests.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected String contextKeyString​(Object contextKey)
      Deprecated.
      Subclasses can override this to return a String representation of their context key for use in caching and logging.
      protected org.springframework.context.ConfigurableApplicationContext getContext​(Object key)
      Deprecated.
      Obtain an ApplicationContext for the given key, potentially cached.
      static Map<String,​org.springframework.context.ConfigurableApplicationContext> getContextKeyToContextMap()
      Deprecated.
       
      protected boolean isContextKeyEmpty​(Object key)
      Deprecated.
      Determine if the supplied context key is empty.
      protected abstract org.springframework.context.ConfigurableApplicationContext loadContext​(Object key)
      Deprecated.
      Load a new ApplicationContext for the given key.
      protected void setDirty​(Object contextKey)
      Deprecated.
      Mark the context with the given key as dirty.
      • Methods inherited from class org.junit.Assert

        assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
    • Field Detail

      • logger

        protected final org.apache.commons.logging.Log logger
        Deprecated.
        Logger available to subclasses
    • Constructor Detail

      • AbstractSpringContextTests

        public AbstractSpringContextTests()
        Deprecated.
        Default constructor for AbstractSpringContextTests.
    • Method Detail

      • isContextKeyEmpty

        protected boolean isContextKeyEmpty​(Object key)
        Deprecated.
        Determine if the supplied context key is empty.

        By default, null values, empty strings, and zero-length arrays are considered empty.

        Parameters:
        key - the context key to check
        Returns:
        true if the supplied context key is empty
      • getContext

        protected final org.springframework.context.ConfigurableApplicationContext getContext​(Object key)
                                                                                       throws Exception
        Deprecated.
        Obtain an ApplicationContext for the given key, potentially cached.
        Parameters:
        key - the context key; may be null.
        Returns:
        the corresponding ApplicationContext instance (potentially cached), or null if the provided key is empty
        Throws:
        Exception
      • setDirty

        protected final void setDirty​(Object contextKey)
        Deprecated.
        Mark the context with the given key as dirty. This will cause the cached context to be reloaded before the next test case is executed.

        Call this method only if you change the state of a singleton bean, potentially affecting future tests.

      • contextKeyString

        protected String contextKeyString​(Object contextKey)
        Deprecated.
        Subclasses can override this to return a String representation of their context key for use in caching and logging.
        Parameters:
        contextKey - the context key
      • loadContext

        protected abstract org.springframework.context.ConfigurableApplicationContext loadContext​(Object key)
                                                                                           throws Exception
        Deprecated.
        Load a new ApplicationContext for the given key.

        To be implemented by subclasses.

        Parameters:
        key - the context key
        Returns:
        the corresponding ApplicationContext instance (new)
        Throws:
        Exception
      • getContextKeyToContextMap

        @NotNull
        public static Map<String,​org.springframework.context.ConfigurableApplicationContext> getContextKeyToContextMap()
        Deprecated.