public abstract class

AbstractContextLoader

extends Object
implements ContextLoader
java.lang.Object
   ↳ org.springframework.test.context.support.AbstractContextLoader
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Abstract application context loader, which provides a basis for all concrete implementations of the ContextLoader strategy. Provides a Template Method based approach for processing locations.

Summary

Public Constructors
AbstractContextLoader()
Public Methods
final String[] processLocations(Class<?> clazz, String... locations)
If the supplied locations are null or empty and isGenerateDefaultLocations() is true, default locations will be generated for the specified class and the configured resource suffix; otherwise, the supplied locations will be modified if necessary and returned.
Protected Methods
String[] generateDefaultLocations(Class<?> clazz)
Generates the default classpath resource locations array based on the supplied class.
abstract String getResourceSuffix()
Get the suffix to append to ApplicationContext resource locations when generating default locations.
boolean isGenerateDefaultLocations()
Determine whether or not default resource locations should be generated if the locations provided to #processLocations(Class,String...) processLocations() are null or empty.
String[] modifyLocations(Class<?> clazz, String... locations)
Generate a modified version of the supplied locations array and returns it.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.test.context.ContextLoader

Public Constructors

public AbstractContextLoader ()

Public Methods

public final String[] processLocations (Class<?> clazz, String... locations)

If the supplied locations are null or empty and isGenerateDefaultLocations() is true, default locations will be generated for the specified class and the configured resource suffix; otherwise, the supplied locations will be modified if necessary and returned.

Parameters
clazz the class with which the locations are associated: to be used when generating default locations
locations the unmodified locations to use for loading the application context (can be null or empty)
Returns
  • an array of application context resource locations

Protected Methods

protected String[] generateDefaultLocations (Class<?> clazz)

Generates the default classpath resource locations array based on the supplied class.

For example, if the supplied class is com.example.MyTest, the generated locations will contain a single string with a value of "classpath:/com/example/MyTest<suffix>", where <suffix> is the value of the resource suffix string.

Subclasses can override this method to implement a different default location generation strategy.

Parameters
clazz the class for which the default locations are to be generated
Returns
  • an array of default application context resource locations

protected abstract String getResourceSuffix ()

Get the suffix to append to ApplicationContext resource locations when generating default locations.

Must be implemented by subclasses.

Returns
  • the resource suffix; should not be null or empty

protected boolean isGenerateDefaultLocations ()

Determine whether or not default resource locations should be generated if the locations provided to #processLocations(Class,String...) processLocations() are null or empty.

Can be overridden by subclasses to change the default behavior.

Returns
  • always true by default

protected String[] modifyLocations (Class<?> clazz, String... locations)

Generate a modified version of the supplied locations array and returns it.

A plain path, e.g. "context.xml", will be treated as a classpath resource from the same package in which the specified class is defined. A path starting with a slash is treated as a fully qualified class path location, e.g.: "/org/springframework/whatever/foo.xml". A path which references a URL (e.g., a path prefixed with classpath:, file:, http:, etc.) will be added to the results unchanged.

Subclasses can override this method to implement a different location modification strategy.

Parameters
clazz the class with which the locations are associated
locations the resource locations to be modified
Returns
  • an array of modified application context resource locations