Package de.cuioss.test.valueobjects
Class MapperTest<M extends Function<S,T>,S,T>
java.lang.Object
de.cuioss.test.valueobjects.MapperTest<M,S,T>
- Type Parameters:
M
- Mapper: The type of the MapperS
- Source: The type of the source-Objects to be mapped fromT
- Target: The type of the source-Objects to be mapped to
- All Implemented Interfaces:
TestObjectProvider<M>
,GeneratorRegistry
public class MapperTest<M extends Function<S,T>,S,T>
extends Object
implements GeneratorRegistry, TestObjectProvider<M>
Allows to test a mapper implementing a
Function
to map a (pseudo-)DTO
object based on whatever technology (FHIR, ...) to a DTO object. The actual
test-method is verifyMapper()
. The mapper-test-configuration is
defined with VerifyMapperConfiguration
For simple uses-case, like well designed beans there is no special
configuration needed
- In case the mapper needs to be configured in a special way (not using the
default constructor) you can overwrite
getUnderTest()
- The metadata / creation of the source objects can be adjusted in
multiple ways:
PropertyMetadata
: The annotations on class level affect the metadata for the source-objectsresolveSourcePropertyMetadata()
: can be overwritten as an alternative for usingPropertyMetadata
annotationsgetSourceInstantiator(RuntimeProperties)
: If not overwritten the default implementation chooses theBeanInstantiator
in order to generate source-objects.
- The metadata target objects is derived by reflection.
Caution: For more complex objects that can not be created by the
generator framework you must provide either a
TypedGenerator
, seeGeneratorRegistry
or overwriteanyTargetObject()
- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionParameterizedInstantiator<? extends S>
getSourceInstantiator
(RuntimeProperties runtimeProperties) protected void
Reads the type information and fills the fields#getMapperClass()
,#getSourceClass()
,#getTargetClass()
.Resolves thePropertyMetadata
for the source objects by using reflection and the annotationsPropertyConfig
and /PropertyConfigs
if provided.Resolves thePropertyMetadata
for the target objects by using reflectionvoid
Shorthand for callingverifyMapper(PropertyReflectionConfig)
withnull
void
verifyMapper
(PropertyReflectionConfig targetConfig) The actual test-method to be runMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.cuioss.test.valueobjects.util.GeneratorRegistry
registerAdditionalGenerators
-
Constructor Details
-
MapperTest
public MapperTest()
-
-
Method Details
-
intializeTypeInformation
Reads the type information and fills the fields#getMapperClass()
,#getSourceClass()
,#getTargetClass()
. It runs it checks only once -
verifyMapper
Shorthand for callingverifyMapper(PropertyReflectionConfig)
withnull
-
verifyMapper
The actual test-method to be run- Parameters:
targetConfig
- providing configuration, may be null
-
getUnderTest
- Specified by:
getUnderTest
in interfaceTestObjectProvider<M extends Function<S,
T>> - Returns:
- the bean to be tested. Usually instantiated by Inject or other concrete
-
resolveSourcePropertyMetadata
Resolves thePropertyMetadata
for the source objects by using reflection and the annotationsPropertyConfig
and /PropertyConfigs
if provided.- Returns:
- a
List
ofPropertyMetadata
defining the base line for the configured attributes
-
resolveTargetPropertyMetadata
Resolves thePropertyMetadata
for the target objects by using reflection- Parameters:
config
- providing configuration, may be null- Returns:
- a
List
ofPropertyMetadata
defining the base line for the configured attributes
-
anyTargetObject
- Returns:
- a target object to be used for reflection based resolving of
PropertyMetadata
. The default implementation uses theGeneratorRegistry
in order to instantiate a corresponding object. For more complex objects you should add a correspondingTypedGenerator
, seeGeneratorRegistry
-
getSourceInstantiator
public ParameterizedInstantiator<? extends S> getSourceInstantiator(RuntimeProperties runtimeProperties) - Parameters:
runtimeProperties
- to be used for creating theParameterizedInstantiator
- Returns:
- the
ParameterizedInstantiator
to be used for instantiating source-object. If not overwritten it default to the beanInstantiator
-