Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
Expand All @@ -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");
}
}
Loading