Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rooije committed May 21, 2024
1 parent 8c9ebfb commit 6a96b8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.ToStringConsumer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.shaded.org.apache.commons.io.filefilter.WildcardFileFilter;

import java.io.File;
Expand All @@ -24,6 +23,7 @@ public class KeycloakTestServer {
private static KeycloakUtilsImpl userUtils;
private static DockerComposeContainer dockerClient;
private static boolean running;
private static volatile boolean starting;

/**
* Use main method to start keycloak server manually. Server can be stopped by manually updating the 'keepGoing'
Expand All @@ -35,11 +35,11 @@ public static void main(String[] args) throws Throwable {
File keycloakTmpDir = Files.createTempDirectory("keycloak").toFile();
final File spiBuildLib = Paths.get("mydeltares-keycloak-spi", "build", "libs").toFile();
final File themeBuildLib = Paths.get("mydeltares-keycloak-theme", "build", "libs").toFile();
File dataDir = new File(keycloakTmpDir, "data/import");
File dataDir = new File(keycloakTmpDir, "keycloak/data/import");
dataDir.mkdirs();
File configDir = new File(keycloakTmpDir, "conf");
File configDir = new File(keycloakTmpDir, "keycloak/conf");
configDir.mkdir();
File deploymentDir = new File(keycloakTmpDir, "providers");
File deploymentDir = new File(keycloakTmpDir, "keycloak/providers");
deploymentDir.mkdir();

Files.copy(new File(testResources.getParent(), "docker-compose.yml").toPath(), new File(keycloakTmpDir, "docker-compose.yml").toPath());
Expand Down Expand Up @@ -71,8 +71,15 @@ public static void main(String[] args) throws Throwable {

public static void startKeycloak(String keycloakDir) {

starting = true;
dockerClient = new DockerComposeContainer(new File(keycloakDir, "docker-compose.yml"));
final WaitStrategy waitStrategy = new HttpWaitStrategy().forPort(8080).withStartupTimeout(Duration.ofMinutes(1));
int port = 8080;
int debugPort = 8787;

System.out.printf("Starting Keycloak on port %d and debug port %d\n", port, debugPort);

final HttpWaitStrategy waitStrategy = new HttpWaitStrategy();
waitStrategy.forPath("/auth").forPort(port).withStartupTimeout(Duration.ofMinutes(1));
dockerClient.withLogConsumer("keycloak", new ToStringConsumer() {
@Override
public void accept(OutputFrame outputFrame) {
Expand All @@ -84,10 +91,15 @@ public void accept(OutputFrame outputFrame) {
}
}
}
}).withExposedService("keycloak", 8080, waitStrategy);
dockerClient. start();
running = true;

}).withExposedService("keycloak", port, waitStrategy);
try {
dockerClient.start();
running = true;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
starting = false;
}
}

public static void stopKeycloak() {
Expand Down Expand Up @@ -115,6 +127,13 @@ public static void stopKeycloak() {


public static boolean isRunning() {
while (starting) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return running;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
keycloak.baseurl=http://localhost:8080/auth/realms/liferay-portal/
keycloak.baseapiurl=http://localhost:8080/auth/admin/realms/liferay-portal/
keycloak.clientid=admin-api-admin
keycloak.clientsecret=password
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
keycloak.baseurl=http://localhost:8080/auth/realms/liferay-portal/
keycloak.baseapiurl=http://localhost:8080/auth/admin/realms/liferay-portal/
keycloak.clientid=user-api-admin
keycloak.clientsecret=password
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
keycloak.baseurl=http://localhost:8080/auth/realms/liferay-portal/
keycloak.baseapiurl=http://localhost:8080/auth/admin/realms/liferay-portal/
keycloak.clientid=viewer-api-admin
keycloak.clientsecret=password

0 comments on commit 6a96b8e

Please sign in to comment.