-
Notifications
You must be signed in to change notification settings - Fork 7.9k
JUnit 5 test framework PoC #29517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
JUnit 5 test framework PoC #29517
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?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-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-tests-base</artifactId> | ||
| <name>Keycloak Base Tests</name> | ||
| <packaging>jar</packaging> | ||
| <description>Example tests to demonstrate new testing framework</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.keycloak.test</groupId> | ||
| <artifactId>keycloak-test-junit5-framework</artifactId> | ||
| <version>999.0.0-SNAPSHOT</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> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
37 changes: 37 additions & 0 deletions
37
test-poc/base/src/test/java/org/keycloak/test/base/CustomConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.keycloak.test.base; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.keycloak.admin.client.Keycloak; | ||
| import org.keycloak.common.Profile; | ||
| import org.keycloak.representations.info.FeatureRepresentation; | ||
| import org.keycloak.test.framework.KeycloakIntegrationTest; | ||
| import org.keycloak.test.framework.TestAdminClient; | ||
| import org.keycloak.test.framework.server.KeycloakTestServerConfig; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| @KeycloakIntegrationTest(config = CustomConfigTest.CustomServerConfig.class) | ||
| public class CustomConfigTest { | ||
|
|
||
| @TestAdminClient | ||
| Keycloak adminClient; | ||
|
|
||
| @Test | ||
| public void testUpdateEmailFeatureEnabled() { | ||
| Optional<FeatureRepresentation> updateEmailFeature = adminClient.serverInfo().getInfo().getFeatures().stream().filter(f -> f.getName().equals(Profile.Feature.UPDATE_EMAIL.name())).findFirst(); | ||
| Assertions.assertTrue(updateEmailFeature.isPresent()); | ||
| Assertions.assertTrue(updateEmailFeature.get().isEnabled()); | ||
| } | ||
|
|
||
| public static class CustomServerConfig implements KeycloakTestServerConfig { | ||
|
|
||
| @Override | ||
| public Set<String> features() { | ||
| return Set.of("update-email"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
test-poc/base/src/test/java/org/keycloak/test/base/DefaultConfig1Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.keycloak.test.base; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.keycloak.admin.client.Keycloak; | ||
| import org.keycloak.representations.idm.RealmRepresentation; | ||
| import org.keycloak.test.framework.KeycloakIntegrationTest; | ||
| import org.keycloak.test.framework.TestAdminClient; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @KeycloakIntegrationTest | ||
| public class DefaultConfig1Test { | ||
|
|
||
| @TestAdminClient | ||
| Keycloak adminClient; | ||
|
|
||
| @Test | ||
| public void testAdminClient() { | ||
| List<RealmRepresentation> realms = adminClient.realms().findAll(); | ||
| Assertions.assertFalse(realms.isEmpty()); | ||
jonkoops marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
24 changes: 24 additions & 0 deletions
24
test-poc/base/src/test/java/org/keycloak/test/base/DefaultConfig2Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.keycloak.test.base; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.keycloak.admin.client.Keycloak; | ||
| import org.keycloak.representations.idm.RealmRepresentation; | ||
| import org.keycloak.test.framework.KeycloakIntegrationTest; | ||
| import org.keycloak.test.framework.TestAdminClient; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @KeycloakIntegrationTest | ||
| public class DefaultConfig2Test { | ||
|
|
||
| @TestAdminClient | ||
| Keycloak adminClient; | ||
|
|
||
| @Test | ||
| public void testAdminClient() { | ||
| List<RealmRepresentation> realms = adminClient.realms().findAll(); | ||
| Assertions.assertFalse(realms.isEmpty()); | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
test-poc/base/src/test/java/org/keycloak/test/base/ManagedResourcesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package org.keycloak.test.base; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.keycloak.admin.client.resource.ClientResource; | ||
| import org.keycloak.admin.client.resource.RealmResource; | ||
| import org.keycloak.representations.idm.ClientRepresentation; | ||
| import org.keycloak.test.framework.KeycloakIntegrationTest; | ||
| import org.keycloak.test.framework.TestClient; | ||
| import org.keycloak.test.framework.TestRealm; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @KeycloakIntegrationTest | ||
| public class ManagedResourcesTest { | ||
|
|
||
| @TestRealm | ||
| RealmResource realmResource; | ||
|
|
||
| @TestClient | ||
| ClientResource clientResource; | ||
|
|
||
| @Test | ||
| public void testCreatedRealm() { | ||
| Assertions.assertEquals("ManagedResourcesTest", realmResource.toRepresentation().getRealm()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreatedClient() { | ||
| Assertions.assertEquals("ManagedResourcesTest", clientResource.toRepresentation().getClientId()); | ||
|
|
||
| List<ClientRepresentation> clients = realmResource.clients().findByClientId("ManagedResourcesTest"); | ||
| Assertions.assertEquals(1, clients.size()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| loggers=org.keycloak.test | ||
| logger.org.keycloak.test.level=TRACE | ||
|
|
||
| logger.handlers=CONSOLE | ||
|
|
||
| handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler | ||
| handler.CONSOLE.properties=autoFlush | ||
| handler.CONSOLE.level=ERROR | ||
| handler.CONSOLE.autoFlush=true | ||
| handler.CONSOLE.formatter=PATTERN | ||
|
|
||
| # The log format pattern for both logs | ||
| formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter | ||
| formatter.PATTERN.properties=pattern | ||
| formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p %t [%c] %m%n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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-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-junit5-framework</artifactId> | ||
| <name>Keycloak JUnit 5 testing framework</name> | ||
| <packaging>jar</packaging> | ||
| <description>PoC JUnit 5 testing framework for Keycloak</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-admin-client</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.keycloak</groupId> | ||
| <artifactId>keycloak-junit5</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| </project> |
17 changes: 17 additions & 0 deletions
17
test-poc/framework/src/main/java/org/keycloak/test/framework/KeycloakIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.keycloak.test.framework; | ||
|
|
||
| import org.keycloak.test.framework.server.DefaultKeycloakTestServerConfig; | ||
| import org.keycloak.test.framework.server.KeycloakTestServerConfig; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| public @interface KeycloakIntegrationTest { | ||
|
|
||
| Class<? extends KeycloakTestServerConfig> config() default DefaultKeycloakTestServerConfig.class; | ||
|
|
||
| } |
50 changes: 50 additions & 0 deletions
50
...framework/src/main/java/org/keycloak/test/framework/KeycloakIntegrationTestExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.keycloak.test.framework; | ||
|
|
||
| import org.junit.jupiter.api.extension.AfterAllCallback; | ||
| import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
| import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.keycloak.test.framework.injection.Registry; | ||
|
|
||
| public class KeycloakIntegrationTestExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback { | ||
|
|
||
| @Override | ||
| public void beforeAll(ExtensionContext context) { | ||
| if (isExtensionEnabled(context)) { | ||
| getRegistry(context).beforeAll(context.getRequiredTestClass()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void beforeEach(ExtensionContext context) { | ||
| if (isExtensionEnabled(context)) { | ||
| getRegistry(context).beforeEach(context.getRequiredTestInstance()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void afterAll(ExtensionContext context) { | ||
| if (isExtensionEnabled(context)) { | ||
| getRegistry(context).afterAll(); | ||
| } | ||
| } | ||
|
|
||
| private boolean isExtensionEnabled(ExtensionContext context) { | ||
| return context.getRequiredTestClass().isAnnotationPresent(KeycloakIntegrationTest.class); | ||
| } | ||
|
|
||
| private Registry getRegistry(ExtensionContext context) { | ||
| ExtensionContext.Store store = getStore(context); | ||
| Registry registry = (Registry) store.getOrComputeIfAbsent(Registry.class, r -> new Registry()); | ||
| registry.setCurrentContext(context); | ||
| return registry; | ||
| } | ||
|
|
||
| private ExtensionContext.Store getStore(ExtensionContext context) { | ||
| while (context.getParent().isPresent()) { | ||
| context = context.getParent().get(); | ||
| } | ||
| return context.getStore(ExtensionContext.Namespace.create(getClass())); | ||
| } | ||
|
|
||
| } |
13 changes: 13 additions & 0 deletions
13
test-poc/framework/src/main/java/org/keycloak/test/framework/TestAdminClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.keycloak.test.framework; | ||
|
|
||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.FIELD) | ||
| public @interface TestAdminClient { | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.