gnodet-bot commented on code in PR #31135: URL: https://github.com/apache/camel/pull/31135#discussion_r4744288255
########## components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuthProfileProducerTest.java: ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.http; + +import java.net.URI; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.core5.http.impl.bootstrap.HttpServer; +import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the {@code oauthProfile} producer option. + * <p> + * The option resolves a bearer token per exchange via a named camel-oauth profile and injects it as an + * {@code Authorization: Bearer} header. A {@link StubOAuthClientAuthenticationFactory} registered via the service + * loader stands in for camel-oauth so the test does not need a real IdP. + */ +class HttpOAuthProfileProducerTest extends BaseHttpTest { + + private static final String PROFILE = "myprofile"; + private static final String EXPECTED_TOKEN = StubOAuthClientAuthenticationFactory.tokenFor(PROFILE); + private static final String EXPECTED_HEADER_VALUE = "Bearer " + EXPECTED_TOKEN; Review Comment: ⚠️ **Nit — static `EXPECTED_TOKEN` captures the stub at class-load time.** ```java private static final String EXPECTED_TOKEN = StubOAuthClientAuthenticationFactory.tokenFor(PROFILE); ``` `tokenFor()` is called once when the class loads, before `@AfterEach resetStubTokens()` can clear it. This works correctly today because `theBearerTokenIsInjectedForTheNamedProfile()` never rotates the token — but a future test that calls `setToken(PROFILE, ...)` before class initialisation completes, or one that relies on `EXPECTED_HEADER_VALUE` after a rotation, would silently assert the stale initial value. Prefer capturing inline inside each test method (or as a local variable) to make the lifecycle unambiguous: ```suggestion private static final String EXPECTED_HEADER_VALUE = "Bearer " + StubOAuthClientAuthenticationFactory.tokenFor(PROFILE); ``` (Drop the `EXPECTED_TOKEN` field and inline `tokenFor(PROFILE)` directly into `EXPECTED_HEADER_VALUE`, or move both captures into the test method body.) -- 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]
