Package org.springframework.test.context
Class ContextConfigurationAttributes
- java.lang.Object
- org.springframework.test.context.ContextConfigurationAttributes
public class ContextConfigurationAttributes extends Object
ContextConfigurationAttributesencapsulates 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 newContextConfigurationAttributesinstance with default values.ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass)Construct a newContextConfigurationAttributesinstance for the test class that declared the@ContextConfigurationannotation and its corresponding attributes.ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass)Construct a newContextConfigurationAttributesinstance for the test class that declared the@ContextConfigurationannotation and its corresponding attributes.ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs)Construct a newContextConfigurationAttributesinstance for the suppliedAnnotationAttributes(parsed from a@ContextConfigurationannotation) and the test class that declared them.ContextConfigurationAttributes(Class<?> declaringClass, ContextConfiguration contextConfiguration)Construct a newContextConfigurationAttributesinstance for the supplied@ContextConfigurationannotation and the test class that declared it.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)Determine if the supplied object is equal to thisContextConfigurationAttributesinstance 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 theContextLoaderclass that was declared via@ContextConfiguration.Class<?>getDeclaringClass()Get the class that declared the@ContextConfigurationannotation, either explicitly or implicitly.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]getInitializers()Get theApplicationContextInitializerclasses that were declared via@ContextConfiguration.String[]getLocations()Get the resource locations that were declared via@ContextConfiguration.StringgetName()Get the name of the context hierarchy level that was declared via@ContextConfiguration.booleanhasClasses()Determine if thisContextConfigurationAttributesinstance has class-based resources.inthashCode()Generate a unique hash code for all properties of thisContextConfigurationAttributesinstance excluding the name.booleanhasLocations()Determine if thisContextConfigurationAttributesinstance has path-based resource locations.booleanhasResources()Determine if thisContextConfigurationAttributesinstance has either path-based resource locations or class-based resources.booleanisInheritInitializers()Get theinheritInitializersflag that was declared via@ContextConfiguration.booleanisInheritLocations()Get theinheritLocationsflag that was declared via@ContextConfiguration.voidsetClasses(Class<?>... classes)Set the processed annotated classes, effectively overriding the original value declared via@ContextConfiguration.voidsetLocations(String... locations)Set the processed resource locations, effectively overriding the original value declared via@ContextConfiguration.StringtoString()Provide a String representation of the context configuration attributes and declaring class.
Constructor Detail
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass)
Construct a newContextConfigurationAttributesinstance 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 newContextConfigurationAttributesinstance for the supplied@ContextConfigurationannotation and the test class that declared it.- Parameters:
declaringClass- the test class that declared@ContextConfigurationcontextConfiguration- the annotation from which to retrieve the attributes
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs)
Construct a newContextConfigurationAttributesinstance for the suppliedAnnotationAttributes(parsed from a@ContextConfigurationannotation) and the test class that declared them.- Parameters:
declaringClass- the test class that declared@ContextConfigurationannAttrs- the annotation attributes from which to retrieve the attributes
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass)
Construct a newContextConfigurationAttributesinstance for the test class that declared the@ContextConfigurationannotation and its corresponding attributes.- Parameters:
declaringClass- the test class that declared@ContextConfigurationlocations- the resource locations declared via@ContextConfigurationclasses- the annotated classes declared via@ContextConfigurationinheritLocations- theinheritLocationsflag declared via@ContextConfigurationinitializers- the context initializers declared via@ContextConfigurationinheritInitializers- theinheritInitializersflag declared via@ContextConfigurationcontextLoaderClass- theContextLoaderclass declared via@ContextConfiguration- Throws:
IllegalArgumentException- if thedeclaringClassorcontextLoaderClassisnull
ContextConfigurationAttributes
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass)
Construct a newContextConfigurationAttributesinstance for the test class that declared the@ContextConfigurationannotation and its corresponding attributes.- Parameters:
declaringClass- the test class that declared@ContextConfigurationlocations- the resource locations declared via@ContextConfigurationclasses- the annotated classes declared via@ContextConfigurationinheritLocations- theinheritLocationsflag declared via@ContextConfigurationinitializers- the context initializers declared via@ContextConfigurationinheritInitializers- theinheritInitializersflag declared via@ContextConfigurationname- the name of level in the context hierarchy, ornullif not applicablecontextLoaderClass- theContextLoaderclass declared via@ContextConfiguration- Throws:
IllegalArgumentException- if thedeclaringClassorcontextLoaderClassisnull
Method Detail
getDeclaringClass
public Class<?> getDeclaringClass()
Get the class that declared the@ContextConfigurationannotation, 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
nullor empty - See Also:
ContextConfiguration.classes(),setClasses(Class[])
hasClasses
public boolean hasClasses()
Determine if thisContextConfigurationAttributesinstance has class-based resources.- Returns:
trueif theclassesarray 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
nullor empty - See Also:
ContextConfiguration.value(),ContextConfiguration.locations(),setLocations(String[])
hasLocations
public boolean hasLocations()
Determine if thisContextConfigurationAttributesinstance has path-based resource locations.- Returns:
trueif thelocationsarray is not empty- See Also:
hasResources(),hasClasses()
hasResources
public boolean hasResources()
Determine if thisContextConfigurationAttributesinstance has either path-based resource locations or class-based resources.- Returns:
trueif either thelocationsor theclassesarray is not empty- See Also:
hasLocations(),hasClasses()
isInheritLocations
public boolean isInheritLocations()
Get theinheritLocationsflag that was declared via@ContextConfiguration.- Returns:
- the
inheritLocationsflag - See Also:
ContextConfiguration.inheritLocations()
getInitializers
public Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] getInitializers()
Get theApplicationContextInitializerclasses that were declared via@ContextConfiguration.- Returns:
- the
ApplicationContextInitializerclasses - Since:
- 3.2
isInheritInitializers
public boolean isInheritInitializers()
Get theinheritInitializersflag that was declared via@ContextConfiguration.- Returns:
- the
inheritInitializersflag - Since:
- 3.2
getName
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
nullif not applicable - Since:
- 3.2.2
- See Also:
ContextConfiguration.name()
getContextLoaderClass
public Class<? extends ContextLoader> getContextLoaderClass()
Get theContextLoaderclass that was declared via@ContextConfiguration.- Returns:
- the
ContextLoaderclass - See Also:
ContextConfiguration.loader()
equals
public boolean equals(Object other)
Determine if the supplied object is equal to thisContextConfigurationAttributesinstance 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 thisContextConfigurationAttributesinstance excluding the name.