Database suppliers refactoring WIP (#34574)

Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
Stian Thorgersen 2024-11-05 07:20:11 +01:00 committed by GitHub
parent 612e2caae1
commit d6b01015c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 785 additions and 296 deletions

80
test-framework/bom/pom.xml Executable file
View file

@ -0,0 +1,80 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-bom</artifactId>
<name>Keycloak Test Framework - BOM</name>
<packaging>pom</packaging>
<description>BOM for Keycloak Test Framework</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-ui</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mariadb</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mssql</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mysql</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-oracle</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-postgres</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View file

@ -44,30 +44,6 @@
<groupId>org.keycloak</groupId>
<artifactId>keycloak-junit5</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-free</artifactId>
</dependency>
<!-- Temporary dependency until we figure out how we want to support OAuth -->
<dependency>
<groupId>com.nimbusds</groupId>

View file

@ -3,11 +3,6 @@ package org.keycloak.test.framework;
import org.keycloak.test.framework.admin.KeycloakAdminClientSupplier;
import org.keycloak.test.framework.database.DevFileDatabaseSupplier;
import org.keycloak.test.framework.database.DevMemDatabaseSupplier;
import org.keycloak.test.framework.database.MSSQLServerDatabaseSupplier;
import org.keycloak.test.framework.database.MariaDBDatabaseSupplier;
import org.keycloak.test.framework.database.MySQLDatabaseSupplier;
import org.keycloak.test.framework.database.OracleDatabaseSupplier;
import org.keycloak.test.framework.database.PostgresDatabaseSupplier;
import org.keycloak.test.framework.database.TestDatabase;
import org.keycloak.test.framework.events.EventsSupplier;
import org.keycloak.test.framework.events.SysLogServerSupplier;
@ -38,11 +33,6 @@ public class CoreTestFrameworkExtension implements TestFrameworkExtension {
new RemoteKeycloakTestServerSupplier(),
new DevMemDatabaseSupplier(),
new DevFileDatabaseSupplier(),
new MySQLDatabaseSupplier(),
new PostgresDatabaseSupplier(),
new MariaDBDatabaseSupplier(),
new MSSQLServerDatabaseSupplier(),
new OracleDatabaseSupplier(),
new OAuthClientSupplier(),
new SysLogServerSupplier(),
new EventsSupplier()

View file

@ -0,0 +1,58 @@
package org.keycloak.test.framework.database;
import org.jboss.logging.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import java.io.IOException;
import java.time.Duration;
import java.util.Map;
public abstract class AbstractContainerTestDatabase implements TestDatabase {
private static final Logger LOGGER = Logger.getLogger(AbstractContainerTestDatabase.class);
private JdbcDatabaseContainer<?> container;
@SuppressWarnings("resource")
public void start() {
container = createContainer();
container.withStartupTimeout(Duration.ofMinutes(30))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(AbstractContainerTestDatabase.class)))
.start();
try {
String postStartCommand = getPostStartCommand();
if (postStartCommand != null) {
LOGGER.tracev("Running post start command: {0}", postStartCommand);
String result = container.execInContainer("bash", "-c", postStartCommand).getStdout();
LOGGER.tracev(result);
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
public void stop() {
container.stop();
}
@Override
public Map<String, String> serverConfig() {
return Map.of(
"db", getKeycloakDatabaseName(),
"db-url", container.getJdbcUrl(),
"db-username", container.getUsername(),
"db-password", container.getPassword()
);
}
public abstract JdbcDatabaseContainer<?> createContainer();
public String getPostStartCommand() {
return null;
}
public abstract String getKeycloakDatabaseName();
}

View file

@ -8,9 +8,6 @@ import org.keycloak.test.framework.injection.Supplier;
public abstract class AbstractDatabaseSupplier implements Supplier<TestDatabase, InjectTestDatabase> {
protected static final String DEFAULT_DB_USERNAME = "keycloak";
protected static final String DEFAULT_DB_PASSWORD = "Password1!";
@Override
public Class<InjectTestDatabase> getAnnotationClass() {
return InjectTestDatabase.class;

View file

@ -1,17 +1,34 @@
package org.keycloak.test.framework.database;
import java.util.Map;
public class DevFileDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "dev-file";
@Override
public String getAlias() {
return "dev-file";
}
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig().vendor(VENDOR);
return new TestDatabase(databaseConfig);
return new DevFileTestDatabase();
}
private static class DevFileTestDatabase implements TestDatabase {
@Override
public void start() {
}
@Override
public String getAlias() {
return VENDOR;
public void stop() {
// TODO Should we clean-up H2 database here?
}
@Override
public Map<String, String> serverConfig() {
return Map.of("db", "dev-file");
}
}
}

View file

@ -1,17 +1,33 @@
package org.keycloak.test.framework.database;
import java.util.Map;
public class DevMemDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "dev-mem";
@Override
public String getAlias() {
return "dev-mem";
}
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig().vendor(VENDOR);
return new TestDatabase(databaseConfig);
return new DevMemTestDatabase();
}
private static class DevMemTestDatabase implements TestDatabase {
@Override
public void start() {
}
@Override
public String getAlias() {
return VENDOR;
public void stop() {
}
@Override
public Map<String, String> serverConfig() {
return Map.of("db", "dev-mem");
}
}
}

View file

@ -1,18 +0,0 @@
package org.keycloak.test.framework.database;
public class MSSQLServerDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "mssql";
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig()
.vendor(VENDOR)
.containerImage("mcr.microsoft.com/mssql/server:latest");
return new TestDatabase(databaseConfig);
}
@Override
public String getAlias() {
return VENDOR;
}
}

View file

@ -1,20 +0,0 @@
package org.keycloak.test.framework.database;
public class MariaDBDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "mariadb";
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig()
.vendor(VENDOR)
.username(DEFAULT_DB_USERNAME)
.password(DEFAULT_DB_PASSWORD)
.containerImage("mariadb:latest");
return new TestDatabase(databaseConfig);
}
@Override
public String getAlias() {
return VENDOR;
}
}

