gnodet-bot commented on code in PR #30148:
URL: https://github.com/apache/camel/pull/30148#discussion_r4597539394
##########
components/camel-oauth/src/test/java/org/apache/camel/test/oauth/AbstractOAuthCodeFlowTest.java:
##########
@@ -35,38 +34,20 @@ void testCodeFlowAuth() throws Exception {
var admin = new KeycloakAdmin(new
KeycloakAdmin.AdminParams(KEYCLOAK_BASE_URL));
Assumptions.assumeTrue(admin.isKeycloakRunning(), "Keycloak is not
running");
+ admin.close();
Review Comment:
⚠️ `admin` leaks when `assumeTrue` aborts the test. `TestAbortedException`
unwinds before `admin.close()` on line 37. Use try-with-resources like the
other sites:
```suggestion
try (var admin = new KeycloakAdmin(new
KeycloakAdmin.AdminParams(KEYCLOAK_BASE_URL))) {
Assumptions.assumeTrue(admin.isKeycloakRunning(), "Keycloak is
not running");
}
```
##########
components/camel-oauth/src/test/java/org/apache/camel/test/oauth/AbstractOAuthCodeFlowTest.java:
##########
@@ -35,38 +34,20 @@ void testCodeFlowAuth() throws Exception {
var admin = new KeycloakAdmin(new
KeycloakAdmin.AdminParams(KEYCLOAK_BASE_URL));
Assumptions.assumeTrue(admin.isKeycloakRunning(), "Keycloak is not
running");
+ admin.close();
try (CamelContext context = createCamelContext()) {
addOAuthCodeFlowRoutes(context);
context.start();
// Verify Realm, Client, and User exist
var keycloak = getKeycloakAdmin().getKeycloak();
-
Assertions.assertNotNull(keycloak.realm(KEYCLOAK_REALM).toRepresentation());
- Assertions.assertEquals(1,
keycloak.realm(KEYCLOAK_REALM).clients().findByClientId(TEST_CLIENT_ID).size());
- Assertions.assertEquals(1,
keycloak.realm(KEYCLOAK_REALM).users().search("alice").size());
+
Assumptions.assumeTrue(keycloak.realm(KEYCLOAK_REALM).toRepresentation() !=
null);
+
Assumptions.assumeTrue(keycloak.realm(KEYCLOAK_REALM).clients().findByClientId(TEST_CLIENT_ID).size()
== 1);
+
Assumptions.assumeTrue(keycloak.realm(KEYCLOAK_REALM).users().search("alice").size()
== 1);
Review Comment:
⚠️ Switching `Assertions.assertNotNull`/`assertEquals` to
`Assumptions.assumeTrue` changes a hard failure into a silent skip. If
`setupKeycloakRealm()` ran but the realm/client/user is missing
(misconfiguration, Keycloak bug), the test now skips silently instead of
failing. The earlier `isKeycloakRunning()` assumption already guards the
no-Keycloak case — these post-setup checks should remain assertions.
```suggestion
org.junit.jupiter.api.Assertions.assertNotNull(keycloak.realm(KEYCLOAK_REALM).toRepresentation());
org.junit.jupiter.api.Assertions.assertEquals(1,
keycloak.realm(KEYCLOAK_REALM).clients().findByClientId(TEST_CLIENT_ID).size());
org.junit.jupiter.api.Assertions.assertEquals(1,
keycloak.realm(KEYCLOAK_REALM).users().search("alice").size());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]