Interface AotTestAttributes


public interface AotTestAttributes
Holder for metadata specific to ahead-of-time (AOT) support in the Spring TestContext Framework.

AOT test attributes are supported in two modes of operation: build-time and run-time. At build time, test components can contribute attributes during the AOT processing phase. At run time, test components can retrieve attributes that were contributed at build time. If AotDetector.useGeneratedArtifacts() returns true, run-time mode applies.

For example, if a test component computes something at build time that cannot be computed at run time, the result of the build-time computation can be stored as an AOT attribute and retrieved at run time without repeating the computation.

An AotContextLoader would typically contribute an attribute in loadContextForAotProcessing(); whereas, an AotTestExecutionListener would typically contribute an attribute in processAheadOfTime(). Any other test component — such as a TestContextBootstrapper — can choose to contribute an attribute at any point in time. Note that contributing an attribute during standard JVM test execution will not have any adverse side effect since AOT attributes will be ignored in that scenario. In any case, you should use AotDetector.useGeneratedArtifacts() to determine if invocations of setAttribute(String, String) and removeAttribute(String) are permitted.

Since:
6.0
Author:
Sam Brannen
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Retrieve the attribute value for the given name as a boolean.
    Get the current instance of AotTestAttributes to use.
    Retrieve the attribute value for the given name as a String.
    void
    Remove the attribute stored under the provided name.
    default void
    setAttribute(String name, boolean value)
    Set a boolean attribute for later retrieval during AOT run-time execution.
    void
    setAttribute(String name, String value)
    Set a String attribute for later retrieval during AOT run-time execution.
  • Method Details

    • getInstance

      static AotTestAttributes getInstance()
      Get the current instance of AotTestAttributes to use.

      See the class-level Javadoc for details on the two supported modes.

    • setAttribute

      void setAttribute(String name, String value)
      Set a String attribute for later retrieval during AOT run-time execution.

      In general, users should take care to prevent overlaps with other metadata attributes by using fully-qualified names, perhaps using a class or package name as a prefix.

      Parameters:
      name - the unique attribute name
      value - the associated attribute value
      Throws:
      UnsupportedOperationException - if invoked during AOT run-time execution
      IllegalArgumentException - if the provided value is null or if an attempt is made to override an existing attribute
      See Also:
    • setAttribute

      default void setAttribute(String name, boolean value)
      Set a boolean attribute for later retrieval during AOT run-time execution.

      In general, users should take care to prevent overlaps with other metadata attributes by using fully-qualified names, perhaps using a class or package name as a prefix.

      Parameters:
      name - the unique attribute name
      value - the associated attribute value
      Throws:
      UnsupportedOperationException - if invoked during AOT run-time execution
      IllegalArgumentException - if an attempt is made to override an existing attribute
      See Also:
    • removeAttribute

      void removeAttribute(String name)
      Remove the attribute stored under the provided name.
      Parameters:
      name - the unique attribute name
      Throws:
      UnsupportedOperationException - if invoked during AOT run-time execution
      See Also:
    • getString

      @Nullable String getString(String name)
      Retrieve the attribute value for the given name as a String.
      Parameters:
      name - the unique attribute name
      Returns:
      the associated attribute value, or null if not found
      See Also:
    • getBoolean

      default boolean getBoolean(String name)
      Retrieve the attribute value for the given name as a boolean.
      Parameters:
      name - the unique attribute name
      Returns:
      true if the attribute is set to "true" (ignoring case), false otherwise
      See Also: