org.unitils.util
Class AnnotationConfigLoader<A extends Annotation,CFG extends ResourceConfig>

java.lang.Object
  extended by org.unitils.util.AnnotationConfigLoader<A,CFG>
Type Parameters:
A - The annotation class used for configuring the resource on a test object
CFG - The type of the resource configuration class
All Implemented Interfaces:
ResourceConfigLoader<CFG>
Direct Known Subclasses:
HibernateAnnotationConfigLoader, JpaAnnotationConfigLoader

public abstract class AnnotationConfigLoader<A extends Annotation,CFG extends ResourceConfig>
extends Object
implements ResourceConfigLoader<CFG>

Loads the configuration of a resource that is configured on a test object, by reading class, method or field level annotations. Also supports custom configuration methods.

Author:
Filip Neven, Tim Ducheyne

Field Summary
protected  Class<A> annotationClass
          The annotation class used for configuring the resource on a test object
 
Constructor Summary
AnnotationConfigLoader(Class<A> annotationClass)
          Creates a new instance for the given annotation class
 
Method Summary
protected abstract  CFG createResourceConfig(A configuringAnnotation, Method customConfigMethod)
          Either the given configuring annotation or custom config method must not be null (may also both be not-null)
protected  Method getCustomConfigMethod(Class<?> testClass)
           
protected  CFG getResourceConfig(Class<?> testClass)
           
protected abstract  boolean isConfiguringAnnotation(A annotation)
           
protected abstract  boolean isCustomConfigMethod(Method annotatedMethod)
           
 CFG loadResourceConfig(Object testObject)
          Loads the resource configuration for the given test object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

annotationClass

protected Class<A extends Annotation> annotationClass
The annotation class used for configuring the resource on a test object

Constructor Detail

AnnotationConfigLoader

public AnnotationConfigLoader(Class<A> annotationClass)
Creates a new instance for the given annotation class

Parameters:
annotationClass - The class of the configuring annotation, not null
Method Detail

loadResourceConfig

public CFG loadResourceConfig(Object testObject)
Loads the resource configuration for the given test object

Specified by:
loadResourceConfig in interface ResourceConfigLoader<CFG extends ResourceConfig>
Parameters:
testObject - The test instance, not null
Returns:
The resource configuration, if available. Null if not.

getResourceConfig

protected CFG getResourceConfig(Class<?> testClass)
Parameters:
testClass - The test class, not null
Returns:
The resource config object

createResourceConfig

protected abstract CFG createResourceConfig(A configuringAnnotation,
                                            Method customConfigMethod)
Either the given configuring annotation or custom config method must not be null (may also both be not-null)

Parameters:
configuringAnnotation - Configuring annotation, if any
customConfigMethod - Custom config method, if any
Returns:
A new resource config object, given the configuring annotation and custom configuration method

getCustomConfigMethod

protected Method getCustomConfigMethod(Class<?> testClass)
Parameters:
testClass - The test class, not null
Returns:
The test class's custom configuration method, if any

isCustomConfigMethod

protected abstract boolean isCustomConfigMethod(Method annotatedMethod)
Parameters:
annotatedMethod - A method annotated with annotationClass
Returns:
True if the given method is a custom configuration method

isConfiguringAnnotation

protected abstract boolean isConfiguringAnnotation(A annotation)
Parameters:
annotation - Annotation of type annotationClass
Returns:
True if for the given annotation, the necessary attributes are filled so that it can be regarded as a configuring annotation


Copyright © 2011. All Rights Reserved.