Class MicroserviceExtension

java.lang.Object
org.apache.juneau.microservice.test.MicroserviceExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension

public class MicroserviceExtension extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver
JUnit 5 extension behind @MicroserviceTest: boots a whole Microservice (config + lifecycle + embedded Jetty on an ephemeral port) for the test class, with @TestBean mock-bean injection and convenience parameter resolution.
Lifecycle (per class)

The microservice is built + started once in beforeAll and stopped in afterAll. A fresh instance is booted per class and stopped cleanly — never reused, since Microservice restart is unsupported (the stopped flag is one-way, the bean store is closed, and each start() adds a JVM shutdown hook). The bound port is read from the live ServerConnector (never hard-coded), mirroring the established fixture pattern.

Mock-bean injection

@TestBean declarations are discovered via JuneauBeanStoreExtension.discoverOverrides(Object). Mode INJECT (the default) installs the overrides via Microservice.Builder.overridingBeanStore(...) before boot, so the service reads them from startup. Mode OVERLAY pushes the overrides onto the booted instance's bean store for the class duration and pops them in teardown.

Parameter resolution

Resolves RestClient (bound to the booted root URL), Microservice, WritableBeanStore, and the bound port (int / Integer) on test + lifecycle method parameters.

Since:
10.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default name of the optional static Microservice.Builder supplier method on the test class.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ec)
     
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ec)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Field Details

  • Constructor Details

  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ec)
      Specified by:
      supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
    • resolveParameter

      public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ec)
      Specified by:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver