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
IntegrationTestSuiteExtensionretrieves theSchema, theStorePropertiesand thetests-to-skipMapfrom theIntegrationTestSuiteclass. The values are then used by the test classes from theSuiteon execution or to exclude the tests listed in the tests-to-skipMap.The required
SchemaandStorePropertiesare injected in to the test instance before each test is run. This injection is either at field level (seebeforeEach(ExtensionContext)) or asMethodparameters (seeresolveParameter(ParameterContext, ExtensionContext)).For the
tests-to-skipMap, each test method is checked before execution and if the methodMap.containsKey(Object)then the test is omitted.In order to find the
Classcontaining theSchema, theStorePropertiesandtests-to-skipMap, theIntegrationTestSuiteExtensionmust first instantiate theClass. This is done through advertising theClassname using aConfigurationParameter. TheClassmust also extendIntegrationTestSuiteso 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
IntegrationTestSuiteClassadvertised is the same as theSuiteClass. However, you can advertise anyClassas long as it implementsIntegrationTestSuite.
-
-
Field Summary
Fields Modifier and Type Field Description static StringINIT_CLASS
-
Constructor Summary
Constructors Constructor Description IntegrationTestSuiteExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)ThebeforeEachMethodis called before each test method is run.org.junit.jupiter.api.extension.ConditionEvaluationResultevaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)TheevaluateExecutionConditionMethodallows the disabling of tests if some condition is met.ObjectresolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)TheresolveParameterMethodis called everytime a parameter passes thesupportsParameter(ParameterContext, ExtensionContext)check.booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)ThesupportsParameterMethodreturnstrueif the parameter is either aSchemaor aStorePropertiesorfalseotherwise.
-
-
-
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
beforeAllMethodis used to load theClassimplementingIntegrationTestSuite. This is required for injecting theSchemaandStorePropertiesand checking whether the tests are enabled using thetests-to-skipMap.The
beforeAllmethod first checks if theINIT_CLASShas been set and if so attempts to retrieve theIntegrationTestSuiteObjectfrom the cache. If the cache does not contain the instance then it attempts instantiation. If there are errors during the instantiation thenExceptions are thrown and theSuitefails.- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Parameters:
extensionContext- the current extension context; nevernull
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
ThebeforeEachMethodis called before each test method is run. In the case of theIntegrationTestSuiteExtension, if any of the fields are annotated with the@InjectedFromStoreITsSuiteannotation, the value is checked to see if it isSchemaor aStorePropertiesand if so the value is made accessible before the test is run. If the value is not found then aParameterResolutionExceptionis thrown. For example:class TestIT { @InjectedFromStoreITsSuite Schema schema; @InjectedFromStoreITsSuite StoreProperties storeProperties; @Test void test() { .... } }- Specified by:
beforeEachin 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)ThesupportsParameterMethodreturnstrueif the parameter is either aSchemaor aStorePropertiesorfalseotherwise.- Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout 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
TheresolveParameterMethodis called everytime a parameter passes thesupportsParameter(ParameterContext, ExtensionContext)check. TheParameterResolvertype is checked and if it is aSchemaor aStorePropertiesthe corresponding value is returned. AParameterResolutionExceptionis thrown if there are no matches. The parameters should be annotated with@InjectedFromStoreITsSuiteAnnotation. For example:void test(@InjectedFromStoreITsSuite final Schema schema) { .... }- Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout to be invoked; nevernull- Returns:
- the
Objectmatching theParameterResolvertype - Throws:
org.junit.jupiter.api.extension.ParameterResolutionException- if theObjectmatching theParameterResolvertype cannot be found
-
evaluateExecutionCondition
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
TheevaluateExecutionConditionMethodallows the disabling of tests if some condition is met. In this case the test is skipped if the test method is in thetests-to-skipMapprovided theClassimplementingIntegrationTestSuite.- Specified by:
evaluateExecutionConditionin interfaceorg.junit.jupiter.api.extension.ExecutionCondition- Parameters:
context- the current extension context; nevernull- Returns:
- a
ConditionEvaluationResult.enabled(String)orConditionEvaluationResult.disabled(String)Objectfor theTestin question
-
-