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 @@ -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}.
Expand Down Expand Up @@ -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();
}

}