gnodet opened a new pull request, #30148:
URL: https://github.com/apache/camel/pull/30148

   ## Summary
   
   Fix `OAuthCodeFlowServletTest` and `OAuthClientCredentialsServletTest` 
failing with
   `BindException` and `TestAbortedException` (skip instead of proper failure) 
when both
   tests run in the same JVM fork.
   
   ## Root Cause
   
   Two bugs in `AbstractKeycloakTest`:
   
   1. **Shared static port**: `AvailablePortFinder.find()` was called once as a 
static
      field initializer in the _base class_ (`AbstractKeycloakTest`). Static 
initializers
      execute once per class-load in the JVM — so all subclasses shared the 
same `port`
      value. When `OAuthClientCredentialsServletTest` and 
`OAuthCodeFlowServletTest` ran
      in the same Surefire fork, the first class to call `@BeforeAll` 
successfully bound
      Undertow to that port; the second class then failed with `BindException` 
because the
      same port was still occupied.
   
   2. **Undertow started before Keycloak assumption**: Both servlet test 
classes started
      the Undertow server unconditionally in `@BeforeAll`, then checked
      `Assumptions.assumeTrue(admin.isKeycloakRunning())` only inside 
individual test
      methods. When Keycloak was absent this caused a hard `RuntimeException`
      (`BindException`) instead of a clean `TestAbortedException` skip.
   
   ## Fix
   
   - Remove the shared `SERVER_PORT` / `port` / `APP_BASE_URL` static fields 
from
     `AbstractKeycloakTest`.
   - Add `protected abstract int getPort()` to the base class, with 
`getAppBaseUrl()`
     computed from it.
   - Each concrete test class (`OAuthCodeFlowServletTest`,
     `OAuthClientCredentialsServletTest`, `OAuthCodeFlowVertxTest`,
     `OAuthClientCredentialsVertxTest`, `SSLCertTrustTest`) now declares its own
     `static final AvailablePortFinder.Port SERVER_PORT = 
AvailablePortFinder.find()`
     and implements `getPort()`. Each class gets a distinct port even when 
running in
     the same JVM fork.
   - Change `createUndertowServer()` to accept an explicit port parameter.
   - For servlet tests: check 
`Assumptions.assumeTrue(admin.isKeycloakRunning())` in
     `@BeforeAll` _before_ calling `createUndertowServer()`, so Undertow is 
never started
     when Keycloak is absent and skips are clean.
   
   ## Tests
   
   No new tests added — the fix is in the test infrastructure itself. The issue 
was that
   the existing tests failed with `BindException`; after this fix each class 
binds to its
   own distinct port and the Keycloak skip propagates cleanly via JUnit's 
`@BeforeAll`
   assumption mechanism.
   
   Fixes CAMEL-23480
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
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]

Reply via email to