Closed belgoros closed 3 years ago
The Keycloak-Testcontainer won't configure itself base on some Spring config properties. Testcontainers have no relation to Spring. Generally, Testcontainers start on a random port on each run. That's the concept of Testcontainers.
You have to take care in your Spring test environment/configuration to set the appropriate url/port of Keycloak after Keycloak-Testcontainer has startet. Please consult the Spring docs on how to do that. I'm not a Spring guy, I don't know how this can be achieved, I only know that it is possible and also a well-known and wide-used practice.
I just wonder if:
auth-server-url: http://localhost:8080/auth
property in the test/resources/application.yml
fileI'm facing the same issue with Spring. Would be great to have a pointer to the widely used practice.
Please consult the Spring Boot docs for @ContextConfiguration
and ApplicationContextInitializer<ConfigurableApplicationContext>
. That‘s what you need.
I'm trying to run a test using the exported from Keycloack server JSON configuration file as follows:
The
BaseKeycloakTest
class is defined as follows:I'm getting the token in
BaseKeycloakTest
as follows:When running the test, it seems like
realm-export.json
file is not taken in consideration, - the generated token URL looks like that:instead of:
what raises the error:
The
KeucloakConfig
class looks like that:And
application.yml
for tests looks like that:What is wrong with that?