Package org.springframework.test.context
Class ContextConfigurationAttributes
java.lang.Object
org.springframework.test.context.ContextConfigurationAttributes
ContextConfigurationAttributes
encapsulates the context configuration
attributes declared via @ContextConfiguration
.- Since:
- 3.1
- Author:
- Sam Brannen, Phillip Webb
- See Also:
-
Constructor Summary
ConstructorDescriptionContextConfigurationAttributes
(Class<?> declaringClass) Construct a newContextConfigurationAttributes
instance with default values.ContextConfigurationAttributes
(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<?>>[] initializers, boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) Construct a newContextConfigurationAttributes
instance for the test class that declared the@ContextConfiguration
annotation and its corresponding attributes.ContextConfigurationAttributes
(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<?>>[] initializers, boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass) Construct a newContextConfigurationAttributes
instance for the test class that declared the@ContextConfiguration
annotation and its corresponding attributes.ContextConfigurationAttributes
(Class<?> declaringClass, AnnotationAttributes annAttrs) Construct a newContextConfigurationAttributes
instance for the suppliedAnnotationAttributes
(parsed from a@ContextConfiguration
annotation) and the test class that declared them.ContextConfigurationAttributes
(Class<?> declaringClass, ContextConfiguration contextConfiguration) Construct a newContextConfigurationAttributes
instance for the supplied@ContextConfiguration
annotation and the test class that declared it. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine if the supplied object is equal to thisContextConfigurationAttributes
instance by comparing both object's declaring class, locations, annotated classes, inheritLocations flag, context initializer classes, inheritInitializers flag, and theContextLoader class
.Class<?>[]
Get the annotated classes that were declared via@ContextConfiguration
.Class<? extends ContextLoader>
Get theContextLoader
class that was declared via@ContextConfiguration
.Class<?>
Get the class that declared the@ContextConfiguration
annotation, either explicitly or implicitly.Class<? extends ApplicationContextInitializer<?>>[]
Get theApplicationContextInitializer
classes that were declared via@ContextConfiguration
.String[]
Get the resource locations that were declared via@ContextConfiguration
.getName()
Get the name of the context hierarchy level that was declared via@ContextConfiguration
.boolean
Determine if thisContextConfigurationAttributes
instance has class-based resources.int
hashCode()
Generate a unique hash code for all properties of thisContextConfigurationAttributes
instance excluding the name.boolean
Determine if thisContextConfigurationAttributes
instance has path-based resource locations.boolean
Determine if thisContextConfigurationAttributes
instance has either path-based resource locations or class-based resources.boolean
Get theinheritInitializers
flag that was declared via@ContextConfiguration
.boolean
Get theinheritLocations
flag that was declared via@ContextConfiguration
.void
setClasses
(Class<?>... classes) Set the processed annotated classes, effectively overriding the original value declared via@ContextConfiguration
.void
setLocations
(String... locations) Set the processed resource locations, effectively overriding the original value declared via@ContextConfiguration
.toString()
Provide a String representation of the context configuration attributes and declaring class.
-
Constructor Details
-
ContextConfigurationAttributes
Construct a newContextConfigurationAttributes
instance with default values.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
, either explicitly or implicitly- Since:
- 4.3
-
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, ContextConfiguration contextConfiguration) Construct a newContextConfigurationAttributes
instance for the supplied@ContextConfiguration
annotation and the test class that declared it.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
contextConfiguration
- the annotation from which to retrieve the attributes
-
ContextConfigurationAttributes
Construct a newContextConfigurationAttributes
instance for the suppliedAnnotationAttributes
(parsed from a@ContextConfiguration
annotation) and the test class that declared them.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
annAttrs
- the annotation attributes from which to retrieve the attributes
-
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<?>>[] initializers, boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) Construct a newContextConfigurationAttributes
instance for the test class that declared the@ContextConfiguration
annotation and its corresponding attributes.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
locations
- the resource locations declared via@ContextConfiguration
classes
- the annotated classes declared via@ContextConfiguration
inheritLocations
- theinheritLocations
flag declared via@ContextConfiguration
initializers
- the context initializers declared via@ContextConfiguration
inheritInitializers
- theinheritInitializers
flag declared via@ContextConfiguration
contextLoaderClass
- theContextLoader
class declared via@ContextConfiguration
- Throws:
IllegalArgumentException
- if thedeclaringClass
orcontextLoaderClass
isnull
-
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<?>>[] initializers, boolean inheritInitializers, @Nullable String name, Class<? extends ContextLoader> contextLoaderClass) Construct a newContextConfigurationAttributes
instance for the test class that declared the@ContextConfiguration
annotation and its corresponding attributes.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
locations
- the resource locations declared via@ContextConfiguration
classes
- the annotated classes declared via@ContextConfiguration
inheritLocations
- theinheritLocations
flag declared via@ContextConfiguration
initializers
- the context initializers declared via@ContextConfiguration
inheritInitializers
- theinheritInitializers
flag declared via@ContextConfiguration
name
- the name of level in the context hierarchy, ornull
if not applicablecontextLoaderClass
- theContextLoader
class declared via@ContextConfiguration
- Throws:
IllegalArgumentException
- if thedeclaringClass
orcontextLoaderClass
isnull
-
-
Method Details
-
getDeclaringClass
Get the class that declared the@ContextConfiguration
annotation, either explicitly or implicitly.- Returns:
- the declaring class (never
null
)
-
setClasses
Set the processed annotated classes, effectively overriding the original value declared via@ContextConfiguration
.- See Also:
-
getClasses
Get the annotated classes that were declared via@ContextConfiguration
.Note: this is a mutable property. The returned value may therefore represent a processed value that does not match the original value declared via
@ContextConfiguration
.- Returns:
- the annotated classes (potentially {empty)
- See Also:
-
hasClasses
public boolean hasClasses()Determine if thisContextConfigurationAttributes
instance has class-based resources.- Returns:
true
if theclasses
array is not empty- See Also:
-
setLocations
Set the processed resource locations, effectively overriding the original value declared via@ContextConfiguration
.- See Also:
-
getLocations
Get the resource locations that were declared via@ContextConfiguration
.Note: this is a mutable property. The returned value may therefore represent a processed value that does not match the original value declared via
@ContextConfiguration
.- Returns:
- the resource locations (potentially empty)
- See Also:
-
hasLocations
public boolean hasLocations()Determine if thisContextConfigurationAttributes
instance has path-based resource locations.- Returns:
true
if thelocations
array is not empty- See Also:
-
hasResources
public boolean hasResources()Determine if thisContextConfigurationAttributes
instance has either path-based resource locations or class-based resources. -
isInheritLocations
public boolean isInheritLocations()Get theinheritLocations
flag that was declared via@ContextConfiguration
.- Returns:
- the
inheritLocations
flag - See Also:
-
getInitializers
Get theApplicationContextInitializer
classes that were declared via@ContextConfiguration
.- Returns:
- the
ApplicationContextInitializer
classes - Since:
- 3.2
-
isInheritInitializers
public boolean isInheritInitializers()Get theinheritInitializers
flag that was declared via@ContextConfiguration
.- Returns:
- the
inheritInitializers
flag - Since:
- 3.2
-
getName
Get the name of the context hierarchy level that was declared via@ContextConfiguration
.- Returns:
- the name of the context hierarchy level or
null
if not applicable - Since:
- 3.2.2
- See Also:
-
getContextLoaderClass
Get theContextLoader
class that was declared via@ContextConfiguration
.- Returns:
- the
ContextLoader
class - See Also:
-
equals
Determine if the supplied object is equal to thisContextConfigurationAttributes
instance by comparing both object's declaring class, locations, annotated classes, inheritLocations flag, context initializer classes, inheritInitializers flag, and theContextLoader class
. -
hashCode
public int hashCode()Generate a unique hash code for all properties of thisContextConfigurationAttributes
instance excluding the name. -
toString
Provide a String representation of the context configuration attributes and declaring class.
-