Package org.springframework.test.context
Class ContextConfigurationAttributes
- java.lang.Object
- org.springframework.test.context.ContextConfigurationAttributes
public class ContextConfigurationAttributes extends Object
ContextConfigurationAttributes
encapsulates the context configuration attributes declared via@ContextConfiguration
.- Since:
- 3.1
- Author:
- Sam Brannen, Phillip Webb
- See Also:
ContextConfiguration
,SmartContextLoader.processContextConfiguration(ContextConfigurationAttributes)
,MergedContextConfiguration
Constructor Summary
Constructors Constructor Description ContextConfigurationAttributes(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
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<?>[]
getClasses()
Get the annotated classes that were declared via@ContextConfiguration
.Class<? extends ContextLoader>
getContextLoaderClass()
Get theContextLoader
class that was declared via@ContextConfiguration
.Class<?>
getDeclaringClass()
Get the class that declared the@ContextConfiguration
annotation, either explicitly or implicitly.Class<? extends ApplicationContextInitializer<?>>[]
getInitializers()
Get theApplicationContextInitializer
classes that were declared via@ContextConfiguration
.String[]
getLocations()
Get the resource locations that were declared via@ContextConfiguration
.String
getName()
Get the name of the context hierarchy level that was declared via@ContextConfiguration
.boolean
hasClasses()
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
hasLocations()
Determine if thisContextConfigurationAttributes
instance has path-based resource locations.boolean
hasResources()
Determine if thisContextConfigurationAttributes
instance has either path-based resource locations or class-based resources.boolean
isInheritInitializers()
Get theinheritInitializers
flag that was declared via@ContextConfiguration
.boolean
isInheritLocations()
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
.String
toString()
Provide a String representation of the context configuration attributes and declaring class.
Constructor Detail
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass)
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
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs)
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 Detail
getDeclaringClass
public Class<?> getDeclaringClass()
Get the class that declared the@ContextConfiguration
annotation, either explicitly or implicitly.- Returns:
- the declaring class (never
null
)
setClasses
public void setClasses(Class<?>... classes)
Set the processed annotated classes, effectively overriding the original value declared via@ContextConfiguration
.- See Also:
getClasses()
getClasses
public Class<?>[] 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:
ContextConfiguration.classes()
,setClasses(Class[])
hasClasses
public boolean hasClasses()
Determine if thisContextConfigurationAttributes
instance has class-based resources.- Returns:
true
if theclasses
array is not empty- See Also:
hasResources()
,hasLocations()
setLocations
public void setLocations(String... locations)
Set the processed resource locations, effectively overriding the original value declared via@ContextConfiguration
.- See Also:
getLocations()
getLocations
public String[] 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:
ContextConfiguration.value()
,ContextConfiguration.locations()
,setLocations(java.lang.String...)
hasLocations
public boolean hasLocations()
Determine if thisContextConfigurationAttributes
instance has path-based resource locations.- Returns:
true
if thelocations
array is not empty- See Also:
hasResources()
,hasClasses()
hasResources
public boolean hasResources()
Determine if thisContextConfigurationAttributes
instance has either path-based resource locations or class-based resources.- Returns:
true
if either thelocations
or theclasses
array is not empty- See Also:
hasLocations()
,hasClasses()
isInheritLocations
public boolean isInheritLocations()
Get theinheritLocations
flag that was declared via@ContextConfiguration
.- Returns:
- the
inheritLocations
flag - See Also:
ContextConfiguration.inheritLocations()
getInitializers
public Class<? extends ApplicationContextInitializer<?>>[] 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
@Nullable public String 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:
ContextConfiguration.name()
getContextLoaderClass
public Class<? extends ContextLoader> getContextLoaderClass()
Get theContextLoader
class that was declared via@ContextConfiguration
.- Returns:
- the
ContextLoader
class - See Also:
ContextConfiguration.loader()
equals
public boolean equals(@Nullable Object other)
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.