Class ManagedCas

java.lang.Object
org.apache.uima.fit.testing.junit.ManagedCas
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 ManagedCas extends Object implements org.junit.jupiter.api.extension.TestWatcher, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.AfterAllCallback
Provides a CAS object which is automatically reset before the test. The idea of this class is to re-use CAS objects across different test method to avoid the overhead of having to set up a new CAS every time. Each thread requesting a CAS gets a different instance (the CASes are internally managed as ThreadLocal. When a test completes, all of the CASses that handed out to any thread are reset (except any CASes which may meanwhile have been garbage collected).
  • Constructor Details

    • ManagedCas

      public ManagedCas()
      Provides a CAS with an auto-detected type system.
    • ManagedCas

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

    • get

      public CAS get()
      Returns:
      the CAS 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 ManagedCas skipValidation()
      Skip validation for the current test run only.
      Returns:
      the object for chaining.
    • withoutDefaultValidator

      public ManagedCas 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 ManagedCas withDefaultValidator(Validator aValidator)
      Set a default validator for the all test runs.
      Returns:
      the object for chaining.
    • withValidator

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