diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7468012884..f8813c6380 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -969,7 +969,7 @@ jobs: uses: ./.github/actions/integration-test-setup - name: Run tests - run: ./mvnw test -f test-framework/pom.xml + run: ./mvnw package -f test-framework/pom.xml base-new-integration-tests: name: Base IT (new) diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/Maven.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/Maven.java index 8e6c5af1a7..d166915949 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/Maven.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/Maven.java @@ -57,16 +57,12 @@ public final class Maven { ArtifactDescriptorResult projectDescriptor = repositorySystem.readArtifactDescriptor( ctx.getRepositorySystemSession(), new ArtifactDescriptorRequest() - .setArtifact(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "pom", project.getVersion())) + .setArtifact(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "pom", project.getVersion())) .setRepositories(remoteRepositories)); List dependencies = new ArrayList<>(projectDescriptor.getDependencies()); dependencies.addAll(projectDescriptor.getManagedDependencies()); Artifact artifact = resolveArtifact(groupId, artifactId, dependencies); - if (artifact == null) { - resolveArtifact(groupId, artifactId, projectDescriptor.getManagedDependencies()); - } - if (artifact == null) { artifact = resolveArtifactRecursively(ctx, projectDescriptor, groupId, artifactId); } diff --git a/test-framework/core/src/main/java/org/keycloak/test/framework/server/AbstractKeycloakTestServerSupplier.java b/test-framework/core/src/main/java/org/keycloak/test/framework/server/AbstractKeycloakTestServerSupplier.java index 5f804eee43..0bd17623a7 100644 --- a/test-framework/core/src/main/java/org/keycloak/test/framework/server/AbstractKeycloakTestServerSupplier.java +++ b/test-framework/core/src/main/java/org/keycloak/test/framework/server/AbstractKeycloakTestServerSupplier.java @@ -58,7 +58,7 @@ public abstract class AbstractKeycloakTestServerSupplier implements Supplier rawOptions) { + public void start(List rawOptions, Set dependencies) { keycloak = new RawKeycloakDistribution(DEBUG, MANUAL_STOP, ENABLE_TLS, RE_CREATE, REMOVE_BUILD_OPTIONS_AFTER_BUILD, REQUEST_PORT); + + for (Dependency dependency : dependencies) { + keycloak.copyProvider(dependency.getGroupId(), dependency.getArtifactId()); + } + keycloak.run(rawOptions).assertStartedDevMode(); } diff --git a/test-framework/core/src/main/java/org/keycloak/test/framework/server/EmbeddedKeycloakTestServer.java b/test-framework/core/src/main/java/org/keycloak/test/framework/server/EmbeddedKeycloakTestServer.java index 6f482e191f..199c7d373f 100644 --- a/test-framework/core/src/main/java/org/keycloak/test/framework/server/EmbeddedKeycloakTestServer.java +++ b/test-framework/core/src/main/java/org/keycloak/test/framework/server/EmbeddedKeycloakTestServer.java @@ -1,9 +1,11 @@ package org.keycloak.test.framework.server; +import io.quarkus.maven.dependency.Dependency; import org.keycloak.Keycloak; import org.keycloak.common.Version; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeoutException; public class EmbeddedKeycloakTestServer implements KeycloakTestServer { @@ -11,10 +13,14 @@ public class EmbeddedKeycloakTestServer implements KeycloakTestServer { private Keycloak keycloak; @Override - public void start(List rawOptions) { - keycloak = Keycloak.builder() - .setVersion(Version.VERSION) - .start(rawOptions); + public void start(List rawOptions, Set dependencies) { + Keycloak.Builder builder = Keycloak.builder().setVersion(Version.VERSION); + + for(Dependency dependency : dependencies) { + builder.addDependency(dependency.getGroupId(), dependency.getArtifactId(), ""); + } + + keycloak = builder.start(rawOptions); } @Override diff --git a/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServer.java b/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServer.java index 6e01fd1912..3bdcdf3543 100644 --- a/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServer.java +++ b/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServer.java @@ -1,10 +1,13 @@ package org.keycloak.test.framework.server; +import io.quarkus.maven.dependency.Dependency; + import java.util.List; +import java.util.Set; public interface KeycloakTestServer { - void start(List rawOptions); + void start(List rawOptions, Set dependencies); void stop(); diff --git a/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServerConfig.java b/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServerConfig.java index c35642c034..4868840fb9 100644 --- a/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServerConfig.java +++ b/test-framework/core/src/main/java/org/keycloak/test/framework/server/KeycloakTestServerConfig.java @@ -1,5 +1,7 @@ package org.keycloak.test.framework.server; +import io.quarkus.maven.dependency.Dependency; + import java.util.Collections; import java.util.Map; import java.util.Set; @@ -16,4 +18,8 @@ public interface KeycloakTestServerConfig { default boolean enableSysLog() { return false; } + default Set dependencies() { + return Collections.emptySet(); + } + } diff --git a/test-framework/core/src/main/java/org/keycloak/test/framework/server/RemoteKeycloakTestServer.java b/test-framework/core/src/main/java/org/keycloak/test/framework/server/RemoteKeycloakTestServer.java index 7a35198999..c057b9f37e 100644 --- a/test-framework/core/src/main/java/org/keycloak/test/framework/server/RemoteKeycloakTestServer.java +++ b/test-framework/core/src/main/java/org/keycloak/test/framework/server/RemoteKeycloakTestServer.java @@ -1,16 +1,19 @@ package org.keycloak.test.framework.server; +import io.quarkus.maven.dependency.Dependency; import org.jboss.logging.Logger; import java.util.List; +import java.util.Set; public class RemoteKeycloakTestServer implements KeycloakTestServer { private static final Logger LOGGER = Logger.getLogger(RemoteKeycloakTestServer.class); @Override - public void start(List rawOptions) { + public void start(List rawOptions, Set dependencies) { LOGGER.infov("Requested server config: {0}", String.join(" ", rawOptions)); + LOGGER.infov("Requested dependencies: {0}", String.join(" ", dependencies.toString())); } @Override diff --git a/test-framework/examples/pom.xml b/test-framework/examples/pom.xml index e5de429d85..fd00e7963d 100755 --- a/test-framework/examples/pom.xml +++ b/test-framework/examples/pom.xml @@ -27,77 +27,13 @@ 4.0.0 keycloak-test-framework-examples - Keycloak Test Framework Examples - jar + Keycloak Test Framework Examples Parent + pom Example tests to demonstrate the new testing framework - - - - org.keycloak.test - keycloak-test-framework-bom - ${project.version} - import - pom - - - - - - - org.keycloak.test - keycloak-test-framework-core - - - org.keycloak.test - keycloak-test-framework-db-mariadb - - - org.keycloak.test - keycloak-test-framework-db-mssql - - - org.keycloak.test - keycloak-test-framework-db-mysql - - - org.keycloak.test - keycloak-test-framework-db-oracle - - - org.keycloak.test - keycloak-test-framework-db-postgres - - - org.keycloak.test - keycloak-test-framework-ui - - - org.jboss.logmanager - jboss-logmanager - test - - - - - - - maven-surefire-plugin - - - org.jboss.logmanager.LogManager - io.quarkus.bootstrap.forkjoin.QuarkusForkJoinWorkerThreadFactory - - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - + + providers + tests + diff --git a/test-framework/examples/providers/pom.xml b/test-framework/examples/providers/pom.xml new file mode 100644 index 0000000000..991852b015 --- /dev/null +++ b/test-framework/examples/providers/pom.xml @@ -0,0 +1,41 @@ + + + + keycloak-test-framework-examples + org.keycloak.test + 999.0.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + + keycloak-test-framework-example-providers + Keycloak Test Framework Example Providers + jar + Example providers used for test framework example tests + + + + org.keycloak + keycloak-core + provided + + + org.keycloak + keycloak-server-spi + provided + + + org.keycloak + keycloak-server-spi-private + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + + + + diff --git a/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProvider.java b/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProvider.java new file mode 100644 index 0000000000..572970303f --- /dev/null +++ b/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProvider.java @@ -0,0 +1,39 @@ +package org.keycloak.providers.example; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.keycloak.models.KeycloakSession; +import org.keycloak.services.resource.RealmResourceProvider; + +/** + * + * @author Simon Vacek + */ +public class MyCustomRealmResourceProvider implements RealmResourceProvider { + + private final KeycloakSession session; + + public MyCustomRealmResourceProvider(KeycloakSession session) { + this.session = session; + } + + @Override + public Object getResource() { + return this; + } + + @Override + public void close() { + + } + + @GET + @Path("hello") + @Produces(MediaType.TEXT_PLAIN) + public Response hello() { + return Response.ok("Hello World!").type(MediaType.TEXT_PLAIN).build(); + } +} diff --git a/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProviderFactory.java b/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProviderFactory.java new file mode 100644 index 0000000000..8274fa56cc --- /dev/null +++ b/test-framework/examples/providers/src/main/java/org/keycloak/providers/example/MyCustomRealmResourceProviderFactory.java @@ -0,0 +1,40 @@ +package org.keycloak.providers.example; + +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.KeycloakSessionFactory; +import org.keycloak.services.resource.RealmResourceProvider; +import org.keycloak.services.resource.RealmResourceProviderFactory; + +/** + * + * @author Simon Vacek + */ +public class MyCustomRealmResourceProviderFactory implements RealmResourceProviderFactory { + + public static final String ID = "custom-provider"; + + @Override + public String getId() { + return ID; + } + + @Override + public RealmResourceProvider create(KeycloakSession session) { + return new MyCustomRealmResourceProvider(session); + } + + @Override + public void init(org.keycloak.Config.Scope config) { + + } + + @Override + public void postInit(KeycloakSessionFactory factory) { + + } + + @Override + public void close() { + + } +} diff --git a/test-framework/examples/providers/src/main/resources/META-INF/beans.xml b/test-framework/examples/providers/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-framework/examples/providers/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory b/test-framework/examples/providers/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory new file mode 100644 index 0000000000..677c734e1a --- /dev/null +++ b/test-framework/examples/providers/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory @@ -0,0 +1 @@ +org.keycloak.providers.example.MyCustomRealmResourceProviderFactory \ No newline at end of file diff --git a/test-framework/examples/tests/pom.xml b/test-framework/examples/tests/pom.xml new file mode 100644 index 0000000000..0c7cd6c715 --- /dev/null +++ b/test-framework/examples/tests/pom.xml @@ -0,0 +1,109 @@ + + + + + + keycloak-test-framework-examples + org.keycloak.test + 999.0.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + keycloak-test-framework-example-tests + Keycloak Test Framework Example Tests + jar + Example tests to demonstrate the new testing framework + + + + + org.keycloak.test + keycloak-test-framework-bom + ${project.version} + import + pom + + + + + + + org.keycloak.test + keycloak-test-framework-core + + + org.keycloak.test + keycloak-test-framework-db-mariadb + + + org.keycloak.test + keycloak-test-framework-db-mssql + + + org.keycloak.test + keycloak-test-framework-db-mysql + + + org.keycloak.test + keycloak-test-framework-db-oracle + + + org.keycloak.test + keycloak-test-framework-db-postgres + + + org.keycloak.test + keycloak-test-framework-ui + + + org.keycloak.test + keycloak-test-framework-example-providers + ${project.version} + test + + + org.jboss.logmanager + jboss-logmanager + test + + + + + + + maven-surefire-plugin + + + org.jboss.logmanager.LogManager + io.quarkus.bootstrap.forkjoin.QuarkusForkJoinWorkerThreadFactory + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/CustomConfigTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/CustomConfigTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/CustomConfigTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/CustomConfigTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/DefaultConfig1Test.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/DefaultConfig1Test.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/DefaultConfig1Test.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/DefaultConfig1Test.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/DefaultConfig2Test.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/DefaultConfig2Test.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/DefaultConfig2Test.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/DefaultConfig2Test.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/EventsTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/EventsTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/EventsTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/EventsTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/FancyRealmTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/FancyRealmTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/FancyRealmTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/FancyRealmTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/GlobalManagedResourcesTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/GlobalManagedResourcesTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/GlobalManagedResourcesTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/GlobalManagedResourcesTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/ManagedResources2Test.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/ManagedResources2Test.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/ManagedResources2Test.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/ManagedResources2Test.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/ManagedResourcesTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/ManagedResourcesTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/ManagedResourcesTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/ManagedResourcesTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/MultipleInstancesTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/MultipleInstancesTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/MultipleInstancesTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/MultipleInstancesTest.java diff --git a/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/MyCustomProviderTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/MyCustomProviderTest.java new file mode 100644 index 0000000000..6860f8862a --- /dev/null +++ b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/MyCustomProviderTest.java @@ -0,0 +1,52 @@ +package org.keycloak.test.examples; + +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.maven.dependency.DependencyBuilder; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.HttpClientBuilder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.keycloak.test.framework.annotations.InjectRealm; +import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; +import org.keycloak.test.framework.realm.ManagedRealm; +import org.keycloak.test.framework.server.KeycloakTestServerConfig; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Set; + + +/** + * + * @author Simon Vacek + */ +@KeycloakIntegrationTest(config = MyCustomProviderTest.ServerConfig.class) +public class MyCustomProviderTest { + + @InjectRealm + ManagedRealm realm; + + @Test + public void httpGetTest() { + String url = realm.getBaseUrl(); + + HttpUriRequest request = new HttpGet(url + "/custom-provider/hello"); + try { + HttpResponse response = HttpClientBuilder.create().build().execute(request); + Assertions.assertEquals(200, response.getStatusLine().getStatusCode()); + + String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + Assertions.assertEquals("Hello World!", content); + } catch (IOException ignored) {} + } + + public static class ServerConfig implements KeycloakTestServerConfig { + + public Set dependencies() { + return Set.of(new DependencyBuilder().setGroupId("org.keycloak.test").setArtifactId("keycloak-test-framework-example-providers").build()); + } + } +} diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/OAuthClientTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/OAuthClientTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/OAuthClientTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/OAuthClientTest.java diff --git a/test-framework/examples/src/test/java/org/keycloak/test/examples/PagesTest.java b/test-framework/examples/tests/src/test/java/org/keycloak/test/examples/PagesTest.java similarity index 100% rename from test-framework/examples/src/test/java/org/keycloak/test/examples/PagesTest.java rename to test-framework/examples/tests/src/test/java/org/keycloak/test/examples/PagesTest.java diff --git a/test-framework/examples/src/test/resources/container-license-acceptance.txt b/test-framework/examples/tests/src/test/resources/container-license-acceptance.txt similarity index 100% rename from test-framework/examples/src/test/resources/container-license-acceptance.txt rename to test-framework/examples/tests/src/test/resources/container-license-acceptance.txt diff --git a/test-framework/examples/src/test/resources/logging.properties b/test-framework/examples/tests/src/test/resources/logging.properties similarity index 100% rename from test-framework/examples/src/test/resources/logging.properties rename to test-framework/examples/tests/src/test/resources/logging.properties