Use ConfigProperties in a QuarkusTestCallback

148 views Asked by At

For my integration tests, I would like to simplify the oauth security with an annotation and a QuarkusTestBeforeTestExecutionCallback, that sets up my RestAssured instance with the necessary oauth access token for a user with desired roles.

Everything would work just fine, the single problem I'm facing is, that I do not get the URL of the Keycloak Devservice into my QuarkusTestBeforeTestExecutionCallback, as apparently @ConfigProperty(name = "quarkus.oidc.auth-server-url"), which does work in the @QuarkusTest does not work in the callback class. As the callback class is somehow executed in the context of the @QuarkusTest, the property should be theoretically somehow accessible I guess.

How can I get a config property, which is available in a @QuarkusTest in a QuarkusCallback class?

1

There are 1 answers

0
Herr Derb On

I managed to get the desired ConfigProperty with manual invocation using the classloader of the test object, as following:

public class MyCallback implements QuarkusTestBeforeEachCallback {
    @Override
    public void beforeEach(QuarkusTestMethodContext context) {
        ClassLoader classloader = context.getTestInstance().getClass().getClassLoader();
        Config config = ConfigProvider.getConfig(classLoader);
        ConfigValue configValue = config.getConfigValue("my.config.property.name");
    ...
}