|
27 | 27 | import org.springframework.mock.env.MockEnvironment; |
28 | 28 |
|
29 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
30 | 31 |
|
31 | 32 | /** |
32 | 33 | * Unit tests for {@link MistralAiBindingsPropertiesProcessor}. |
@@ -65,4 +66,58 @@ void whenDisabledThenPropertiesAreNotContributed() { |
65 | 66 | assertThat(this.properties).isEmpty(); |
66 | 67 | } |
67 | 68 |
|
| 69 | + @Test |
| 70 | + void nullBindingsShouldThrowException() { |
| 71 | + assertThatThrownBy( |
| 72 | + () -> new MistralAiBindingsPropertiesProcessor().process(this.environment, null, this.properties)) |
| 73 | + .isInstanceOf(NullPointerException.class); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void nullEnvironmentShouldThrowException() { |
| 78 | + assertThatThrownBy( |
| 79 | + () -> new MistralAiBindingsPropertiesProcessor().process(null, this.bindings, this.properties)) |
| 80 | + .isInstanceOf(NullPointerException.class); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + void nullPropertiesShouldThrowException() { |
| 85 | + assertThatThrownBy( |
| 86 | + () -> new MistralAiBindingsPropertiesProcessor().process(this.environment, this.bindings, null)) |
| 87 | + .isInstanceOf(NullPointerException.class); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + void missingApiKeyShouldStillSetNullValue() { |
| 92 | + Bindings bindingsWithoutApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"), Map |
| 93 | + .of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "uri", "https://my.mistralai.example.net"))); |
| 94 | + |
| 95 | + new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithoutApiKey, this.properties); |
| 96 | + |
| 97 | + assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net"); |
| 98 | + assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", null); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void emptyApiKeyIsStillSet() { |
| 103 | + Bindings bindingsWithEmptyApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"), |
| 104 | + Map.of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "api-key", "", "uri", |
| 105 | + "https://my.mistralai.example.net"))); |
| 106 | + |
| 107 | + new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithEmptyApiKey, this.properties); |
| 108 | + |
| 109 | + assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", ""); |
| 110 | + assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net"); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + void wrongBindingTypeShouldBeIgnored() { |
| 115 | + Bindings wrongTypeBindings = new Bindings(new Binding("test-name", Paths.get("test-path"), |
| 116 | + Map.of(Binding.TYPE, "different-type", "api-key", "demo", "uri", "https://my.mistralai.example.net"))); |
| 117 | + |
| 118 | + new MistralAiBindingsPropertiesProcessor().process(this.environment, wrongTypeBindings, this.properties); |
| 119 | + |
| 120 | + assertThat(this.properties).isEmpty(); |
| 121 | + } |
| 122 | + |
68 | 123 | } |
0 commit comments