Class 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
@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
FieldsModifier and TypeFieldDescriptionstatic final StringDefault name of the optionalstatic Microservice.Buildersupplier method on the test class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext pc, org.junit.jupiter.api.extension.ExtensionContext ec) booleansupportsParameter(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, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Field Details
-
BUILDER_SUPPLIER_METHOD
Default name of the optionalstatic Microservice.Buildersupplier method on the test class.- See Also:
-
-
Constructor Details
-
MicroserviceExtension
public MicroserviceExtension()
-
-
Method Details
-
beforeAll
- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceorg.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:
supportsParameterin interfaceorg.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:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver
-