Class 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 the Schema, the StoreProperties and the tests-to-skip Map from the IntegrationTestSuite class. The values are then used by the test classes from the Suite on execution or to exclude the tests listed in the tests-to-skip Map.

    The required Schema and StoreProperties are injected in to the test instance before each test is run. This injection is either at field level (see beforeEach(ExtensionContext)) or as Method parameters (see resolveParameter(ParameterContext, ExtensionContext)).

    For the tests-to-skip Map, each test method is checked before execution and if the method Map.containsKey(Object) then the test is omitted.

    In order to find the Class containing the Schema, the StoreProperties and tests-to-skip Map, the IntegrationTestSuiteExtension must first instantiate the Class. This is done through advertising the Class name using a ConfigurationParameter. The Class must also extend IntegrationTestSuite so the data can be retrieved by the IntegrationTestSuiteExtension. 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 the Suite Class. However, you can advertise any Class as long as it implements IntegrationTestSuite.

    • Constructor Detail

      • IntegrationTestSuiteExtension

        public IntegrationTestSuiteExtension()
    • Method Detail

      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext extensionContext)

        The beforeAll Method is used to load the Class implementing IntegrationTestSuite. This is required for injecting the Schema and StoreProperties and checking whether the tests are enabled using the tests-to-skip Map.

        The beforeAll method first checks if the INIT_CLASS has been set and if so attempts to retrieve the IntegrationTestSuite Object from the cache. If the cache does not contain the instance then it attempts instantiation. If there are errors during the instantiation then Exceptions are thrown and the Suite fails.

        Specified by:
        beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
        Parameters:
        extensionContext - the current extension context; never null
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
        The beforeEach Method is called before each test method is run. In the case of the IntegrationTestSuiteExtension, if any of the fields are annotated with the @InjectedFromStoreITsSuite annotation, the value is checked to see if it is Schema or a StoreProperties and if so the value is made accessible before the test is run. If the value is not found then a ParameterResolutionException is thrown. For example:
         
         class TestIT {
             @InjectedFromStoreITsSuite
             Schema schema;
             @InjectedFromStoreITsSuite
             StoreProperties storeProperties;
             @Test
             void test() {
                 ....
             }
         }
         
         
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Parameters:
        context - the current extension context; never null
      • supportsParameter

        public boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                         org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        The supportsParameter Method returns true if the parameter is either a Schema or a StoreProperties or false otherwise.
        Specified by:
        supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
        Parameters:
        parameterContext - the context for the parameter for which an argument should be resolved; never null
        extensionContext - the extension context for the Executable about to be invoked; never null
        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
        The resolveParameter Method is called everytime a parameter passes the supportsParameter(ParameterContext, ExtensionContext) check. The ParameterResolver type is checked and if it is a Schema or a StoreProperties the corresponding value is returned. A ParameterResolutionException 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 interface org.junit.jupiter.api.extension.ParameterResolver
        Parameters:
        parameterContext - the context for the parameter for which an argument should be resolved; never null
        extensionContext - the extension context for the Executable about to be invoked; never null
        Returns:
        the Object matching the ParameterResolver type
        Throws:
        org.junit.jupiter.api.extension.ParameterResolutionException - if the Object matching the ParameterResolver type cannot be found
      • evaluateExecutionCondition

        public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition​(org.junit.jupiter.api.extension.ExtensionContext context)
        The evaluateExecutionCondition Method allows the disabling of tests if some condition is met. In this case the test is skipped if the test method is in the tests-to-skip Map provided the Class implementing IntegrationTestSuite.
        Specified by:
        evaluateExecutionCondition in interface org.junit.jupiter.api.extension.ExecutionCondition
        Parameters:
        context - the current extension context; never null
        Returns:
        a ConditionEvaluationResult.enabled(String) or ConditionEvaluationResult.disabled(String) Object for the Test in question