View file

@ -1,21 +0,0 @@
package org.keycloak.test.framework.database;
public class MySQLDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "mysql";
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig()
.vendor(VENDOR)
.username(DEFAULT_DB_USERNAME)
.password(DEFAULT_DB_PASSWORD)
.containerImage("mysql:latest");
return new TestDatabase(databaseConfig);
}
@Override
public String getAlias() {
return VENDOR;
}
}

View file

@ -1,34 +0,0 @@
package org.keycloak.test.framework.database;
import java.util.HashMap;
import java.util.Map;
public class OracleDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "oracle";
private static final String CONTAINER_IMAGE = "docker.io/miquelsi/oracle-19c:19.3";
@Override
TestDatabase getTestDatabase() {
Map<String, String> env = new HashMap<>();
env.put("ORACLE_SID", "keycloak");
env.put("ORACLE_PWD", "sa");
DatabaseConfig databaseConfig = new DatabaseConfig()
.vendor(VENDOR)
.username(DEFAULT_DB_USERNAME)
.password(DEFAULT_DB_PASSWORD)
.postStartCommand("(echo 'alter session set \"_ORACLE_SCRIPT\"=true;' && echo 'CREATE USER " +
DEFAULT_DB_USERNAME + " IDENTIFIED BY \"" +
DEFAULT_DB_PASSWORD + "\";' && echo 'GRANT CONNECT,RESOURCE,DBA,GRANT ANY PRIVILEGE,UNLIMITED TABLESPACE TO " +
DEFAULT_DB_USERNAME + ";') | sqlplus -L SYS/" + env.get("ORACLE_PWD") + "@localhost/" + env.get("ORACLE_SID") + " AS SYSDBA")
.containerImage(CONTAINER_IMAGE)
.env(env);
return new TestDatabase(databaseConfig);
}
@Override
public String getAlias() {
return VENDOR;
}
}

View file

@ -1,21 +0,0 @@
package org.keycloak.test.framework.database;
public class PostgresDatabaseSupplier extends AbstractDatabaseSupplier {
public static final String VENDOR = "postgres";
@Override
TestDatabase getTestDatabase() {
DatabaseConfig databaseConfig = new DatabaseConfig()
.vendor(VENDOR)
.username(DEFAULT_DB_USERNAME)
.password(DEFAULT_DB_PASSWORD)
.containerImage("postgres:latest");
return new TestDatabase(databaseConfig);
}
@Override
public String getAlias() {
return VENDOR;
}
}

View file

