diff --git a/spring-ai-spring-cloud-bindings/src/test/java/org/springframework/ai/bindings/MistralAiBindingsPropertiesProcessorTests.java b/spring-ai-spring-cloud-bindings/src/test/java/org/springframework/ai/bindings/MistralAiBindingsPropertiesProcessorTests.java index d99e991bf3e..32813bf30c2 100644 --- a/spring-ai-spring-cloud-bindings/src/test/java/org/springframework/ai/bindings/MistralAiBindingsPropertiesProcessorTests.java +++ b/spring-ai-spring-cloud-bindings/src/test/java/org/springframework/ai/bindings/MistralAiBindingsPropertiesProcessorTests.java @@ -27,6 +27,7 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Unit tests for {@link MistralAiBindingsPropertiesProcessor}. @@ -65,4 +66,58 @@ void whenDisabledThenPropertiesAreNotContributed() { assertThat(this.properties).isEmpty(); } + @Test + void nullBindingsShouldThrowException() { + assertThatThrownBy( + () -> new MistralAiBindingsPropertiesProcessor().process(this.environment, null, this.properties)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void nullEnvironmentShouldThrowException() { + assertThatThrownBy( + () -> new MistralAiBindingsPropertiesProcessor().process(null, this.bindings, this.properties)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void nullPropertiesShouldThrowException() { + assertThatThrownBy( + () -> new MistralAiBindingsPropertiesProcessor().process(this.environment, this.bindings, null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void missingApiKeyShouldStillSetNullValue() { + Bindings bindingsWithoutApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"), Map + .of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "uri", "https://my.mistralai.example.net"))); + + new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithoutApiKey, this.properties); + + assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net"); + assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", null); + } + + @Test + void emptyApiKeyIsStillSet() { + Bindings bindingsWithEmptyApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"), + Map.of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "api-key", "", "uri", + "https://my.mistralai.example.net"))); + + new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithEmptyApiKey, this.properties); + + assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", ""); + assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net"); + } + + @Test + void wrongBindingTypeShouldBeIgnored() { + Bindings wrongTypeBindings = new Bindings(new Binding("test-name", Paths.get("test-path"), + Map.of(Binding.TYPE, "different-type", "api-key", "demo", "uri", "https://my.mistralai.example.net"))); + + new MistralAiBindingsPropertiesProcessor().process(this.environment, wrongTypeBindings, this.properties); + + assertThat(this.properties).isEmpty(); + } + }