Skip to content

Commit 1ad5c0f

Browse files
committed
Update Kotlin integration tests
This commit updates the Kotlin integration tests to leverage the new Kotlin reflection capabilities allowing to identify required properties. It also adds a missing jackson-module-kotlin dependency and refine test implementation to be closer to the Java ones and use more idiomatic Kotlin code.
1 parent 2cb608b commit 1ad5c0f

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

spring-ai-spring-boot-autoconfigure/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@
578578
<scope>test</scope>
579579
</dependency>
580580

581+
<dependency>
582+
<groupId>com.fasterxml.jackson.module</groupId>
583+
<artifactId>jackson-module-kotlin</artifactId>
584+
<scope>test</scope>
585+
</dependency>
586+
581587
</dependencies>
582588

583589
</project>

spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackContextKotlinIT.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FunctionCallbackResolverKotlinIT : BaseOllamaIT() {
3939

4040
companion object {
4141

42-
private val MODEL_NAME = OllamaModel.LLAMA3_2.getName();
42+
private val MODEL_NAME = "qwen2.5:3b";
4343

4444
@JvmStatic
4545
@BeforeAll
@@ -72,7 +72,7 @@ class FunctionCallbackResolverKotlinIT : BaseOllamaIT() {
7272
val response = chatModel
7373
.call(Prompt(listOf(userMessage), OllamaOptions.builder().function("weatherInfo").build()))
7474

75-
logger.info("Response: " + response)
75+
logger.info("Response: $response")
7676

7777
assertThat(response.getResult().output.text).contains("30", "10", "15")
7878
}
@@ -93,10 +93,11 @@ class FunctionCallbackResolverKotlinIT : BaseOllamaIT() {
9393
.build()
9494

9595
val response = chatModel.call(Prompt(listOf(userMessage), functionOptions));
96+
val output = response.getResult().output.text
9697

97-
logger.info("Response: " + response.getResult().getOutput().getText());
98+
logger.info("Response: $output");
9899

99-
assertThat(response.getResult().output.text).contains("30", "10", "15");
100+
assertThat(output).contains("30", "10", "15");
100101
}
101102
}
102103

spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.springframework.ai.chat.prompt.Prompt
2828
import org.springframework.ai.model.function.FunctionCallback
2929
import org.springframework.ai.model.function.FunctionCallingOptions
3030
import org.springframework.ai.ollama.OllamaChatModel
31-
import org.springframework.ai.ollama.api.OllamaModel
3231
import org.springframework.ai.ollama.api.OllamaOptions
3332
import org.springframework.boot.autoconfigure.AutoConfigurations
3433
import org.springframework.boot.test.context.runner.ApplicationContextRunner
@@ -39,7 +38,7 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
3938

4039
companion object {
4140

42-
private val MODEL_NAME = OllamaModel.LLAMA3_2.getName();
41+
private val MODEL_NAME = "qwen2.5:3b";
4342

4443
@JvmStatic
4544
@BeforeAll
@@ -72,7 +71,7 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
7271
val response = chatModel
7372
.call(Prompt(listOf(userMessage), OllamaOptions.builder().function("WeatherInfo").build()))
7473

75-
logger.info("Response: " + response)
74+
logger.info("Response: $response")
7675

7776
assertThat(response.getResult().output.text).contains("30", "10", "15")
7877
}
@@ -93,10 +92,10 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
9392
.build()
9493

9594
val response = chatModel.call(Prompt(listOf(userMessage), functionOptions));
95+
val output = response.getResult().output.text
96+
logger.info("Response: $output");
9697

97-
logger.info("Response: " + response.getResult().getOutput().getText());
98-
99-
assertThat(response.getResult().output.text).contains("30", "10", "15");
98+
assertThat(output).contains("30", "10", "15");
10099
}
101100
}
102101

spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/MockKotlinWeatherService.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,16 @@ enum class Unit(val unitName: String) {
6161
@JsonInclude(Include.NON_NULL)
6262
@JsonClassDescription("Weather API request")
6363
data class KotlinRequest(
64-
@get:JsonProperty(required = true, value = "location")
64+
6565
@get:JsonPropertyDescription("The city and state e.g. San Francisco, CA")
66-
val location: String = "",
66+
val location: String,
6767

68-
@get:JsonProperty(required = true, value = "lat")
6968
@get:JsonPropertyDescription("The city latitude")
70-
val lat: Double = 0.0,
69+
val lat: Double,
7170

72-
@get:JsonProperty(required = true, value = "lon")
7371
@get:JsonPropertyDescription("The city longitude")
74-
val lon: Double = 0.0,
72+
val lon: Double,
7573

76-
@get:JsonProperty(required = true, value = "unit")
7774
@get:JsonPropertyDescription("Temperature unit")
7875
val unit: Unit = Unit.C
7976
)

0 commit comments

Comments
 (0)