Class ManagedJCas

java.lang.Object
org.apache.uima.fit.testing.junit.ManagedJCas
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestWatcher

public final class ManagedJCas extends Object implements org.junit.jupiter.api.extension.TestWatcher, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.AfterAllCallback
Provides a JCas object which is automatically reset before the test. The idea of this class is to re-use JCas objects across different test method to avoid the overhead of having to set up a new JCas every time. Each thread requesting a JCas gets a different instance (the JCases are internally managed as ThreadLocal. When a test completes, all of the JCasses that handed out to any thread are reset (except any JCases which may meanwhile have been garbage collected).
  • Constructor Details

    • ManagedJCas

      public ManagedJCas()
      Provides a JCas with an auto-detected type system.
    • ManagedJCas

      public ManagedJCas(TypeSystemDescription aTypeSystemDescription)
      Provides a JCas with the specified type system.
      Parameters:
      aTypeSystemDescription - the type system used to initialize the CAS.
  • Method Details

    • get

      public JCas get()
      Returns:
      the JCas object managed by this rule.
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext aContext) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • afterTestExecution

      public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
      Throws:
      Exception
    • skipValidation

      public ManagedJCas skipValidation()
      Skip validation for the current test run only.
      Returns:
      the object for chaining.
    • withoutDefaultValidator

      public ManagedJCas withoutDefaultValidator()
      Skip validation by default. If validation is enabled for a particular run using withValidator(Validator) it is reset to a no-op validator again after the test is complete.
      Returns:
      the object for chaining.
    • withDefaultValidator

      public ManagedJCas withDefaultValidator(Validator aValidator)
      Set a default validator for the all test runs.
      Returns:
      the object for chaining.
    • withValidator

      public ManagedJCas withValidator(Validator aValidator)
      Set a validator for the current test run only.
      Returns:
      the object for chaining.