Annotation Type RestBootstrap


@Inherited @Documented @Target(TYPE) @Retention(RUNTIME) @ExtendWith({dev.resteasy.junit.extension.extensions.SeBootstrapExtension.class,dev.resteasy.junit.extension.extensions.RestResourceProducerExtension.class,dev.resteasy.junit.extension.extensions.UriBuilderParameterResolver.class}) public @interface RestBootstrap
An annotation which starts a SeBootstrap.Instance for unit testing.

There are two ways to specify what to bootstrap:

  1. Application class - Specify a custom Application class via application():
    @RestBootstrap(application = MyApplication.class)
    public class MyTest {
        // Tests run with MyApplication
    }
    
  2. Resource classes - For simple cases, specify Jakarta REST resource classes via value():
    @RestBootstrap({ UserResource.class, OrderResource.class })
    public class MyTest {
        // Tests run with a synthetic Application containing these resources
    }
    

Exactly one of application() or value() must be specified. Specifying both or neither will result in an ExtensionConfigurationException.

The default provider attempts to use a ServiceLoader to lookup the first provider found. If found that provider will be used. This can be useful when when you want to use the same provider across all tests without having to define the type on each annotation.

Since:
1.0
Author:
James R. Perkins
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<? extends jakarta.ws.rs.core.Application>
    The application to use for starting a SeBootstrap.Instance.
    A factory used to be build the configuration for starting the SeBootstrap.
    jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication
    The SSL client authentication mode to use when the test class is also annotated with @SelfSignedCert.
    long
    The timeout used to wait for the SeBootstrap to start.
    The time unit to use for the timeout.
    Class<?>[]
    Jakarta REST resource classes to bootstrap for testing.
  • Element Details

    • value

      Class<?>[] value
      Jakarta REST resource classes to bootstrap for testing.

      This provides a simplified alternative to application() for common cases where you only need to specify resource classes without custom Application configuration. When value() is specified, the extension creates a synthetic Application that returns these classes from Application.getClasses().

      This is mutually exclusive with application(). Exactly one must be specified.

      Example

      @RestBootstrap({ UserResource.class, OrderResource.class })
      public class SimpleTest {
          @RestResource
          private Client client;
      
          @Test
          public void testUser() {
              // Test UserResource
          }
      }
      

      When to use value() vs application():

      • Use value() for simple tests that only need to specify resource classes
      • Use application() when you need:
        • Custom ApplicationPath configuration
        • Custom Application properties
        • Programmatic resource filtering or dynamic configuration
      Returns:
      an array of Jakarta REST resource classes, or empty if using application() instead
      Default:
      {}
    • application

      Class<? extends jakarta.ws.rs.core.Application> application
      The application to use for starting a SeBootstrap.Instance.

      This is mutually exclusive with value(). Exactly one must be specified.

      The default value of Application.class serves as a marker indicating no application was specified. In this case, value() must be non-empty.

      Returns:
      the application class, or Application.class if using value() instead
      Default:
      jakarta.ws.rs.core.Application.class
    • configFactory

      Class<? extends ConfigurationProvider> configFactory
      A factory used to be build the configuration for starting the SeBootstrap.
      Returns:
      the configuration factory to use
      Default:
      dev.resteasy.junit.extension.api.ConfigurationProvider.class
    • timeout

      long timeout
      The timeout used to wait for the SeBootstrap to start.
      Returns:
      the timeout value
      Default:
      60L
    • timeoutUnit

      TimeUnit timeoutUnit
      The time unit to use for the timeout.
      Returns:
      the timeout unit
      Default:
      SECONDS
    • sslClientAuthentication

      jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication sslClientAuthentication
      The SSL client authentication mode to use when the test class is also annotated with @SelfSignedCert.

      This controls whether the server requests or requires a client certificate during the TLS handshake:

      • OPTIONAL (default) — the server requests a client certificate but does not require one. This is the recommended default for testing, as the injected Client is always configured with the client SSL context.
      • MANDATORY — the server requires a valid client certificate. Connections without a client certificate will be rejected.
      • NONE — the server does not request a client certificate.

      This attribute is only used by the default ConfigurationProvider. Custom providers specified via configFactory() are responsible for their own SSL client authentication configuration.

      This attribute has no effect if the test class is not annotated with @SelfSignedCert.

      Returns:
      the SSL client authentication mode
      See Also:
      Default:
      OPTIONAL