org.springframework.test
Class AbstractDependencyInjectionSpringContextTests

java.lang.Object
  extended by TestCase
      extended by org.springframework.test.ConditionalTestCase
          extended by org.springframework.test.AbstractSpringContextTests
              extended by org.springframework.test.AbstractSingleSpringContextTests
                  extended by org.springframework.test.AbstractDependencyInjectionSpringContextTests
Direct Known Subclasses:
AbstractTransactionalSpringContextTests

Deprecated. as of Spring 3.0, in favor of using the listener-based test context framework (AbstractJUnit38SpringContextTests)

@Deprecated
public abstract class AbstractDependencyInjectionSpringContextTests
extends AbstractSingleSpringContextTests

Convenient superclass for JUnit 3.8 based tests depending on a Spring context. The test instance itself is populated by Dependency Injection.

Really for integration testing, not unit testing. You should not normally use the Spring container for unit tests: simply populate your POJOs in plain JUnit tests!

This supports two modes of populating the test:

Since:
1.1.1
Author:
Rod Johnson, Rob Harrop, Rick Evans, Sam Brannen
See Also:
AbstractSingleSpringContextTests.setDirty(), AbstractSingleSpringContextTests.contextKey(), AbstractSpringContextTests.getContext(java.lang.Object), AbstractSingleSpringContextTests.getConfigLocations()

Field Summary
static int AUTOWIRE_BY_NAME
          Deprecated. Constant that indicates autowiring bean properties by name.
static int AUTOWIRE_BY_TYPE
          Deprecated. Constant that indicates autowiring bean properties by type.
static int AUTOWIRE_NO
          Deprecated. Constant that indicates no autowiring at all.
private  int autowireMode
          Deprecated.  
private  boolean dependencyCheck
          Deprecated.  
private  java.lang.String[] managedVariableNames
          Deprecated.  
private  boolean populateProtectedVariables
          Deprecated.  
 
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
applicationContext
 
Fields inherited from class org.springframework.test.ConditionalTestCase
logger
 
Constructor Summary
AbstractDependencyInjectionSpringContextTests()
          Deprecated. Default constructor for AbstractDependencyInjectionSpringContextTests.
AbstractDependencyInjectionSpringContextTests(java.lang.String name)
          Deprecated. Constructor for AbstractDependencyInjectionSpringContextTests with a JUnit name.
 
Method Summary
private  java.lang.reflect.Field findField(java.lang.Class clazz, java.lang.String name)
          Deprecated.  
 int getAutowireMode()
          Deprecated. Return the autowire mode for test properties set by Dependency Injection.
private  void initManagedVariableNames()
          Deprecated.  
protected  void injectDependencies()
          Deprecated. Inject dependencies into 'this' instance (that is, this test instance).
 boolean isDependencyCheck()
          Deprecated. Return whether or not dependency checking should be performed for test properties set by Dependency Injection.
 boolean isPopulateProtectedVariables()
          Deprecated. Return whether to populate protected variables of this test case.
private  boolean isProtectedInstanceField(java.lang.reflect.Field field)
          Deprecated.  
private  void populateProtectedVariables()
          Deprecated.  
protected  void prepareTestInstance()
          Deprecated. Prepare this test instance, injecting dependencies into its protected fields and its bean properties.
 void setAutowireMode(int autowireMode)
          Deprecated. Set the autowire mode for test properties set by Dependency Injection.
 void setDependencyCheck(boolean dependencyCheck)
          Deprecated. Set whether or not dependency checking should be performed for test properties set by Dependency Injection.
 void setPopulateProtectedVariables(boolean populateFields)
          Deprecated. Set whether to populate protected variables of this test case.
 
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests
contextKey, createApplicationContext, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, onSetUp, onTearDown, prepareApplicationContext, setDirty, setUp, tearDown
 
Methods inherited from class org.springframework.test.AbstractSpringContextTests
addContext, contextKeyString, getContext, hasCachedContext, isContextKeyEmpty, setDirty
 
Methods inherited from class org.springframework.test.ConditionalTestCase
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOWIRE_NO

public static final int AUTOWIRE_NO
Deprecated. 
Constant that indicates no autowiring at all.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_BY_NAME

public static final int AUTOWIRE_BY_NAME
Deprecated. 
Constant that indicates autowiring bean properties by name.

See Also:
setAutowireMode(int), Constant Field Values

AUTOWIRE_BY_TYPE

public static final int AUTOWIRE_BY_TYPE
Deprecated. 
Constant that indicates autowiring bean properties by type.

See Also:
setAutowireMode(int), Constant Field Values

populateProtectedVariables

private boolean populateProtectedVariables
Deprecated. 

autowireMode

private int autowireMode
Deprecated. 

dependencyCheck

private boolean dependencyCheck
Deprecated. 

managedVariableNames

private java.lang.String[] managedVariableNames
Deprecated. 
Constructor Detail

AbstractDependencyInjectionSpringContextTests

public AbstractDependencyInjectionSpringContextTests()
Deprecated. 
Default constructor for AbstractDependencyInjectionSpringContextTests.


AbstractDependencyInjectionSpringContextTests

public AbstractDependencyInjectionSpringContextTests(java.lang.String name)
Deprecated. 
Constructor for AbstractDependencyInjectionSpringContextTests with a JUnit name.

Parameters:
name - the name of this text fixture
Method Detail

setPopulateProtectedVariables

public final void setPopulateProtectedVariables(boolean populateFields)
Deprecated. 
Set whether to populate protected variables of this test case. Default is false.


isPopulateProtectedVariables

public final boolean isPopulateProtectedVariables()
Deprecated. 
Return whether to populate protected variables of this test case.


setAutowireMode

public final void setAutowireMode(int autowireMode)
Deprecated. 
Set the autowire mode for test properties set by Dependency Injection.

The default is AUTOWIRE_BY_TYPE. Can be set to AUTOWIRE_BY_NAME or AUTOWIRE_NO instead.

See Also:
AUTOWIRE_BY_TYPE, AUTOWIRE_BY_NAME, AUTOWIRE_NO

getAutowireMode

public final int getAutowireMode()
Deprecated. 
Return the autowire mode for test properties set by Dependency Injection.


setDependencyCheck

public final void setDependencyCheck(boolean dependencyCheck)
Deprecated. 
Set whether or not dependency checking should be performed for test properties set by Dependency Injection.

The default is true, meaning that tests cannot be run unless all properties are populated.


isDependencyCheck

public final boolean isDependencyCheck()
Deprecated. 
Return whether or not dependency checking should be performed for test properties set by Dependency Injection.


prepareTestInstance

protected void prepareTestInstance()
                            throws java.lang.Exception
Deprecated. 
Prepare this test instance, injecting dependencies into its protected fields and its bean properties.

Note: if the ApplicationContext for this test instance has not been configured (e.g., is null), dependency injection will naturally not be performed, but an informational message will be written to the log.

Overrides:
prepareTestInstance in class AbstractSingleSpringContextTests
Throws:
java.lang.Exception - in case of preparation failure
See Also:
injectDependencies()

injectDependencies

protected void injectDependencies()
                           throws java.lang.Exception
Deprecated. 
Inject dependencies into 'this' instance (that is, this test instance).

The default implementation populates protected variables if the appropriate flag is set, else uses autowiring if autowiring is switched on (which it is by default).

Override this method if you need full control over how dependencies are injected into the test instance.

Throws:
java.lang.Exception - in case of dependency injection failure
java.lang.IllegalStateException - if the ApplicationContext for this test instance has not been configured
See Also:
populateProtectedVariables()

initManagedVariableNames

private void initManagedVariableNames()
                               throws java.lang.IllegalAccessException
Deprecated. 
Throws:
java.lang.IllegalAccessException

isProtectedInstanceField

private boolean isProtectedInstanceField(java.lang.reflect.Field field)
Deprecated. 

populateProtectedVariables

private void populateProtectedVariables()
                                 throws java.lang.IllegalAccessException
Deprecated. 
Throws:
java.lang.IllegalAccessException

findField

private java.lang.reflect.Field findField(java.lang.Class clazz,
                                          java.lang.String name)
                                   throws java.lang.NoSuchFieldException
Deprecated. 
Throws:
java.lang.NoSuchFieldException