From e62c08b80ff78aa63b24891170dd091dcb211bab Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Thu, 6 Aug 2026 17:30:03 +0200 Subject: [PATCH] CAMEL-24345: Fix GoogleVertexAIProducerOptionsTest to not require Google credentials Construct the configuration and endpoint directly instead of resolving through CamelContext, which triggers doStart() and credential lookup. The test only verifies buildConfig() and determineStreamOutputMode() behavior, not actual Google Cloud connectivity. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Claus Ibsen --- .../GoogleVertexAIProducerOptionsTest.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/components/camel-google/camel-google-vertexai/src/test/java/org/apache/camel/component/google/vertexai/GoogleVertexAIProducerOptionsTest.java b/components/camel-google/camel-google-vertexai/src/test/java/org/apache/camel/component/google/vertexai/GoogleVertexAIProducerOptionsTest.java index e3e7c74de94f1..82b2ed1ec37d7 100644 --- a/components/camel-google/camel-google-vertexai/src/test/java/org/apache/camel/component/google/vertexai/GoogleVertexAIProducerOptionsTest.java +++ b/components/camel-google/camel-google-vertexai/src/test/java/org/apache/camel/component/google/vertexai/GoogleVertexAIProducerOptionsTest.java @@ -26,12 +26,11 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Verifies that the producer applies the options that describe the shape of the request and of the response. + * Verifies that the producer applies the options that describe the shape of the request and of the response. Uses + * direct object construction to avoid starting the endpoint (which requires Google Cloud credentials). */ class GoogleVertexAIProducerOptionsTest { - private static final String BASE = "google-vertexai:my-project:us-central1:gemini-2.0-flash"; - private DefaultCamelContext context; @AfterEach @@ -41,30 +40,36 @@ void tearDown() { } } - private GoogleVertexAIProducer producer(String query) throws Exception { + private GoogleVertexAIProducer producer(GoogleVertexAIConfiguration config) { context = new DefaultCamelContext(); - context.start(); - GoogleVertexAIEndpoint endpoint = context.getEndpoint(BASE + query, GoogleVertexAIEndpoint.class); + GoogleVertexAIComponent component = new GoogleVertexAIComponent(context); + GoogleVertexAIEndpoint endpoint + = new GoogleVertexAIEndpoint("google-vertexai:my-project:us-central1:gemini-2.0-flash", component, config); return new GoogleVertexAIProducer(endpoint); } @Test - void jsonModeAsksTheModelForJson() throws Exception { - GenerateContentConfig config = producer("?jsonMode=true").buildConfig(new DefaultExchange(context)); + void jsonModeAsksTheModelForJson() { + GoogleVertexAIConfiguration config = new GoogleVertexAIConfiguration(); + config.setJsonMode(true); + GenerateContentConfig result = producer(config).buildConfig(new DefaultExchange(context)); - assertThat(config.responseMimeType()).contains("application/json"); + assertThat(result.responseMimeType()).contains("application/json"); } @Test - void jsonModeIsOffByDefault() throws Exception { - GenerateContentConfig config = producer("").buildConfig(new DefaultExchange(context)); + void jsonModeIsOffByDefault() { + GoogleVertexAIConfiguration config = new GoogleVertexAIConfiguration(); + GenerateContentConfig result = producer(config).buildConfig(new DefaultExchange(context)); - assertThat(config.responseMimeType()).isEmpty(); + assertThat(result.responseMimeType()).isEmpty(); } @Test - void theStreamOutputModeComesFromTheConfigurationOrTheHeader() throws Exception { - GoogleVertexAIProducer producer = producer("?streamOutputMode=chunks"); + void theStreamOutputModeComesFromTheConfigurationOrTheHeader() { + GoogleVertexAIConfiguration config = new GoogleVertexAIConfiguration(); + config.setStreamOutputMode("chunks"); + GoogleVertexAIProducer producer = producer(config); Exchange exchange = new DefaultExchange(context); assertThat(producer.determineStreamOutputMode(exchange)).isEqualTo("chunks"); @@ -75,7 +80,8 @@ void theStreamOutputModeComesFromTheConfigurationOrTheHeader() throws Exception } @Test - void theStreamOutputModeDefaultsToComplete() throws Exception { - assertThat(producer("").determineStreamOutputMode(new DefaultExchange(context))).isEqualTo("complete"); + void theStreamOutputModeDefaultsToComplete() { + GoogleVertexAIConfiguration config = new GoogleVertexAIConfiguration(); + assertThat(producer(config).determineStreamOutputMode(new DefaultExchange(context))).isEqualTo("complete"); } }