Class AbstractMicronautExtension<C>

java.lang.Object
io.micronaut.test.extensions.AbstractMicronautExtension<C>
Type Parameters:
C - The extension context
All Implemented Interfaces:
TestExecutionListener, TestMethodInterceptor<Object>
Direct Known Subclasses:
MicronautJunit5Extension, MicronautSpockExtension

public abstract class AbstractMicronautExtension<C> extends Object implements TestExecutionListener, TestMethodInterceptor<Object>
Abstract base class for both JUnit 5 and Spock.
Since:
1.0
Author:
graemerocher
  • Field Details

    • TEST_ROLLBACK

      public static final String TEST_ROLLBACK
      See Also:
    • TEST_TRANSACTIONAL

      public static final String TEST_TRANSACTIONAL
      See Also:
    • TEST_TRANSACTION_MODE

      public static final String TEST_TRANSACTION_MODE
      See Also:
    • DISABLED_MESSAGE

      public static final String DISABLED_MESSAGE
      See Also:
    • MISCONFIGURED_MESSAGE

      public static final String MISCONFIGURED_MESSAGE
      See Also:
    • TEST_PROPERTY_SOURCE

      public static final String TEST_PROPERTY_SOURCE
      The name of the property source that contains test properties.
      See Also:
    • applicationContext

      protected io.micronaut.context.ApplicationContext applicationContext
    • embeddedApplication

      protected io.micronaut.runtime.EmbeddedApplication embeddedApplication
    • refreshScope

      protected io.micronaut.runtime.context.scope.refresh.RefreshScope refreshScope
    • specDefinition

      protected io.micronaut.inject.BeanDefinition<?> specDefinition
    • testProperties

      protected Map<String,Object> testProperties
    • oldValues

      protected Map<String,Object> oldValues
    • testAnnotationValue

      protected MicronautTestValue testAnnotationValue
  • Constructor Details

    • AbstractMicronautExtension

      public AbstractMicronautExtension()
  • Method Details

    • hasInterceptors

      protected boolean hasInterceptors()
      Returns:
      True if there are interceptors
    • interceptBeforeEach

      public Object interceptBeforeEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable
      Description copied from interface: TestMethodInterceptor
      Intercepts before each test invocation.
      Specified by:
      interceptBeforeEach in interface TestMethodInterceptor<C>
      Parameters:
      methodInvocationContext - the method invocation context
      Returns:
      intercepted return value
      Throws:
      Exception - allows any exception to propagate
      Throwable
    • interceptAfterEach

      public Object interceptAfterEach(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable
      Description copied from interface: TestMethodInterceptor
      Intercepts after each test invocation.
      Specified by:
      interceptAfterEach in interface TestMethodInterceptor<C>
      Parameters:
      methodInvocationContext - the method invocation context
      Returns:
      intercepted return value
      Throws:
      Exception - allows any exception to propagate
      Throwable
    • interceptTest

      public Object interceptTest(TestMethodInvocationContext<Object> methodInvocationContext) throws Throwable
      Description copied from interface: TestMethodInterceptor
      Intercepts each test invocation.
      Specified by:
      interceptTest in interface TestMethodInterceptor<C>
      Parameters:
      methodInvocationContext - the method invocation context
      Returns:
      intercepted return value
      Throws:
      Exception - allows any exception to propagate
      Throwable
    • beforeTestExecution

      public void beforeTestExecution(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed before a single test iteration is executed.
      Specified by:
      beforeTestExecution in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • beforeCleanupTest

      public void beforeCleanupTest(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed before the setup method of a test method.
      Specified by:
      beforeCleanupTest in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • afterCleanupTest

      public void afterCleanupTest(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed after the setup method of a test method.
      Specified by:
      afterCleanupTest in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • afterTestExecution

      public void afterTestExecution(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed after a single test iteration has been executed .
      Specified by:
      afterTestExecution in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • beforeTestClass

      public void beforeTestClass(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed before all of the tests of a class are executed.
      Specified by:
      beforeTestClass in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • afterTestClass

      public void afterTestClass(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed after all of the tests of a class have bean executed.
      Specified by:
      afterTestClass in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • beforeSetupTest

      public void beforeSetupTest(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed before the setup method of a test method.
      Specified by:
      beforeSetupTest in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • afterSetupTest

      public void afterSetupTest(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed after the setup method of a test method.
      Specified by:
      afterSetupTest in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • beforeTestMethod

      public void beforeTestMethod(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed before a test method is executed (a test method may contain multiple iterations).
      Specified by:
      beforeTestMethod in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • afterTestMethod

      public void afterTestMethod(TestContext testContext) throws Exception
      Description copied from interface: TestExecutionListener
      Executed after a test method has been executed (a test method may contain multiple iterations).
      Specified by:
      afterTestMethod in interface TestExecutionListener
      Parameters:
      testContext - the test context
      Throws:
      Exception - allows any exception to propagate
    • beforeClass

      protected void beforeClass(C context, Class<?> testClass, @Nullable @Nullable MicronautTestValue testAnnotationValue)
      Executed before tests within a class are run.
      Parameters:
      context - The test context
      testClass - The test class
      testAnnotationValue - The test annotation values
    • postProcessBuilder

      protected void postProcessBuilder(io.micronaut.context.ApplicationContextBuilder builder)
      Allows subclasses to customize the builder right before context initialization.
      Parameters:
      builder - the application context builder
    • resolveTestProperties

      protected abstract void resolveTestProperties(C context, MicronautTestValue testAnnotationValue, Map<String,Object> testProperties)
      Resolves any test properties.
      Parameters:
      context - The test context
      testAnnotationValue - The test annotation
      testProperties - The test properties
    • beforeEach

      protected void beforeEach(C context, @Nullable @Nullable Object testInstance, @Nullable @Nullable AnnotatedElement method, List<io.micronaut.context.annotation.Property> propertyAnnotations)
      To be called by the different implementations before each test method.
      Parameters:
      context - The test context
      testInstance - The test instance
      method - The test method
      propertyAnnotations - The @Property annotations found in the test method, if any
    • afterClass

      protected void afterClass(C context)
      Executed after the class is complete.
      Parameters:
      context - the context
    • afterEach

      public void afterEach(C context) throws Exception
      Executed after each test completes.
      Parameters:
      context - The context
      Throws:
      Exception - allows any exception to propagate
    • startApplicationContext

      protected void startApplicationContext()
      Starts the application context.
    • isTestSuiteBeanPresent

      protected boolean isTestSuiteBeanPresent(Class<?> requiredTestClass)
      Parameters:
      requiredTestClass - The test class
      Returns:
      true if the te given class has a bean definition class in the classpath (ie: the annotation processor has been run correctly)
    • alignMocks

      protected abstract void alignMocks(C context, Object instance)
      Parameters:
      context - The context
      instance - The mock instance to inject