mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Injection of web target with correct endpoint. (#2380)
* Injection of web target with correct endpoint. * Support for junit5 tests already in MP Config implementation * Support for inherited repeating annotations. Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
This commit is contained in:
@@ -41,6 +41,11 @@ A test can be annotated with `io.helidon.microprofile.tests.junit5.HelidonTest`
|
||||
CDI test. This annotation will start the CDI container before any test method is invoked, and stop it after
|
||||
the last method is invoked. This annotation also enables injection into the test class itself.
|
||||
|
||||
The annotations described in this section are inherited (for the non-repeatable ones), and additive (for repeatable).
|
||||
So if you declare `@DisableDiscovery` on abstract class, all implementations will have discovery disabled, unless you
|
||||
annotate the implementation class with `@DisableDiscovery(false)`.
|
||||
If you declare `@AddBean` on both abstract class and implementation class, both beans will be added.
|
||||
|
||||
In addition to this simplification, the following annotations are supported:
|
||||
|
||||
- `io.helidon.microprofile.tests.junit5.AddBean` - to add one or more beans to the container
|
||||
@@ -49,6 +54,7 @@ In addition to this simplification, the following annotations are supported:
|
||||
(if not added through service loader, or when discovery is disabled)
|
||||
- `io.helidon.microprofile.tests.junit5.AddConfig` - to add one or more configuration properties to MicroProfile config
|
||||
without the need of creating a `microprofile-config.properties` file
|
||||
- `io.helidon.microprofile.tests.junit5.DisableDiscovery` - to disable automated discovery of beans and extensions
|
||||
|
||||
[source,java]
|
||||
.Code sample
|
||||
@@ -84,10 +90,23 @@ This will change the behavior as follows:
|
||||
|
||||
== Usage - configuration
|
||||
In addition to the `@AddConfig` annotation, you can also use
|
||||
`@Configuration`.
|
||||
`@Configuration` to configure additional classpath properties config sources using `configSources`, and to
|
||||
mark that a custom configuration is desired.
|
||||
You can set up config in `@BeforeAll` method and register it with `ConfigProviderResolver` using MP Config APIs, and declare
|
||||
`@Configuration(useExisting=true)`.
|
||||
Note that this is not compatible with repeatable tests that use method sources that access CDI, as we must delay the CDI
|
||||
startup to the test class instantiation (which is too late, as the method sources are already invoked by this time).
|
||||
|
||||
This allows you to do the following:
|
||||
*If you want to use method sources that use CDI with repeatable tests, please do not use `@Configuration(useExisting=true)`*
|
||||
|
||||
- when `useExisting` is set to `true`, the configuration will not be changed
|
||||
and current MP configuration will be used
|
||||
- you can configure additional classpath properties config sources using `configSources`
|
||||
== Usage - added parameters and injection types
|
||||
The following types are available for injection (when a single CDI container is used per test class):
|
||||
|
||||
- `WebTarget` - a JAX-RS client's target configured for the current hostname and port when `helidon-micorprofile-server` is on
|
||||
the classpath
|
||||
|
||||
The following types are available as method parameters (in any type of Helidon tests):
|
||||
|
||||
- `WebTarget` - a JAX-RS client's target configured for the current hostname and port when `helidon-micorprofile-server` is on
|
||||
the classpath
|
||||
- `SeContainer` - the current container instance
|
||||
Reference in New Issue
Block a user