Skip to content

Commit

Permalink
Merge pull request #986 from michalvavrik/feature/kc-annotation-impro…
Browse files Browse the repository at this point in the history
…vements

KeycloakContainer and Keycloak service refactoring, Keycloak image bump and resulting OCP fixes
  • Loading branch information
jedla97 authored Dec 18, 2023
2 parents 6c458c1 + e00c41f commit dcf617a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.qe;

import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_BASE_PATH;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_FILE;
import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -12,14 +15,12 @@

public abstract class BaseSecurityResourceIT {

static final String REALM_BASE_PATH = "realms";
static final String REALM_DEFAULT = "test-realm";
static final String CLIENT_ID_DEFAULT = "test-application-client";
static final String CLIENT_SECRET_DEFAULT = "test-application-client-secret";
static final String NORMAL_USER = "test-normal-user";

@KeycloakContainer(command = { "start-dev --import-realm" })
static KeycloakService keycloak = new KeycloakService("/keycloak-realm.json", REALM_DEFAULT, REALM_BASE_PATH);
@KeycloakContainer(command = { "start-dev", "--import-realm" })
static KeycloakService keycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM, DEFAULT_REALM_BASE_PATH);

private AuthzClient authzClient;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkus.qe;

import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_BASE_PATH;
import static io.quarkus.test.bootstrap.KeycloakService.DEFAULT_REALM_FILE;

import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.KeycloakService;
Expand All @@ -11,12 +15,12 @@
@OpenShiftScenario
public class OpenShiftUsingCustomTemplateResourceIT {

private static final String REALM_DEFAULT = "test-realm";
private static final String CLIENT_ID_DEFAULT = "test-application-client";
private static final String CLIENT_SECRET_DEFAULT = "test-application-client-secret";

@Container(image = "quay.io/keycloak/keycloak:22.0.1", expectedLog = "started", port = 8080)
static final KeycloakService customkeycloak = new KeycloakService("/keycloak-realm.json", REALM_DEFAULT);
static final KeycloakService customkeycloak = new KeycloakService(DEFAULT_REALM_FILE, DEFAULT_REALM,
DEFAULT_REALM_BASE_PATH);

@QuarkusApplication
static final RestService app = new RestService()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static java.util.regex.Pattern.quote;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -119,10 +121,11 @@ protected String replaceDeploymentContent(String content) {
content = content.replaceAll(quote(customServiceName), model.getContext().getOwner().getName());
}

String args = Arrays.stream(model.getCommand()).map(cmd -> "\"" + cmd + "\"").collect(Collectors.joining(", "));
return content.replaceAll(quote("${IMAGE}"), model.getImage())
.replaceAll(quote("${SERVICE_NAME}"), model.getContext().getName())
.replaceAll(quote("${INTERNAL_PORT}"), "" + model.getPort())
.replaceAll(quote("${ARGS}"), String.join(" ", model.getCommand()));
.replaceAll(quote("${ARGS}"), args);
}

private void applyDeployment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

public class KeycloakService extends BaseService<KeycloakService> {

public static final String DEFAULT_REALM_BASE_PATH = "/realms";
public static final String DEFAULT_REALM = "test-realm";
public static final String DEFAULT_REALM_FILE = "/keycloak-realm.json";
private static final String REALM_DEST_PATH = "/opt/keycloak/data/import";
private static final String USER = "admin";
private static final String PASSWORD = "admin";
Expand All @@ -33,16 +36,6 @@ public KeycloakService(String realmFile, String realmName, String realmBasePath)
withProperty("KEYCLOAK_REALM_IMPORT", "resource_with_destination::" + REALM_DEST_PATH + "|" + realmFile);
}

/**
* Legacy constructor used by previous versions of Keycloak 18.
*/
@Deprecated
public KeycloakService(String realmFile, String realmName) {
this(realmName);
withProperty("KEYCLOAK_IMPORT", "resource::" + realmFile);
withProperty("KEYCLOAK_REALM_IMPORT", "resource_with_destination::" + REALM_DEST_PATH + "|" + realmFile);
}

public KeycloakService(String realmName) {
this.realm = realmName;
withProperty("KEYCLOAK_ADMIN", USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface KeycloakContainer {
String image() default "quay.io/keycloak/keycloak:22.0.1";
String image() default "quay.io/keycloak/keycloak:23.0";

int port() default 8080;

String expectedLog() default "started";
String expectedLog() default "started in";

String[] command() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.test.bootstrap.ManagedResource;
import io.quarkus.test.bootstrap.ServiceContext;
import io.quarkus.test.services.KeycloakContainer;
import io.quarkus.test.utils.PropertiesUtils;

public class KeycloakContainerManagedResourceBuilder extends ContainerManagedResourceBuilder {

Expand Down Expand Up @@ -46,9 +47,9 @@ protected String getExpectedLog() {
@Override
public void init(Annotation annotation) {
KeycloakContainer metadata = (KeycloakContainer) annotation;
this.image = metadata.image();
this.image = PropertiesUtils.resolveProperty(metadata.image());
this.restPort = metadata.port();
this.expectedLog = metadata.expectedLog();
this.expectedLog = PropertiesUtils.resolveProperty(metadata.expectedLog());
this.command = metadata.command();
}

Expand Down

0 comments on commit dcf617a

Please sign in to comment.