From 72fb64f7fc781f00292ea6b8fe22af0a86fa7939 Mon Sep 17 00:00:00 2001 From: Lukas Hanusovsky <61745358+lhanusov@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:31:50 +0200 Subject: [PATCH] Testsuite PoC - distribution server run mode. (#31186) Signed-off-by: Lukas Hanusovsky --- .../DistributionKeycloakTestServer.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/test-poc/framework/src/main/java/org/keycloak/test/framework/server/DistributionKeycloakTestServer.java b/test-poc/framework/src/main/java/org/keycloak/test/framework/server/DistributionKeycloakTestServer.java index 2c6b211a3b..1e36ce2202 100644 --- a/test-poc/framework/src/main/java/org/keycloak/test/framework/server/DistributionKeycloakTestServer.java +++ b/test-poc/framework/src/main/java/org/keycloak/test/framework/server/DistributionKeycloakTestServer.java @@ -1,15 +1,46 @@ package org.keycloak.test.framework.server; +import org.keycloak.it.utils.RawKeycloakDistribution; + +import java.util.LinkedList; +import java.util.List; + public class DistributionKeycloakTestServer implements KeycloakTestServer { + private boolean debug = false; + private boolean manualStop = true; + private boolean enableTls = false; + private boolean reCreate = false; + private boolean removeBuildOptionsAfterBuild = false; + private int requestPort = 8080; + private RawKeycloakDistribution keycloak; + @Override public void start(KeycloakTestServerConfig serverConfig) { - throw new RuntimeException("Method not implemented!"); + keycloak = new RawKeycloakDistribution(debug, manualStop, enableTls, reCreate, removeBuildOptionsAfterBuild, requestPort); + + // Set environment variables user and password for Keycloak Admin used by Keycloak instance. + keycloak.setEnvVar("KC_BOOTSTRAP_ADMIN_USERNAME", serverConfig.adminUserName().get()); + keycloak.setEnvVar("KC_BOOTSTRAP_ADMIN_PASSWORD", serverConfig.adminUserPassword().get()); + + List rawOptions = new LinkedList<>(); + rawOptions.add("start-dev"); + + //rawOptions.add("--db=dev-mem"); // TODO With dev-mem there's an issue as the H2 DB isn't stopped when restarting embedded server + rawOptions.add("--cache=local"); + + if (!serverConfig.features().isEmpty()) { + rawOptions.add("--features=" + String.join(",", serverConfig.features())); + } + + serverConfig.options().forEach((key, value) -> rawOptions.add("--" + key + "=" + value)); + + keycloak.run(rawOptions).assertStartedDevMode(); } @Override public void stop() { - throw new RuntimeException("Method not implemented!"); + keycloak.stop(); } @Override