8000 Migrate Organization Invitation Management tests into new testsuite by hammadxcm · Pull Request #48227 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Migrate Organization Invitation Management tests into new testsuite - #48227

Closed
hammadxcm wants to merge 4 commits into
keycloak:mainfrom
hammadxcm:migrate-organization-invitation-management-tests
Closed

hammadxcm wants to merge 4 commits into
keycloak:mainfrom
hammadxcm:migrate-organization-invitation-management-tests

Conversation

@hammadxcm
@hammadxcm hammadxcm commented Apr 18, 2026 •
Copy link
Copy Markdown
Contributor

Closes #48279

Parent tracking issue: #47926

Part of #48178 (reopened after #48203 — closed under the 2-PR-for-new-contributors rule while four PRs were briefly open. I've since closed #48207 too, so this + #48204 are the only two open).

Migrates OrganizationInvitationManagementTest from testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/admin/ to the new test framework under tests/base/src/test/java/org/keycloak/tests/organization/admin/.

All 15 test methods are pure organization admin-API checks (invitation CRUD, pagination, filtering, search, cross-org isolation, disabled-org behaviour) and required no logic changes — only the framework wiring differs:

  • Extends the new-framework AbstractOrganizationTest (JUnit 5, @InjectRealm).
  • @KeycloakIntegrationTest added at class level.
  • SMTP is supplied via @InjectMailServer MailServer — the GreenMailSupplier already intercepts the realm config, so the manual SMTP override from configureTestRealm is no longer needed.
  • setTimeOffset(int) → @InjectTimeOffSet TimeOffSet.
  • OrganizationAttributeUpdater (not ported to the new framework) is replaced with a local setOrganizationEnabled helper that returns a restore Runnable — same disable/re-enable semantics. (Open question from review: whether to keep this local helper or port OrganizationAttributeUpdater — pending @lhanusov input.)
  • JUnit 4 annotations/assertions swapped for JUnit 5; Hamcrest matchers unchanged.
  • All inline test comments from the original file are preserved.

The remaining admin tests in #48178 (OrganizationTest, OrganizationInvitationLinkTest, OrganizationThemeTest, IdentityProviderThemeConfigTest) still depend on broker/UI infrastructure (legacy bc/BrokerConfiguration, @Page / Graphene) that has no direct equivalent in the new framework yet, so they are not part of this PR.

@vramik vramik left a comment •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hammadxcm for the PR.

I have created #48279 for this PR. Please reference it in the PR.

Overall LGTM, but please revert the comments removal.

@lhanusov I'd like to hear your thoughts about replacing OrganizationAttributeUpdater with private static Runnable setOrganizationEnabled(OrganizationResource org, boolean enabled), thank you.

@vramik
vramik requested a review from lhanusov April 20, 2026 14:47

