-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Testsuite PoC - Injection framework support for multiple instances #31293
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
Conversation
c6cc311 to
b06a5f2
Compare
test-poc/framework/src/main/java/org/keycloak/test/framework/injection/Supplier.java
Outdated
Show resolved
Hide resolved
stianst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be implemented a bit more cleanly, especially with some of the changes in #31406.
- RequestedInstance can have a ref added to it
- InstanceContext can have a ref added to it
- Supplier can have a default method that returns the ref from the annotation if present in a generic way (https://github.com/keycloak/keycloak/pull/31406/files#diff-d888c9866793d97a2ae142800245479b0701fc4e41697164b24f553c8bfc2c2cR16)
b06a5f2 to
6194637
Compare
Closes keycloak#30613 Signed-off-by: Simon Vacek <[email protected]>
6194637 to
4ec1321
Compare
| if (getDeployedInstance(requestedInstance) != null) { | ||
| throw new RuntimeException("Instance ref redefinition: " + requestedInstance.getRef()); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this? When/why would this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could happen whenever someone uses the same ref or when they don't use ref at all. This check can probably be moved elsewhere, I find it comfortable here, in this loop.
@KeycloakIntegrationTest
public class MyTestClass {
@TestRealm
RealmResource realm1;
@TestRealm
RealmResource realm2;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed on the chat, there's nothing wrong in doing that, and it should just end up with realm1 == realm2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not necessary too, but it may be useful for debugging to just print some warning instead throwing exception. WDYT?
Signed-off-by: stianst <[email protected]>
Signed-off-by: Simon Vacek <[email protected]>
jonkoops
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| Assertions.assertEquals("default", realm1.toRepresentation().getRealm()); | ||
| Assertions.assertEquals("default", realm2.toRepresentation().getRealm()); | ||
| Assertions.assertEquals(realm1, realm2); | ||
|
|
||
| Assertions.assertEquals("another", realm3.toRepresentation().getRealm()); | ||
|
|
||
| Assertions.assertEquals("client1", client.toRepresentation().getClientId()); | ||
| Assertions.assertEquals("default", client2.toRepresentation().getClientId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to make assertions about the internals of the framework, perhaps this should be part of the framework module?
lhanusov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…eycloak#31293) * Testsuite PoC - Injection framework support for multiple instances Closes keycloak#30613 Signed-off-by: Simon Vacek <[email protected]> * Add unit tests for multiple instances Signed-off-by: stianst <[email protected]> * Remove check for ref redefinitions Signed-off-by: Simon Vacek <[email protected]> --------- Signed-off-by: Simon Vacek <[email protected]> Signed-off-by: stianst <[email protected]> Co-authored-by: stianst <[email protected]>
The test framework supports injecting multiple instances of the same resource type. These instances must have a different
ref(an identifier for instances). If an instance does not have a ref, a "default" value is assigned. There can be only one instance of a given type without a specifiedrefin the test class.The
refidentifiers are unique only to the type of an instance. That means this is valid:In this case realm == realm3
If there is a deployed instance found that could fit the requested instance, the Registry has the following behavior to the deployed instance:
TestWebDriver,TestAdminClient,KeycloakIntegrationTest, andTestPageare ignored in this PR.Realms, clients, and users have their names set to their
ref.As this should lay down the basic concept of multiple instances of the same type being deployed within the framework, other issues may follow, for example:
realm-refattribute in the annotation@TestUser(realm-ref="realmWithUsers")Closes #30613