org.springframework.test.context
Class ContextConfigurationAttributes

java.lang.Object
  extended by org.springframework.test.context.ContextConfigurationAttributes

public class ContextConfigurationAttributes
extends java.lang.Object

ContextConfigurationAttributes encapsulates the context configuration attributes declared on a test class via @ContextConfiguration.

Since:
3.1
Author:
Sam Brannen
See Also:
ContextConfiguration, SmartContextLoader.processContextConfiguration(ContextConfigurationAttributes), MergedContextConfiguration

Field Summary
private  java.lang.Class<?>[] classes
           
private  java.lang.Class<? extends ContextLoader> contextLoaderClass
           
private  java.lang.Class<?> declaringClass
           
private  boolean inheritLocations
           
private  java.lang.String[] locations
           
private static Log logger
           
 
Constructor Summary
ContextConfigurationAttributes(java.lang.Class<?> declaringClass, ContextConfiguration contextConfiguration)
          Construct a new ContextConfigurationAttributes instance for the supplied @ContextConfiguration annotation and the test class that declared it.
ContextConfigurationAttributes(java.lang.Class<?> declaringClass, java.lang.String[] locations, java.lang.Class<?>[] classes, boolean inheritLocations, java.lang.Class<? extends ContextLoader> contextLoaderClass)
          Construct a new ContextConfigurationAttributes instance for the test class that declared the @ContextConfiguration annotation and its corresponding attributes.
 
Method Summary
 java.lang.Class<?>[] getClasses()
          Get the configuration classes that were declared via @ContextConfiguration.
 java.lang.Class<? extends ContextLoader> getContextLoaderClass()
          Get the ContextLoader class that was declared via @ContextConfiguration.
 java.lang.Class<?> getDeclaringClass()
          Get the class that declared the @ContextConfiguration annotation.
 java.lang.String[] getLocations()
          Get the resource locations that were declared via @ContextConfiguration.
 boolean hasClasses()
          Determine if this ContextConfigurationAttributes instance has class-based resources.
 boolean hasLocations()
          Determine if this ContextConfigurationAttributes instance has path-based resource locations.
 boolean hasResources()
          Determine if this ContextConfigurationAttributes instance has either path-based resource locations or class-based resources.
 boolean isInheritLocations()
          Get the inheritLocations flag that was declared via @ContextConfiguration.
private static java.lang.String[] resolveLocations(java.lang.Class<?> declaringClass, ContextConfiguration contextConfiguration)
          Resolve resource locations from the locations and value attributes of the supplied ContextConfiguration annotation.
 void setClasses(java.lang.Class<?>[] classes)
          Set the processed configuration classes, effectively overriding the original value declared via @ContextConfiguration.
 void setLocations(java.lang.String[] locations)
          Set the processed resource locations, effectively overriding the original value declared via @ContextConfiguration.
 java.lang.String toString()
          Provide a String representation of the context configuration attributes and declaring class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final Log logger

declaringClass

private final java.lang.Class<?> declaringClass

locations

private java.lang.String[] locations

classes

private java.lang.Class<?>[] classes

inheritLocations

private final boolean inheritLocations

contextLoaderClass

private final java.lang.Class<? extends ContextLoader> contextLoaderClass
Constructor Detail

ContextConfigurationAttributes

public ContextConfigurationAttributes(java.lang.Class<?> declaringClass,
                                      ContextConfiguration contextConfiguration)
Construct a new ContextConfigurationAttributes 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(java.lang.Class<?> declaringClass,
                                      java.lang.String[] locations,
                                      java.lang.Class<?>[] classes,
                                      boolean inheritLocations,
                                      java.lang.Class<? extends ContextLoader> contextLoaderClass)
Construct a new ContextConfigurationAttributes 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 configuration classes declared via @ContextConfiguration
inheritLocations - the inheritLocations flag declared via @ContextConfiguration
contextLoaderClass - the ContextLoader class declared via @ContextConfiguration
Throws:
java.lang.IllegalArgumentException - if the declaringClass or contextLoaderClass is null, or if the locations and classes are both non-empty
Method Detail

resolveLocations

private static java.lang.String[] resolveLocations(java.lang.Class<?> declaringClass,
                                                   ContextConfiguration contextConfiguration)
Resolve resource locations from the locations and value attributes of the supplied ContextConfiguration annotation.

Throws:
java.lang.IllegalStateException - if both the locations and value attributes have been declared

getDeclaringClass

public java.lang.Class<?> getDeclaringClass()
Get the class that declared the @ContextConfiguration annotation.

Returns:
the declaring class; never null

getLocations

public java.lang.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 null or empty
See Also:
ContextConfiguration.value(), ContextConfiguration.locations(), #setLocations()

setLocations

public void setLocations(java.lang.String[] locations)
Set the processed resource locations, effectively overriding the original value declared via @ContextConfiguration.

See Also:
getLocations()

getClasses

public java.lang.Class<?>[] getClasses()
Get the configuration 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 configuration classes; potentially null or empty
See Also:
ContextConfiguration.classes(), #setClasses()

setClasses

public void setClasses(java.lang.Class<?>[] classes)
Set the processed configuration classes, effectively overriding the original value declared via @ContextConfiguration.

See Also:
getClasses()

hasLocations

public boolean hasLocations()
Determine if this ContextConfigurationAttributes instance has path-based resource locations.

Returns:
true if the locations array is not empty
See Also:
hasResources(), hasClasses()

hasClasses

public boolean hasClasses()
Determine if this ContextConfigurationAttributes instance has class-based resources.

Returns:
true if the classes array is not empty
See Also:
hasResources(), hasLocations()

hasResources

public boolean hasResources()
Determine if this ContextConfigurationAttributes instance has either path-based resource locations or class-based resources.

Returns:
true if either the locations or the classes array is not empty
See Also:
hasLocations(), hasClasses()

isInheritLocations

public boolean isInheritLocations()
Get the inheritLocations flag that was declared via @ContextConfiguration.

Returns:
the inheritLocations flag
See Also:
ContextConfiguration.inheritLocations()

getContextLoaderClass

public java.lang.Class<? extends ContextLoader> getContextLoaderClass()
Get the ContextLoader class that was declared via @ContextConfiguration.

Returns:
the ContextLoader class
See Also:
ContextConfiguration.loader()

toString

public java.lang.String toString()
Provide a String representation of the context configuration attributes and declaring class.

Overrides:
toString in class java.lang.Object