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 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>conversionContextProviderThe 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 voidannounceCallResults(VariableVariable aDefaultTargetVariable, List<NamedCallResult> someNamedTargetVariables)Invoke theResultAwareFixturemethod for the case of a 'call' type fixture invocation, if the fixture is aResultAwareFixture.voidannounceTableTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, List<ResultTableHeader> someResultHeaders)Invoke theResultAwareFixturemethod for the case of a 'tabletest' type fixture invocation.voidannounceTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, List<NamedResult> someNamedResults)Invoke theResultAwareFixturemethod for the case of a 'test' type fixture invocation, if the fixture is aResultAwareFixture.protected voidannounceTestResultsInternal(ValueOrEnumValueOrOperationCollection aDefaultResult, Set<String> aNamedResultSet)Actually performs the test result announcement call.voidconvertParameterValuesToFixtureDefinedTypes(Method aFixtureMethod, Map<String,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.Class<?>determineCustomConversionTargetType(Object aFixtureResult, String aMethodName, 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.Objectexecute(Map<String,Object> someParameters)Executes the fixture method, using the given set of parameters.protected Class<?>getFixtureClass()protected ObjectgetFixtureInstance()booleanisCustomComparatorAndConversionFixture()Checks whether the wrapped fixture is aCustomComparatorAndConversionFixture.booleanisCustomComparatorFixture()Checks whether the wrapped fixture is aCustomComparatorFixture.booleanisCustomStringConversionFixture()Checks whether the wrapped fixture is aCustomStringConversionFixture.booleanisFinalizationTestFixture()Checks whether the wrapped fixture is aisFinalizationTestFixture().booleanisResultAwareFixture()Checks whether the wrapped fixture is aResultAwareFixture.ComparisonResultperformCustomComparation(Object anExpectedResult, Object aFixtureResult, String aMethodName, String aPropertyName)Performs a custom comparation using the wrapped fixture, which must be aCustomComparatorFixture.protected voidperformNullCheck(FixtureParameter anAnnotation, Object aValue)Validates given parameter values to comply with theFixtureParameter.nullable()setting.FormattedStringperformValueToFormattedStringConversion(Object aValue, String aFixtureMethod, boolean aForceIntermediateMapFlag, ConversionContext aConversionContext)Converts the given value to a string.voidrelease()Releases the fixture instance.List<ExtendedResultFixture.ExtendedResult>retrieveExtendedResults(ExtendedResultFixture.FixtureInvocationResult anInvocationResult)CallExtendedResultFixture#provideExtendedResults()on the fixture - if it is an extended result fixture - and return the extended results.StringrunFinalizationTest()Executes the finalization test forFinalizationTestFixtures.
-
-
-
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 InstantiationException, IllegalAccessException, 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:
InstantiationExceptionIllegalAccessExceptionClassNotFoundException
-
-
Method Detail
-
release
public void release()
Releases the fixture instance.
-
getFixtureClass
protected Class<?> getFixtureClass()
-
getFixtureInstance
protected 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(Object anExpectedResult, Object aFixtureResult, String aMethodName, 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 Class<?> determineCustomConversionTargetType(Object aFixtureResult, String aMethodName, 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 forCustomComparatorAndConversionFixtureinstances, 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(Object aValue, 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 theCustomStringConversionFixtureinterface.- 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 Object execute(Map<String,Object> someParameters) throws Throwable
Executes the fixture method, using the given set of parameters.- Parameters:
someParameters- a map of parameters- Returns:
- the resulting object
- Throws:
Throwable
-
convertParameterValuesToFixtureDefinedTypes
public void convertParameterValuesToFixtureDefinedTypes(Method aFixtureMethod, Map<String,Object> aParameterMap, boolean anIncludeArbitraryParametersFlag) throws ParameterUtil.UnresolvableVariableException, ClassNotFoundException, UnexecutableException, 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:
InstantiationExceptionUnexecutableExceptionClassNotFoundExceptionParameterUtil.UnresolvableVariableException
-
performNullCheck
protected void performNullCheck(FixtureParameter anAnnotation, 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 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, List<NamedCallResult> someNamedTargetVariables)
Invoke theResultAwareFixturemethod for the case of a 'call' type fixture invocation, if the fixture is aResultAwareFixture.
-
announceTestResults
public void announceTestResults(ValueOrEnumValueOrOperationCollection aDefaultResult, List<NamedResult> someNamedResults)
Invoke theResultAwareFixturemethod 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, List<ResultTableHeader> someResultHeaders)
Invoke theResultAwareFixturemethod 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, Set<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 String runFinalizationTest()
Executes the finalization test forFinalizationTestFixtures.- Returns:
- null if successful, an error message otherwise
-
-