@ -1,109 +1,13 @@
package org.keycloak.test.framework.database;
import org.jboss.logging.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.oracle.OracleContainer;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import java.time.Duration;
import java.util.Map;
public class TestDatabase {
public interface TestDatabase {
private static final Logger LOGGER = Logger.getLogger(TestDatabase.class);
void start();
private final DatabaseConfig databaseConfig;
void stop();
private GenericContainer<?> container;
public TestDatabase(DatabaseConfig databaseConfig) {
this.databaseConfig = databaseConfig;
}
public void start() {
if (databaseConfig.getContainerImage() != null) {
container = createContainer();
container.withStartupTimeout(Duration.ofMinutes(30))
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(TestDatabase.class)))
.withEnv(databaseConfig.getEnv())
.start();
try {
if (databaseConfig.getPostStartCommand() != null) {
LOGGER.tracev("Running post start command: " + databaseConfig.getPostStartCommand());
String result = container.execInContainer("bash", "-c", databaseConfig.getPostStartCommand()).getStdout();
LOGGER.tracev(result);
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
databaseConfig.url(getJdbcUrl());
if (container instanceof MSSQLServerContainer) {
databaseConfig.username(((JdbcDatabaseContainer<?>) container).getUsername());
databaseConfig.password(((JdbcDatabaseContainer<?>) container).getPassword());
}
}
}
public void stop() {
if (databaseConfig.getContainerImage() != null) {
container.stop();
container = null;
} else if ("dev-mem".equals(databaseConfig.getVendor())) {
// TODO Stop in-mem H2 database
}
}
public Map<String, String> getServerConfig() {
return databaseConfig.toConfig();
}
public String getJdbcUrl() {
return ((JdbcDatabaseContainer<?>)container).getJdbcUrl();
}
private JdbcDatabaseContainer<?> configureJdbcContainer(JdbcDatabaseContainer<?> jdbcDatabaseContainer) {
if (jdbcDatabaseContainer instanceof MSSQLServerContainer) {
return jdbcDatabaseContainer;
}
return jdbcDatabaseContainer
.withDatabaseName("keycloak")
.withUsername(databaseConfig.getUsername())
.withPassword(databaseConfig.getPassword());
}
private GenericContainer<?> createContainer() {
return switch (databaseConfig.getVendor()) {
case PostgresDatabaseSupplier.VENDOR -> {
DockerImageName POSTGRES = DockerImageName.parse(databaseConfig.getContainerImage());
yield configureJdbcContainer(new PostgreSQLContainer<>(POSTGRES));
}
case MariaDBDatabaseSupplier.VENDOR -> {
DockerImageName MARIADB = DockerImageName.parse(databaseConfig.getContainerImage());
yield configureJdbcContainer(new MariaDBContainer<>(MARIADB));
}
case MySQLDatabaseSupplier.VENDOR -> {
DockerImageName MYSQL = DockerImageName.parse(databaseConfig.getContainerImage());
yield configureJdbcContainer(new MySQLContainer<>(MYSQL));
}
case MSSQLServerDatabaseSupplier.VENDOR -> {
DockerImageName MSSQL = DockerImageName.parse(databaseConfig.getContainerImage());
yield configureJdbcContainer(new MSSQLServerContainer<>(MSSQL));
}
case OracleDatabaseSupplier.VENDOR -> {
DockerImageName ORACLE = DockerImageName.parse(databaseConfig.getContainerImage());
yield configureJdbcContainer(new OracleContainer(ORACLE));
}
default -> throw new RuntimeException("Unsupported database: " + databaseConfig.getVendor());
};
}
Map<String, String> serverConfig();
}

View file

@ -2,6 +2,7 @@ package org.keycloak.test.framework.server;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.config.Config;
import org.keycloak.test.framework.database.AbstractContainerTestDatabase;
import org.keycloak.test.framework.database.TestDatabase;
import org.keycloak.test.framework.events.SysLogServer;
import org.keycloak.test.framework.injection.InstanceContext;
@ -53,7 +54,7 @@ public abstract class AbstractKeycloakTestServerSupplier implements Supplier<Key
if (requiresDatabase()) {
TestDatabase testDatabase = instanceContext.getDependency(TestDatabase.class);
testDatabase.getServerConfig().forEach((key, value) -> rawOptions.add("--" + key + "=" + value));
testDatabase.serverConfig().forEach((key, value) -> rawOptions.add("--" + key + "=" + value));
}
KeycloakTestServer server = getServer();

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-db-mariadb</artifactId>
<name>Keycloak Test Framework - MariaDB support</name>
<packaging>jar</packaging>
<description>MariaDB support for Keycloak Test Framework</description>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,15 @@
package org.keycloak.test.framework.database;
public class MariaDBDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "mariadb";
}
@Override
TestDatabase getTestDatabase() {
return new MariaDBTestDatabase();
}
}

