TestSuite PoC - Rename Test prefix to Inject (#31570)

* TestSuite PoC - Rename `Test` prefix to `Inject`

Closes #31522

Signed-off-by: Jon Koops <jonkoops@gmail.com>

* Rename test database annotation

Signed-off-by: stianst <stianst@gmail.com>

---------

Signed-off-by: Jon Koops <jonkoops@gmail.com>
Signed-off-by: stianst <stianst@gmail.com>
Co-authored-by: stianst <stianst@gmail.com>
This commit is contained in:
Jon Koops 2024-07-25 13:13:53 +02:00 committed by GitHub
parent eea1d10e23
commit c92c642fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 92 additions and 99 deletions

View file

@ -6,7 +6,7 @@ import org.keycloak.admin.client.Keycloak;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.representations.info.FeatureRepresentation; import org.keycloak.representations.info.FeatureRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestAdminClient; import org.keycloak.test.framework.annotations.InjectAdminClient;
import org.keycloak.test.framework.server.KeycloakTestServerConfig; import org.keycloak.test.framework.server.KeycloakTestServerConfig;
import java.util.Optional; import java.util.Optional;
@ -15,7 +15,7 @@ import java.util.Set;
@KeycloakIntegrationTest(config = CustomConfigTest.CustomServerConfig.class) @KeycloakIntegrationTest(config = CustomConfigTest.CustomServerConfig.class)
public class CustomConfigTest { public class CustomConfigTest {
@TestAdminClient @InjectAdminClient
Keycloak adminClient; Keycloak adminClient;
@Test @Test

View file

@ -5,14 +5,14 @@ import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.Keycloak; import org.keycloak.admin.client.Keycloak;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestAdminClient; import org.keycloak.test.framework.annotations.InjectAdminClient;
import java.util.List; import java.util.List;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class DefaultConfig1Test { public class DefaultConfig1Test {
@TestAdminClient @InjectAdminClient
Keycloak adminClient; Keycloak adminClient;
@Test @Test

View file

@ -5,14 +5,14 @@ import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.Keycloak; import org.keycloak.admin.client.Keycloak;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestAdminClient; import org.keycloak.test.framework.annotations.InjectAdminClient;
import java.util.List; import java.util.List;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class DefaultConfig2Test { public class DefaultConfig2Test {
@TestAdminClient @InjectAdminClient
Keycloak adminClient; Keycloak adminClient;
@Test @Test

View file

@ -6,24 +6,21 @@ import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource; import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestClient; import org.keycloak.test.framework.annotations.InjectClient;
import org.keycloak.test.framework.annotations.TestRealm; import org.keycloak.test.framework.annotations.InjectRealm;
import org.keycloak.test.framework.annotations.TestUser; import org.keycloak.test.framework.annotations.InjectUser;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.realm.DefaultClientConfig;
import org.keycloak.test.framework.realm.DefaultRealmConfig;
import org.keycloak.test.framework.realm.DefaultUserConfig;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class GlobalManagedResourcesTest { public class GlobalManagedResourcesTest {
@TestRealm(lifecycle = LifeCycle.GLOBAL) @InjectRealm(lifecycle = LifeCycle.GLOBAL)
RealmResource realmResource; RealmResource realmResource;
@TestClient(lifecycle = LifeCycle.GLOBAL) @InjectClient(lifecycle = LifeCycle.GLOBAL)
ClientResource clientResource; ClientResource clientResource;
@TestUser(lifecycle = LifeCycle.GLOBAL) @InjectUser(lifecycle = LifeCycle.GLOBAL)
UserResource userResource; UserResource userResource;
@Test @Test

View file

@ -6,8 +6,8 @@ import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestClient; import org.keycloak.test.framework.annotations.InjectClient;
import org.keycloak.test.framework.annotations.TestRealm; import org.keycloak.test.framework.annotations.InjectRealm;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
import java.util.List; import java.util.List;
@ -15,10 +15,10 @@ import java.util.List;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class ManagedResources2Test { public class ManagedResources2Test {
@TestRealm(lifecycle = LifeCycle.CLASS) @InjectRealm(lifecycle = LifeCycle.CLASS)
RealmResource realmResource; RealmResource realmResource;
@TestClient @InjectClient
ClientResource clientResource; ClientResource clientResource;
@Test @Test

View file

@ -7,9 +7,9 @@ import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource; import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestClient; import org.keycloak.test.framework.annotations.InjectClient;
import org.keycloak.test.framework.annotations.TestRealm; import org.keycloak.test.framework.annotations.InjectRealm;
import org.keycloak.test.framework.annotations.TestUser; import org.keycloak.test.framework.annotations.InjectUser;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
import java.util.List; import java.util.List;
@ -17,13 +17,13 @@ import java.util.List;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class ManagedResourcesTest { public class ManagedResourcesTest {
@TestRealm(lifecycle = LifeCycle.CLASS) @InjectRealm(lifecycle = LifeCycle.CLASS)
RealmResource realmResource; RealmResource realmResource;
@TestClient @InjectClient
ClientResource clientResource; ClientResource clientResource;
@TestUser @InjectUser
UserResource userResource; UserResource userResource;
@Test @Test

View file

@ -5,28 +5,27 @@ import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.resource.ClientResource; import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestClient; import org.keycloak.test.framework.annotations.InjectClient;
import org.keycloak.test.framework.annotations.TestRealm; import org.keycloak.test.framework.annotations.InjectRealm;
import org.keycloak.test.framework.realm.RealmConfig; import org.keycloak.test.framework.realm.RealmConfig;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class MultipleInstancesTest { public class MultipleInstancesTest {
@TestRealm @InjectRealm
RealmResource realm1; RealmResource realm1;
@TestRealm @InjectRealm
RealmResource realm2; RealmResource realm2;
@TestRealm(ref = "another", config = CustomRealmConfig.class) @InjectRealm(ref = "another", config = CustomRealmConfig.class)
RealmResource realm3; RealmResource realm3;
@TestClient(ref = "client1") @InjectClient(ref = "client1")
ClientResource client; ClientResource client;
@TestClient @InjectClient
ClientResource client2; ClientResource client2;
@Test @Test

View file

@ -3,16 +3,16 @@ package org.keycloak.test.examples;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.page.LoginPage; import org.keycloak.test.framework.page.LoginPage;
import org.keycloak.test.framework.annotations.TestPage; import org.keycloak.test.framework.annotations.InjectPage;
import org.keycloak.test.framework.page.WelcomePage; import org.keycloak.test.framework.page.WelcomePage;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class PagesTest { public class PagesTest {
@TestPage @InjectPage
WelcomePage welcomePage; WelcomePage welcomePage;
@TestPage @InjectPage
LoginPage loginPage; LoginPage loginPage;
@Test @Test

View file

@ -5,9 +5,9 @@ import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.Keycloak; import org.keycloak.admin.client.Keycloak;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; import org.keycloak.test.framework.annotations.KeycloakIntegrationTest;
import org.keycloak.test.framework.annotations.TestAdminClient; import org.keycloak.test.framework.annotations.InjectAdminClient;
import org.keycloak.test.framework.page.WelcomePage; import org.keycloak.test.framework.page.WelcomePage;
import org.keycloak.test.framework.annotations.TestWebDriver; import org.keycloak.test.framework.annotations.InjectWebDriver;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import java.util.List; import java.util.List;
@ -15,10 +15,10 @@ import java.util.List;
@KeycloakIntegrationTest @KeycloakIntegrationTest
public class WelcomePageTest { public class WelcomePageTest {
@TestWebDriver @InjectWebDriver
WebDriver driver; WebDriver driver;
@TestAdminClient @InjectAdminClient
Keycloak adminClient; Keycloak adminClient;
@Test @Test

View file

@ -3,7 +3,7 @@ package org.keycloak.test.framework.admin;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.Keycloak; import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder; import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.test.framework.annotations.TestAdminClient; import org.keycloak.test.framework.annotations.InjectAdminClient;
import org.keycloak.test.framework.config.Config; import org.keycloak.test.framework.config.Config;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
@ -11,11 +11,11 @@ import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
import org.keycloak.test.framework.server.KeycloakTestServer; import org.keycloak.test.framework.server.KeycloakTestServer;
public class KeycloakAdminClientSupplier implements Supplier<Keycloak, TestAdminClient> { public class KeycloakAdminClientSupplier implements Supplier<Keycloak, InjectAdminClient> {
@Override @Override
public Class<TestAdminClient> getAnnotationClass() { public Class<InjectAdminClient> getAnnotationClass() {
return TestAdminClient.class; return InjectAdminClient.class;
} }
@Override @Override
@ -24,7 +24,7 @@ public class KeycloakAdminClientSupplier implements Supplier<Keycloak, TestAdmin
} }
@Override @Override
public Keycloak getValue(InstanceContext<Keycloak, TestAdminClient> instanceContext) { public Keycloak getValue(InstanceContext<Keycloak, InjectAdminClient> instanceContext) {
KeycloakTestServer testServer = instanceContext.getDependency(KeycloakTestServer.class); KeycloakTestServer testServer = instanceContext.getDependency(KeycloakTestServer.class);
return KeycloakBuilder.builder() return KeycloakBuilder.builder()
.serverUrl(testServer.getBaseUrl()) .serverUrl(testServer.getBaseUrl())
@ -41,12 +41,12 @@ public class KeycloakAdminClientSupplier implements Supplier<Keycloak, TestAdmin
} }
@Override @Override
public boolean compatible(InstanceContext<Keycloak, TestAdminClient> a, RequestedInstance<Keycloak, TestAdminClient> b) { public boolean compatible(InstanceContext<Keycloak, InjectAdminClient> a, RequestedInstance<Keycloak, InjectAdminClient> b) {
return true; return true;
} }
@Override @Override
public void close(InstanceContext<Keycloak, TestAdminClient> instanceContext) { public void close(InstanceContext<Keycloak, InjectAdminClient> instanceContext) {
instanceContext.getValue().close(); instanceContext.getValue().close();
} }

View file

@ -8,6 +8,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestAdminClient { public @interface InjectAdminClient {
} }

View file

@ -11,7 +11,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestClient { public @interface InjectClient {
Class<? extends ClientConfig> config() default DefaultClientConfig.class; Class<? extends ClientConfig> config() default DefaultClientConfig.class;

View file

@ -7,5 +7,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestPage { public @interface InjectPage {
} }

View file

@ -11,7 +11,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestRealm { public @interface InjectRealm {
Class<? extends RealmConfig> config() default DefaultRealmConfig.class; Class<? extends RealmConfig> config() default DefaultRealmConfig.class;

View file

@ -10,7 +10,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface KeycloakTestDatabase { public @interface InjectTestDatabase {
Class<? extends DatabaseConfig> config() default DatabaseConfig.class; Class<? extends DatabaseConfig> config() default DatabaseConfig.class;

View file

@ -11,7 +11,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestUser { public @interface InjectUser {
Class<? extends UserConfig> config() default DefaultUserConfig.class; Class<? extends UserConfig> config() default DefaultUserConfig.class;

View file

@ -7,4 +7,4 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface TestWebDriver { } public @interface InjectWebDriver { }

View file

@ -1,19 +1,19 @@
package org.keycloak.test.framework.database; package org.keycloak.test.framework.database;
import org.keycloak.test.framework.annotations.KeycloakTestDatabase; import org.keycloak.test.framework.annotations.InjectTestDatabase;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
public abstract class AbstractDatabaseSupplier implements Supplier<TestDatabase, KeycloakTestDatabase> { public abstract class AbstractDatabaseSupplier implements Supplier<TestDatabase, InjectTestDatabase> {
protected static final String DEFAULT_DB_USERNAME = "keycloak"; protected static final String DEFAULT_DB_USERNAME = "keycloak";
protected static final String DEFAULT_DB_PASSWORD = "Password1!"; protected static final String DEFAULT_DB_PASSWORD = "Password1!";
@Override @Override
public Class<KeycloakTestDatabase> getAnnotationClass() { public Class<InjectTestDatabase> getAnnotationClass() {
return KeycloakTestDatabase.class; return InjectTestDatabase.class;
} }
@Override @Override
@ -22,14 +22,14 @@ public abstract class AbstractDatabaseSupplier implements Supplier<TestDatabase,
} }
@Override @Override
public TestDatabase getValue(InstanceContext<TestDatabase, KeycloakTestDatabase> instanceContext) { public TestDatabase getValue(InstanceContext<TestDatabase, InjectTestDatabase> instanceContext) {
TestDatabase testDatabase = getTestDatabase(); TestDatabase testDatabase = getTestDatabase();
testDatabase.start(); testDatabase.start();
return testDatabase; return testDatabase;
} }
@Override @Override
public boolean compatible(InstanceContext<TestDatabase, KeycloakTestDatabase> a, RequestedInstance<TestDatabase, KeycloakTestDatabase> b) { public boolean compatible(InstanceContext<TestDatabase, InjectTestDatabase> a, RequestedInstance<TestDatabase, InjectTestDatabase> b) {
return true; return true;
} }
@ -41,7 +41,7 @@ public abstract class AbstractDatabaseSupplier implements Supplier<TestDatabase,
abstract TestDatabase getTestDatabase(); abstract TestDatabase getTestDatabase();
@Override @Override
public void close(InstanceContext<TestDatabase, KeycloakTestDatabase> instanceContext) { public void close(InstanceContext<TestDatabase, InjectTestDatabase> instanceContext) {
instanceContext.getValue().stop(); instanceContext.getValue().stop();
} }
} }

View file

@ -1,6 +1,6 @@
package org.keycloak.test.framework.page; package org.keycloak.test.framework.page;
import org.keycloak.test.framework.annotations.TestPage; import org.keycloak.test.framework.annotations.InjectPage;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
@ -8,11 +8,11 @@ import org.openqa.selenium.WebDriver;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
public class PageSupplier implements Supplier<AbstractPage, TestPage> { public class PageSupplier implements Supplier<AbstractPage, InjectPage> {
@Override @Override
public Class<TestPage> getAnnotationClass() { public Class<InjectPage> getAnnotationClass() {
return TestPage.class; return InjectPage.class;
} }
@Override @Override
@ -21,13 +21,13 @@ public class PageSupplier implements Supplier<AbstractPage, TestPage> {
} }
@Override @Override
public AbstractPage getValue(InstanceContext<AbstractPage, TestPage> instanceContext) { public AbstractPage getValue(InstanceContext<AbstractPage, InjectPage> instanceContext) {
WebDriver webDriver = instanceContext.getDependency(WebDriver.class); WebDriver webDriver = instanceContext.getDependency(WebDriver.class);
return createPage(webDriver, instanceContext.getRequestedValueType()); return createPage(webDriver, instanceContext.getRequestedValueType());
} }
@Override @Override
public boolean compatible(InstanceContext<AbstractPage, TestPage> a, RequestedInstance<AbstractPage, TestPage> b) { public boolean compatible(InstanceContext<AbstractPage, InjectPage> a, RequestedInstance<AbstractPage, InjectPage> b) {
return true; return true;
} }

View file

@ -4,20 +4,19 @@ import jakarta.ws.rs.core.Response;
import org.keycloak.admin.client.resource.ClientResource; import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.test.framework.annotations.TestClient; import org.keycloak.test.framework.annotations.InjectClient;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
import org.keycloak.test.framework.injection.SupplierHelpers; import org.keycloak.test.framework.injection.SupplierHelpers;
public class ClientSupplier implements Supplier<ClientResource, TestClient> { public class ClientSupplier implements Supplier<ClientResource, InjectClient> {
private static final String CLIENT_UUID_KEY = "clientUuid"; private static final String CLIENT_UUID_KEY = "clientUuid";
@Override @Override
public Class<TestClient> getAnnotationClass() { public Class<InjectClient> getAnnotationClass() {
return TestClient.class; return InjectClient.class;
} }
@Override @Override
@ -26,7 +25,7 @@ public class ClientSupplier implements Supplier<ClientResource, TestClient> {
} }
@Override @Override
public ClientResource getValue(InstanceContext<ClientResource, TestClient> instanceContext) { public ClientResource getValue(InstanceContext<ClientResource, InjectClient> instanceContext) {
RealmResource realm = instanceContext.getDependency(RealmResource.class); RealmResource realm = instanceContext.getDependency(RealmResource.class);
ClientConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config()); ClientConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config());
@ -50,12 +49,12 @@ public class ClientSupplier implements Supplier<ClientResource, TestClient> {
} }
@Override @Override
public boolean compatible(InstanceContext<ClientResource, TestClient> a, RequestedInstance<ClientResource, TestClient> b) { public boolean compatible(InstanceContext<ClientResource, InjectClient> a, RequestedInstance<ClientResource, InjectClient> b) {
return a.getAnnotation().config().equals(b.getAnnotation().config()); return a.getAnnotation().config().equals(b.getAnnotation().config());
} }
@Override @Override
public void close(InstanceContext<ClientResource, TestClient> instanceContext) { public void close(InstanceContext<ClientResource, InjectClient> instanceContext) {
instanceContext.getValue().remove(); instanceContext.getValue().remove();
} }

View file

@ -3,20 +3,19 @@ package org.keycloak.test.framework.realm;
import org.keycloak.admin.client.Keycloak; import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.test.framework.annotations.TestRealm; import org.keycloak.test.framework.annotations.InjectRealm;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
import org.keycloak.test.framework.injection.SupplierHelpers; import org.keycloak.test.framework.injection.SupplierHelpers;
public class RealmSupplier implements Supplier<RealmResource, TestRealm> { public class RealmSupplier implements Supplier<RealmResource, InjectRealm> {
private static final String REALM_NAME_KEY = "realmName"; private static final String REALM_NAME_KEY = "realmName";
@Override @Override
public Class<TestRealm> getAnnotationClass() { public Class<InjectRealm> getAnnotationClass() {
return TestRealm.class; return InjectRealm.class;
} }
@Override @Override
@ -25,7 +24,7 @@ public class RealmSupplier implements Supplier<RealmResource, TestRealm> {
} }
@Override @Override
public RealmResource getValue(InstanceContext<RealmResource, TestRealm> instanceContext) { public RealmResource getValue(InstanceContext<RealmResource, InjectRealm> instanceContext) {
Keycloak adminClient = instanceContext.getDependency(Keycloak.class); Keycloak adminClient = instanceContext.getDependency(Keycloak.class);
RealmConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config()); RealmConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config());
@ -48,12 +47,12 @@ public class RealmSupplier implements Supplier<RealmResource, TestRealm> {
} }
@Override @Override
public boolean compatible(InstanceContext<RealmResource, TestRealm> a, RequestedInstance<RealmResource, TestRealm> b) { public boolean compatible(InstanceContext<RealmResource, InjectRealm> a, RequestedInstance<RealmResource, InjectRealm> b) {
return a.getAnnotation().config().equals(b.getAnnotation().config()); return a.getAnnotation().config().equals(b.getAnnotation().config());
} }
@Override @Override
public void close(InstanceContext<RealmResource, TestRealm> instanceContext) { public void close(InstanceContext<RealmResource, InjectRealm> instanceContext) {
instanceContext.getValue().remove(); instanceContext.getValue().remove();
} }

View file

@ -4,20 +4,19 @@ import jakarta.ws.rs.core.Response;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource; import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.test.framework.annotations.TestUser; import org.keycloak.test.framework.annotations.InjectUser;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
import org.keycloak.test.framework.injection.Supplier; import org.keycloak.test.framework.injection.Supplier;
import org.keycloak.test.framework.injection.SupplierHelpers; import org.keycloak.test.framework.injection.SupplierHelpers;
public class UserSupplier implements Supplier<UserResource, TestUser> { public class UserSupplier implements Supplier<UserResource, InjectUser> {
private static final String USER_UUID_KEY = "userUuid"; private static final String USER_UUID_KEY = "userUuid";
@Override @Override
public Class<TestUser> getAnnotationClass() { public Class<InjectUser> getAnnotationClass() {
return TestUser.class; return InjectUser.class;
} }
@Override @Override
@ -26,7 +25,7 @@ public class UserSupplier implements Supplier<UserResource, TestUser> {
} }
@Override @Override
public UserResource getValue(InstanceContext<UserResource, TestUser> instanceContext) { public UserResource getValue(InstanceContext<UserResource, InjectUser> instanceContext) {
RealmResource realm = instanceContext.getDependency(RealmResource.class); RealmResource realm = instanceContext.getDependency(RealmResource.class);
UserConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config()); UserConfig config = SupplierHelpers.getInstance(instanceContext.getAnnotation().config());
@ -50,12 +49,12 @@ public class UserSupplier implements Supplier<UserResource, TestUser> {
} }
@Override @Override
public boolean compatible(InstanceContext<UserResource, TestUser> a, RequestedInstance<UserResource, TestUser> b) { public boolean compatible(InstanceContext<UserResource, InjectUser> a, RequestedInstance<UserResource, InjectUser> b) {
return a.getAnnotation().config().equals(b.getAnnotation().config()); return a.getAnnotation().config().equals(b.getAnnotation().config());
} }
@Override @Override
public void close(InstanceContext<UserResource, TestUser> instanceContext) { public void close(InstanceContext<UserResource, InjectUser> instanceContext) {
instanceContext.getValue().remove(); instanceContext.getValue().remove();
} }

View file

@ -1,6 +1,6 @@
package org.keycloak.test.framework.webdriver; package org.keycloak.test.framework.webdriver;
import org.keycloak.test.framework.annotations.TestWebDriver; import org.keycloak.test.framework.annotations.InjectWebDriver;
import org.keycloak.test.framework.injection.InstanceContext; import org.keycloak.test.framework.injection.InstanceContext;
import org.keycloak.test.framework.injection.LifeCycle; import org.keycloak.test.framework.injection.LifeCycle;
import org.keycloak.test.framework.injection.RequestedInstance; import org.keycloak.test.framework.injection.RequestedInstance;
@ -11,11 +11,11 @@ import org.openqa.selenium.remote.AbstractDriverOptions;
import java.time.Duration; import java.time.Duration;
public abstract class AbstractWebDriverSupplier implements Supplier<WebDriver, TestWebDriver> { public abstract class AbstractWebDriverSupplier implements Supplier<WebDriver, InjectWebDriver> {
@Override @Override
public Class<TestWebDriver> getAnnotationClass() { public Class<InjectWebDriver> getAnnotationClass() {
return TestWebDriver.class; return InjectWebDriver.class;
} }
@Override @Override
@ -24,22 +24,22 @@ public abstract class AbstractWebDriverSupplier implements Supplier<WebDriver, T
} }
@Override @Override
public WebDriver getValue(InstanceContext<WebDriver, TestWebDriver> instanceContext) { public WebDriver getValue(InstanceContext<WebDriver, InjectWebDriver> instanceContext) {
return getWebDriver(); return getWebDriver();
} }
@Override @Override
public boolean compatible(InstanceContext<WebDriver, TestWebDriver> a, RequestedInstance<WebDriver, TestWebDriver> b) { public boolean compatible(InstanceContext<WebDriver, InjectWebDriver> a, RequestedInstance<WebDriver, InjectWebDriver> b) {
return true; return true;
} }
@Override @Override
public LifeCycle getLifeCycle(TestWebDriver annotation) { public LifeCycle getLifeCycle(InjectWebDriver annotation) {
return LifeCycle.GLOBAL; return LifeCycle.GLOBAL;
} }
@Override @Override
public void close(InstanceContext<WebDriver, TestWebDriver> instanceContext) { public void close(InstanceContext<WebDriver, InjectWebDriver> instanceContext) {
instanceContext.getValue().quit(); instanceContext.getValue().quit();
} }