Package de.gebit.integrity.fixtures
Class FixtureWrapper<C>
- java.lang.Object
-
- de.gebit.integrity.fixtures.FixtureWrapper<C>
-
- Type Parameters:
C
- the fixture class
public class FixtureWrapper<C> extends java.lang.Object
This wrapper is used to encapsulate fixture instances.- Author:
- Rene Schneider - initial API and implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.inject.Provider<ConversionContext>
conversionContextProvider
The conversion context provider.
-
Constructor Summary
Constructors Constructor Description FixtureWrapper(MethodReference aMethodReference, com.google.inject.Injector anInjector)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
announceCallResults(VariableVariable aDefaultTargetVariable, java.util.List<NamedCallResult> someNamedTargetVariables)
Invoke theResultAwareFixture
method for the case of a 'call' type fixture invocation, if the fixture is aResultAwareFixture
.void
announceTableTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.List<ResultTableHeader> someResultHeaders)
Invoke theResultAwareFixture
method for the case of a 'tabletest' type fixture invocation.void
announceTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.List<NamedResult> someNamedResults)
Invoke theResultAwareFixture
method for the case of a 'test' type fixture invocation, if the fixture is aResultAwareFixture
.protected void
announceTestResultsInternal(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.Set<java.lang.String> aNamedResultSet)
Actually performs the test result announcement call.void
convertParameterValuesToFixtureDefinedTypes(java.lang.reflect.Method aFixtureMethod, java.util.Map<java.lang.String,java.lang.Object> aParameterMap, boolean anIncludeArbitraryParametersFlag)
Replaces all values in the given parameter map with converted versions that match the types that are expected by the given fixture method.java.lang.Class<?>
determineCustomConversionTargetType(java.lang.Object aFixtureResult, java.lang.String aMethodName, java.lang.String aPropertyName)
Returns the type to which the expected result (the data given in the test script) that corresponds to the given fixture result is to be converted.java.lang.Object
execute(java.util.Map<java.lang.String,java.lang.Object> someParameters)
Executes the fixture method, using the given set of parameters.protected java.lang.Class<?>
getFixtureClass()
protected java.lang.Object
getFixtureInstance()
boolean
isCustomComparatorAndConversionFixture()
Checks whether the wrapped fixture is aCustomComparatorAndConversionFixture
.boolean
isCustomComparatorFixture()
Checks whether the wrapped fixture is aCustomComparatorFixture
.boolean
isCustomStringConversionFixture()
Checks whether the wrapped fixture is aCustomStringConversionFixture
.boolean
isFinalizationTestFixture()
Checks whether the wrapped fixture is aisFinalizationTestFixture()
.boolean
isResultAwareFixture()
Checks whether the wrapped fixture is aResultAwareFixture
.ComparisonResult
performCustomComparation(java.lang.Object anExpectedResult, java.lang.Object aFixtureResult, java.lang.String aMethodName, java.lang.String aPropertyName)
Performs a custom comparation using the wrapped fixture, which must be aCustomComparatorFixture
.protected void
performNullCheck(FixtureParameter anAnnotation, java.lang.Object aValue)
Validates given parameter values to comply with theFixtureParameter.nullable()
setting.FormattedString
performValueToFormattedStringConversion(java.lang.Object aValue, java.lang.String aFixtureMethod, boolean aForceIntermediateMapFlag, ConversionContext aConversionContext)
Converts the given value to a string.void
release()
Releases the fixture instance.java.util.List<ExtendedResultFixture.ExtendedResult>
retrieveExtendedResults(ExtendedResultFixture.FixtureInvocationResult anInvocationResult)
CallExtendedResultFixture#provideExtendedResults()
on the fixture - if it is an extended result fixture - and return the extended results.java.lang.String
runFinalizationTest()
Executes the finalization test forFinalizationTestFixture
s.
-
-
-
Field Detail
-
conversionContextProvider
@Inject protected com.google.inject.Provider<ConversionContext> conversionContextProvider
The conversion context provider.
-
-
Constructor Detail
-
FixtureWrapper
public FixtureWrapper(MethodReference aMethodReference, com.google.inject.Injector anInjector) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
Creates a new instance. This also instantiates the given fixture class!- Parameters:
aMethodReference
- the fixture method reference to be wrappedanInjector
- The injector required to inject dependencies into fixture instances and factories. (I don't really like to provide this explicitly here, but cannot use injection, since that happens after the constructor. Maybe I'll refactor this some time later...)- Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
-
-
Method Detail
-
release
public void release()
Releases the fixture instance.
-
getFixtureClass
protected java.lang.Class<?> getFixtureClass()
-
getFixtureInstance
protected java.lang.Object getFixtureInstance()
-
isCustomComparatorFixture
public boolean isCustomComparatorFixture()
Checks whether the wrapped fixture is aCustomComparatorFixture
.- Returns:
- true if it is
-
isCustomComparatorAndConversionFixture
public boolean isCustomComparatorAndConversionFixture()
Checks whether the wrapped fixture is aCustomComparatorAndConversionFixture
.- Returns:
- true if it is
-
isCustomStringConversionFixture
public boolean isCustomStringConversionFixture()
Checks whether the wrapped fixture is aCustomStringConversionFixture
.- Returns:
- true if it is
-
isResultAwareFixture
public boolean isResultAwareFixture()
Checks whether the wrapped fixture is aResultAwareFixture
.- Returns:
- true if it is
-
isFinalizationTestFixture
public boolean isFinalizationTestFixture()
Checks whether the wrapped fixture is aisFinalizationTestFixture()
.- Returns:
- true if it is
-
performCustomComparation
public ComparisonResult performCustomComparation(java.lang.Object anExpectedResult, java.lang.Object aFixtureResult, java.lang.String aMethodName, java.lang.String aPropertyName)
Performs a custom comparation using the wrapped fixture, which must be aCustomComparatorFixture
. Only usable ifisCustomComparatorFixture()
returns true.- Parameters:
anExpectedResult
- the expected resultaFixtureResult
- the result actually returned by the fixtureaMethodName
- the name of the fixture methodaPropertyName
- the name of the result property to be compared (null if it's the default result)- Returns:
- true if comparation was successful, false otherwise
-
determineCustomConversionTargetType
public java.lang.Class<?> determineCustomConversionTargetType(java.lang.Object aFixtureResult, java.lang.String aMethodName, java.lang.String aPropertyName)
Returns the type to which the expected result (the data given in the test script) that corresponds to the given fixture result is to be converted. This can only be used forCustomComparatorAndConversionFixture
instances, which can be checked viaisCustomComparatorAndConversionFixture()
.- Parameters:
aFixtureResult
- the result value returned by the fixture callaMethodName
- the fixture method that was calledaPropertyName
- the property name that is to be compared (null if it's the default result)- Returns:
- the desired target type. "null" chooses the default conversion, but note that this does NOT mean "the
conversion that would have been used if the fixture was just a
CustomComparatorFixture
", but "the conversion that has the highest priority for the data type found in the script".
-
performValueToFormattedStringConversion
public FormattedString performValueToFormattedStringConversion(java.lang.Object aValue, java.lang.String aFixtureMethod, boolean aForceIntermediateMapFlag, ConversionContext aConversionContext)
Converts the given value to a string. This method either calls theValueConverter#convertValueToString(Object, ConversionContext)
method or delegates the conversion to the contained fixture instance, if it does implement theCustomStringConversionFixture
interface.- Parameters:
aValue
- the value to convertaFixtureMethod
- the fixture method that was called to return the given valueaForceIntermediateMapFlag
- whether the conversion should force the usage of an intermediate map (useful for bean types)aConversionContext
- the conversion context to use (may be null if the default shall be used)- Returns:
- the converted string
-
execute
public java.lang.Object execute(java.util.Map<java.lang.String,java.lang.Object> someParameters) throws java.lang.Throwable
Executes the fixture method, using the given set of parameters.- Parameters:
someParameters
- a map of parameters- Returns:
- the resulting object
- Throws:
java.lang.Throwable
-
convertParameterValuesToFixtureDefinedTypes
public void convertParameterValuesToFixtureDefinedTypes(java.lang.reflect.Method aFixtureMethod, java.util.Map<java.lang.String,java.lang.Object> aParameterMap, boolean anIncludeArbitraryParametersFlag) throws ParameterUtil.UnresolvableVariableException, java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException
Replaces all values in the given parameter map with converted versions that match the types that are expected by the given fixture method.- Parameters:
aFixtureMethod
- the methodaParameterMap
- the parameter mapanIncludeArbitraryParametersFlag
- whether arbitrary parameters shall be included- Throws:
java.lang.InstantiationException
UnexecutableException
java.lang.ClassNotFoundException
ParameterUtil.UnresolvableVariableException
-
performNullCheck
protected void performNullCheck(FixtureParameter anAnnotation, java.lang.Object aValue)
Validates given parameter values to comply with theFixtureParameter.nullable()
setting.- Parameters:
anAnnotation
- the fixture parameter annotation setting the rulesaValue
- the parameter value
-
retrieveExtendedResults
public java.util.List<ExtendedResultFixture.ExtendedResult> retrieveExtendedResults(ExtendedResultFixture.FixtureInvocationResult anInvocationResult)
CallExtendedResultFixture#provideExtendedResults()
on the fixture - if it is an extended result fixture - and return the extended results.- Returns:
- the extended result list, or null if the fixture does not support the protocol or didn't return anything
-
announceCallResults
public void announceCallResults(VariableVariable aDefaultTargetVariable, java.util.List<NamedCallResult> someNamedTargetVariables)
Invoke theResultAwareFixture
method for the case of a 'call' type fixture invocation, if the fixture is aResultAwareFixture
.
-
announceTestResults
public void announceTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.List<NamedResult> someNamedResults)
Invoke theResultAwareFixture
method for the case of a 'test' type fixture invocation, if the fixture is aResultAwareFixture
.- Parameters:
aDefaultResult
- The default result as given in the test scriptsomeNamedResults
- A list of named results used by the test
-
announceTableTestResults
public void announceTableTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.List<ResultTableHeader> someResultHeaders)
Invoke theResultAwareFixture
method for the case of a 'tabletest' type fixture invocation.- Parameters:
aDefaultResult
- The default result as given in the test scriptsomeResultHeaders
- A list of named results used by the test
-
announceTestResultsInternal
protected void announceTestResultsInternal(ValueOrEnumValueOrOperationCollection aDefaultResult, java.util.Set<java.lang.String> aNamedResultSet)
Actually performs the test result announcement call.- Parameters:
aDefaultResult
- The default result as given in the test scriptaNamedResultSet
- A list of named results used by the test
-
runFinalizationTest
public java.lang.String runFinalizationTest()
Executes the finalization test forFinalizationTestFixture
s.- Returns:
- null if successful, an error message otherwise
-
-