/**
* Integration tests for Organization Invitation Management functionality
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, revert this change, I don't see any benefit of it

private OrganizationResource organization;
private String organizationId;

@Before
@BeforeEach
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove it and replace it with RealmConfig implementation

@@ -86,14 +78,14 @@ public void testCreateAndListInvitations() {

// List invitations
List<OrganizationInvitationRepresentation> invitations = organization.invitations().list();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, revert this change, I don't see any benefit of it

assertThat(invitations, hasSize(2));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

public void testSendInvitationToDisabledOrganization() throws Exception {
try (OrganizationAttributeUpdater oau = new OrganizationAttributeUpdater(organization).setEnabled(false).update()) {
public void testSendInvitationToDisabledOrganization() {
Runnable restore = setOrganizationEnabled(organization, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use managedRealm and updateWithCleanup instead

@lhanusov lhanusov left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hammadxcm , thanks for contribution. I just want to point out the issue was created by @vramik and he planned to work on it. Your contribution is fine, but it lacks some context and those indentation changes doesn't make sense. Next time, please, start with issues marked with help-wanted, or good-first-issue.

I see, you are probably using some LLM tool or agent, for finding the easy looking issue and trying to deliver a PR that's fine, but if the contributor doesn't know the context, it adds additional work on reviewer, which is time consuming and at the end waste of time.

Please, check for comments and apply those changes

public void testInvitationWorksAfterReEnablingOrganization() throws Exception {
try (OrganizationAttributeUpdater oau = new OrganizationAttributeUpdater(organization).setEnabled(false).update()) {
public void testInvitationWorksAfterReEnablingOrganization() {
Runnable restore = setOrganizationEnabled(organization, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use managedRealm and updateWithCleanup instead

6870
sendInvitation("user@test-org.com", "John", "Doe");

List<OrganizationInvitationRepresentation> invitations = organization.invitations().list();
assertThat(invitations, hasSize(1));
String invitationId = invitations.get(0).getId();

try (OrganizationAttributeUpdater oau = new OrganizationAttributeUpdater(organization).setEnabled(false).update()) {
Runnable restore = setOrganizationEnabled(organization, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use managedRealm and updateWithCleanup instead

private void sendInvitationToOrganization(OrganizationResource org, String email, String firstName, String lastName) {
try (Response response = org.members().inviteUser(email, firstName, lastName)) {
assertThat(response.getStatus(), equalTo(204));
}
}

private static Runnable setOrganizationEnabled(OrganizationResource org, boolean enabled) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this runnable task doesn't add any value, please use: managedRealm and updateWithCleanup instead,
or call managedRealm directly

@lhanusov
Copy link
Copy Markdown
Contributor

@vramik adding auto-expire

@lhanusov
Copy link
Copy Markdown
Contributor

@hammadxcm there is also missing sign-off by you as a contributor, please add it as well

@hammadxcm
hammadxcm force-pushed the migrate-organization-invitation-management-tests branch from 7c91b33 to e928105 Compare April 21, 2026 12:11
@hammadxcm
Copy link
Copy Markdown
Contributor Author

@lhanusov added the sign-off — amended the restore-comments commit and force-pushed. Thanks!

@hammadxcm
hammadxcm commented Apr 21, 2026 E870
Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @lhanusov — point taken on context, I'll pick from help-wanted/good-first-issue next time.

I've addressed the inline comments in 378abf5:

  • Javadoc and chained-call indentation (line 52, 89, 91): reverted back to the original arquillian formatting — blank comment line restored, .filter/.findFirst/.orElse re-indented to the original 12 spaces, and the wrapped List<...> firstPage = \n organization... lines restored. The migration diff is now limited to framework-only changes.
  • @BeforeEach (line 66): removed. Each test now creates its own OrganizationResource inline, matching the idiom in OrganizationGroupsTest in the same package. No RealmConfig was added because none of these 15 tests actually exercises the registration flow — the original arquillian's setRegistrationAllowed(true) wasn't load-bearing for this class. Happy to add one if I've missed a case.
  • setOrganizationEnabled helper (line 374/393/406/432): dropped entirely. The three disabled-org tests now inline toRepresentation() → setEnabled(...) → update(...). Since AbstractOrganizationTest.createOrganization already registers a cleanup that deletes the per-test organization, there's no need for an explicit restore Runnable. testInvitationWorksAfterReEnablingOrganization handles the re-enable step inline.

Let me know if the managedRealm-based approach you had in mind was different — ManagedRealm.updateWithCleanup is realm-scoped (takes RealmConfigBuilder), so it didn't seem to fit the per-organization setEnabled case, but I'm happy to adjust.

Signed-off-by: hammadxcm <hammadkhanxcm@gmail.com>
Closes keycloak#48279

Signed-off-by: hammadxcm <hammadkhanxcm@gmail.com>
- Remove @BeforeEach/setUp and per-class fields; each test now creates
  its own OrganizationResource inline, matching the idiom in
  OrganizationGroupsTest and other new-framework organization tests.
- Drop the setOrganizationEnabled helper; inline the enable/disable
  calls directly in the three disabled-organization tests. The
  per-test organization is auto-cleaned by AbstractOrganizationTest,
  so an explicit restore Runnable is no longer needed.
- Revert the cosmetic Javadoc and chained-method indentation changes
  from the original arquillian file so the migration diff is limited
  to framework-only changes.

Closes keycloak#48279

Signed-off-by: hammadxcm <hammadkhanxcm@gmail.com>
@hammadxcm
hammadxcm force-pushed the migrate-organization-invitation-management-tests branch from 378abf5 to ccc2cc0 Compare April 21, 2026 13:09
Preserves the blank-line whitespace from the original arquillian file
per reviewer feedback, keeping the migration diff limited to framework
changes.

Closes keycloak#48279

Signed-off-by: hammadxcm <hammadkhanxcm@gmail.com>
@hammadxcm
Copy link
Copy Markdown
Contributor Author

@lhanusov final pass in 743f658 — restored trailing whitespace on blank lines inside method bodies and the javadoc * continuation, matching the arquillian original byte-for-byte outside the framework-specific edits. All three remaining threads (javadoc line 52, blank lines 89/91) should now be addressed.

@hammadxcm
hammadxcm requested review from lhanusov and vramik April 21, 2026 14:24
@lhanusov
Copy link
Copy Markdown
Contributor

@hammadxcm thank you for your updates and effort, but still there are lot of places which are not correct, besides emails are sent to non-existent users. I suggest to close this PR and let @vramik to do it, since he is the author of the issue and he plans to work on it in a near future. JFYI reviewing and commenting this simple PR already took me more then 30 minutes, which doesn't make sense. If you want to try LLM and contribute to Keycloak, please, focus on issues with label help-wanted or good-first-issue. Thank you for understanding.

@lhanusov
lhanusov removed their request for review April 21, 2026 15:06
@hammadxcm
Copy link
Copy Markdown
Contributor Author

Thanks @lhanusov, @vramik — closing. Sorry for the reviewer load. I'll stick to help-wanted / good-first-issue labels from here on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Organization Invitation Management tests into new testsuite

3 participants

0