In a setup as described in the docs:
public class MyWireMockResource implements QuarkusTestResourceLifecycleManager {
WireMockServer wireMockServer;
@Override
public Map<String, String> start() {
wireMockServer = new WireMockServer(8090);
wireMockServer.start();
// create some stubs
return Map.of("some.service.url", "localhost:" wireMockServer.port());
}
//...
}
How can I access the value returned in in the start()
method.
The javadoc says:
A map of system properties that should be set for the running test
Why "should be"?
I would like to set some values that I can later used in my productive code.
I have tried: System.getProperty("some.service.url")
I have also tried:
@ConfigProperty(name = "some.service.url")
String serviceUrl;
But the value is not set.
Any help is appreciated.
CodePudding user response:
The system properties mentioned in the javadoc is confusing. The returned map will as expected override the configurations.
It was not working for me to access it with the @ConfigProperty
annotation because I was reading the value in the constructor and not in the method annotated with @PostConstruct
.
@ApplicationScoped
public class SomeBean {
@ConfigProperty(name = "some.service.url")
String serviceUrl;
public SomeBean() {
// we are too early here, value is null:
System.out.println("value in constructor: " serviceUrl);
}
@PostConstruct
void init() {
System.out.println("value in init: " serviceUrl);
}
}