View file

@ -0,0 +1,19 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MariaDBContainer;
class MariaDBTestDatabase extends AbstractContainerTestDatabase {
private static final String IMAGE_NAME = "mariadb:latest";
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new MariaDBContainer<>(IMAGE_NAME);
}
@Override
public String getKeycloakDatabaseName() {
return "mariadb";
}
}

View file

@ -0,0 +1,14 @@
package org.keycloak.test.framework.database;
import org.keycloak.test.framework.TestFrameworkExtension;
import org.keycloak.test.framework.injection.Supplier;
import java.util.List;
public class MariaDBTestFrameworkExtension implements TestFrameworkExtension {
@Override
public List<Supplier<?, ?>> suppliers() {
return List.of(new MariaDBDatabaseSupplier());
}
}

View file

@ -0,0 +1 @@
org.keycloak.test.framework.database.MariaDBTestFrameworkExtension

49
test-framework/db-mssql/pom.xml Executable file
View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-db-mssql</artifactId>
<name>Keycloak Test Framework - SQL Server support</name>
<packaging>jar</packaging>
<description>SQL Server support for Keycloak Test Framework</description>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,15 @@
package org.keycloak.test.framework.database;
public class MSSQLServerDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "mssql";
}
@Override
TestDatabase getTestDatabase() {
return new MSSQLServerTestDatabase();
}
}

View file

@ -0,0 +1,19 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer;
class MSSQLServerTestDatabase extends AbstractContainerTestDatabase {
private static final String IMAGE_NAME = "mcr.microsoft.com/mssql/server:latest";
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new MSSQLServerContainer<>(IMAGE_NAME);
}
@Override
public String getKeycloakDatabaseName() {
return "mssql";
}
}

View file

@ -0,0 +1,14 @@
package org.keycloak.test.framework.database;
import org.keycloak.test.framework.TestFrameworkExtension;
import org.keycloak.test.framework.injection.Supplier;
import java.util.List;
public class MSSQLServerTestFrameworkExtension implements TestFrameworkExtension {
@Override
public List<Supplier<?, ?>> suppliers() {
return List.of(new MSSQLServerDatabaseSupplier());
}
}

View file

@ -0,0 +1 @@
org.keycloak.test.framework.database.MSSQLServerTestFrameworkExtension

45
test-framework/db-mysql/pom.xml Executable file
View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-db-mysql</artifactId>
<name>Keycloak Test Framework - MySQL support</name>
<packaging>jar</packaging>
<description>MySQL support for Keycloak Test Framework</description>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,15 @@
package org.keycloak.test.framework.database;
public class MySQLDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "mysql";
}
@Override
TestDatabase getTestDatabase() {
return new MySQLTestDatabase();
}
}

View file

@ -0,0 +1,19 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;
class MySQLTestDatabase extends AbstractContainerTestDatabase {
private static final String IMAGE_NAME = "mysql:latest";
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new MySQLContainer<>(IMAGE_NAME);
}
@Override
public String getKeycloakDatabaseName() {
return "mysql";
}
}

View file

@ -0,0 +1,14 @@
package org.keycloak.test.framework.database;
import org.keycloak.test.framework.TestFrameworkExtension;
import org.keycloak.test.framework.injection.Supplier;
import java.util.List;
public class MySQLTestFrameworkExtension implements TestFrameworkExtension {
@Override
public List<Supplier<?, ?>> suppliers() {
return List.of(new MySQLDatabaseSupplier());
}
}

View file

@ -0,0 +1 @@
org.keycloak.test.framework.database.MySQLTestFrameworkExtension

View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-db-oracle</artifactId>
<name>Keycloak Test Framework - Oracle support</name>
<packaging>jar</packaging>
<description>Oracle support for Keycloak Test Framework</description>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-free</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,16 @@
package org.keycloak.test.framework.database;
public class Oracle19DatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "oracle19";
}
@Override
TestDatabase getTestDatabase() {
return new Oracle19TestDatabase();
}
}

View file

