Class IntegrationTestSuiteExtension
- java.lang.Object
-
- uk.gov.gchq.gaffer.integration.junit.extensions.IntegrationTestSuiteExtension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.ExecutionCondition
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
public class IntegrationTestSuiteExtension extends Object implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.ExecutionCondition
The
IntegrationTestSuiteExtension
retrieves theSchema
, theStoreProperties
and thetests-to-skip
Map
from theIntegrationTestSuite
class. The values are then used by the test classes from theSuite
on execution or to exclude the tests listed in the tests-to-skipMap
.The required
Schema
andStoreProperties
are injected in to the test instance before each test is run. This injection is either at field level (seebeforeEach(ExtensionContext)
) or asMethod
parameters (seeresolveParameter(ParameterContext, ExtensionContext)
).For the
tests-to-skip
Map
, each test method is checked before execution and if the methodMap.containsKey(Object)
then the test is omitted.In order to find the
Class
containing theSchema
, theStoreProperties
andtests-to-skip
Map
, theIntegrationTestSuiteExtension
must first instantiate theClass
. This is done through advertising theClass
name using aConfigurationParameter
. TheClass
must also extendIntegrationTestSuite
so the data can be retrieved by theIntegrationTestSuiteExtension
. For example:package integration.tests; import static uk.gov.gchq.gaffer.integration.junit.extensions.IntegrationTestSuiteExtension.INIT_CLASS; @Suite @SelectPackages("root.test.packages.to.search") @IncludeClassNamePatterns(".*IT") @ConfigurationParameter(key = INIT_CLASS, value = "integration.tests.IntegrationTestSuiteITs") public class IntegrationTestSuiteITs extends IntegrationTestSuite { public IntegrationTestSuiteITs() { setSchema(...); setStoreProperties(...); setTestsToSkip(...); } }
In this example, the
IntegrationTestSuite
Class
advertised is the same as theSuite
Class
. However, you can advertise anyClass
as long as it implementsIntegrationTestSuite
.
-
-
Field Summary
Fields Modifier and Type Field Description static String
INIT_CLASS
-
Constructor Summary
Constructors Constructor Description IntegrationTestSuiteExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
ThebeforeEach
Method
is called before each test method is run.org.junit.jupiter.api.extension.ConditionEvaluationResult
evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
TheevaluateExecutionCondition
Method
allows the disabling of tests if some condition is met.Object
resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
TheresolveParameter
Method
is called everytime a parameter passes thesupportsParameter(ParameterContext, ExtensionContext)
check.boolean
supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
ThesupportsParameter
Method
returnstrue
if the parameter is either aSchema
or aStoreProperties
orfalse
otherwise.
-
-
-
Field Detail
-
INIT_CLASS
public static final String INIT_CLASS
- See Also:
- Constant Field Values
-
-
Method Detail
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
The
beforeAll
Method
is used to load theClass
implementingIntegrationTestSuite
. This is required for injecting theSchema
andStoreProperties
and checking whether the tests are enabled using thetests-to-skip
Map
.The
beforeAll
method first checks if theINIT_CLASS
has been set and if so attempts to retrieve theIntegrationTestSuite
Object
from the cache. If the cache does not contain the instance then it attempts instantiation. If there are errors during the instantiation thenException
s are thrown and theSuite
fails.- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Parameters:
extensionContext
- the current extension context; nevernull
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
ThebeforeEach
Method
is called before each test method is run. In the case of theIntegrationTestSuiteExtension
, if any of the fields are annotated with the@InjectedFromStoreITsSuite
annotation, the value is checked to see if it isSchema
or aStoreProperties
and if so the value is made accessible before the test is run. If the value is not found then aParameterResolutionException
is thrown. For example:class TestIT { @InjectedFromStoreITsSuite Schema schema; @InjectedFromStoreITsSuite StoreProperties storeProperties; @Test void test() { .... } }
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Parameters:
context
- the current extension context; nevernull
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
ThesupportsParameter
Method
returnstrue
if the parameter is either aSchema
or aStoreProperties
orfalse
otherwise.- Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
- true if the parameter is found, false otherwise
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
TheresolveParameter
Method
is called everytime a parameter passes thesupportsParameter(ParameterContext, ExtensionContext)
check. TheParameterResolver
type is checked and if it is aSchema
or aStoreProperties
the corresponding value is returned. AParameterResolutionException
is thrown if there are no matches. The parameters should be annotated with@InjectedFromStoreITsSuite
Annotation
. For example:void test(@InjectedFromStoreITsSuite final Schema schema) { .... }
- Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
- the
Object
matching theParameterResolver
type - Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
- if theObject
matching theParameterResolver
type cannot be found
-
evaluateExecutionCondition
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
TheevaluateExecutionCondition
Method
allows the disabling of tests if some condition is met. In this case the test is skipped if the test method is in thetests-to-skip
Map
provided theClass
implementingIntegrationTestSuite
.- Specified by:
evaluateExecutionCondition
in interfaceorg.junit.jupiter.api.extension.ExecutionCondition
- Parameters:
context
- the current extension context; nevernull
- Returns:
- a
ConditionEvaluationResult.enabled(String)
orConditionEvaluationResult.disabled(String)
Object
for theTest
in question
-
-