@ -0,0 +1,31 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.oracle.OracleContainer;
import org.testcontainers.utility.DockerImageName;
import java.util.Map;
class Oracle19TestDatabase extends AbstractContainerTestDatabase {
private static final DockerImageName IMAGE_NAME = DockerImageName.parse("docker.io/miquelsi/oracle-19c:19.3").asCompatibleSubstituteFor("gvenzl/oracle-free");
@SuppressWarnings("resource")
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new OracleContainer(IMAGE_NAME)
.withEnv(Map.of("ORACLE_SID", "keycloak", "ORACLE_PWD", "sa"));
}
@Override
public String getPostStartCommand() {
return "(echo 'alter session set \"_ORACLE_SCRIPT\"=true;' && " +
"echo 'GRANT CONNECT,RESOURCE,DBA,GRANT ANY PRIVILEGE,UNLIMITED TABLESPACE TO test;')" +
" | sqlplus -L SYS/sa" + "@localhost/keycloak AS SYSDBA";
}
@Override
public String getKeycloakDatabaseName() {
return "oracle";
}
}

View file

@ -0,0 +1,15 @@
package org.keycloak.test.framework.database;
public class OracleDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "oracle";
}
@Override
TestDatabase getTestDatabase() {
return new OracleTestDatabase();
}
}

View file

@ -0,0 +1,20 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.oracle.OracleContainer;
class OracleTestDatabase extends AbstractContainerTestDatabase {
private static final String IMAGE_NAME = "gvenzl/oracle-free:slim-faststart";
@SuppressWarnings("resource")
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new OracleContainer(IMAGE_NAME);
}
@Override
public String getKeycloakDatabaseName() {
return "oracle";
}
}

View file

@ -0,0 +1,14 @@
package org.keycloak.test.framework.database;
import org.keycloak.test.framework.TestFrameworkExtension;
import org.keycloak.test.framework.injection.Supplier;
import java.util.List;
public class OracleTestFrameworkExtension implements TestFrameworkExtension {
@Override
public List<Supplier<?, ?>> suppliers() {
return List.of(new OracleDatabaseSupplier(), new Oracle19DatabaseSupplier());
}
}

View file

@ -0,0 +1 @@
org.keycloak.test.framework.database.OracleTestFrameworkExtension

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-test-framework-parent</artifactId>
<groupId>org.keycloak.test</groupId>
<version>999.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-test-framework-db-postgres</artifactId>
<name>Keycloak Test Framework - PostgreSQL support</name>
<packaging>jar</packaging>
<description>PostgreSQL support for Keycloak Test Framework</description>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,15 @@
package org.keycloak.test.framework.database;
public class PostgresDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
public String getAlias() {
return "postgres";
}
@Override
TestDatabase getTestDatabase() {
return new PostgresTestDatabase();
}
}

View file

@ -0,0 +1,19 @@
package org.keycloak.test.framework.database;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
class PostgresTestDatabase extends AbstractContainerTestDatabase {
private static final String IMAGE_NAME = "postgres:latest";
@Override
public JdbcDatabaseContainer<?> createContainer() {
return new PostgreSQLContainer<>(IMAGE_NAME);
}
@Override
public String getKeycloakDatabaseName() {
return "postgres";
}
}

View file

@ -0,0 +1,14 @@
package org.keycloak.test.framework.database;
import org.keycloak.test.framework.TestFrameworkExtension;
import org.keycloak.test.framework.injection.Supplier;
import java.util.List;
public class PostgresTestFrameworkExtension implements TestFrameworkExtension {
@Override
public List<Supplier<?, ?>> suppliers() {
return List.of(new PostgresDatabaseSupplier());
}
}

View file

@ -0,0 +1 @@
org.keycloak.test.framework.database.PostgresTestFrameworkExtension

View file

@ -31,37 +31,51 @@
<packaging>jar</packaging>
<description>Example tests to demonstrate the new testing framework</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-bom</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mariadb</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mssql</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mysql</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-oracle</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-postgres</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-ui</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</dependency>
<!-- JDBC Drivers -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View file

@ -33,7 +33,13 @@
<description>Keycloak Test Framework Parent</description>
<modules>
<module>bom</module>
<module>core</module>
<module>db-mariadb</module>
<module>db-mssql</module>
<module>db-mysql</module>
<module>db-oracle</module>
<module>db-postgres</module>
<module>ui</module>
<module>examples</module>
</modules>

View file

@ -31,33 +31,51 @@
<packaging>jar</packaging>
<description>New Keycloak Base Testsuite</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-bom</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-ui</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.10.2</version>
<scope>test</scope>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mariadb</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mssql</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-mysql</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-oracle</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak.test</groupId>
<artifactId>keycloak-test-framework-db-postgres</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</dependency>
<!-- JDBC Drivers -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>