Skip to content

Commit 3e41d16

Browse files
committed
fixup! Introduce Kotlin integration tests
1 parent 3349197 commit 3e41d16

17 files changed

+81
-126
lines changed

kotlin-sdk-test/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ plugins {
33
}
44

55
kotlin {
6+
jvm {
7+
testRuns["test"].executionTask.configure {
8+
useJUnitPlatform()
9+
}
10+
}
611
sourceSets {
712
commonTest {
813
dependencies {
@@ -12,5 +17,13 @@ kotlin {
1217
implementation(libs.kotlinx.coroutines.test)
1318
}
1419
}
20+
jvmTest {
21+
dependencies {
22+
implementation(kotlin("test-junit5"))
23+
implementation(libs.kotlin.logging)
24+
implementation(libs.ktor.server.cio)
25+
implementation(libs.ktor.client.cio)
26+
}
27+
}
1528
}
1629
}

kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientIntegrationTest.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/jvmTest/kotlin/integration/kotlin/KotlinTestBase.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/KotlinTestBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

33
import io.ktor.client.*
44
import io.ktor.client.engine.cio.*

src/jvmTest/kotlin/integration/kotlin/PromptEdgeCasesTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/PromptEdgeCasesTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
44
import io.modelcontextprotocol.kotlin.sdk.*
55
import kotlinx.coroutines.launch
66
import kotlinx.coroutines.runBlocking

src/jvmTest/kotlin/integration/kotlin/PromptIntegrationTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/PromptIntegrationTest.kt

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
44
import io.modelcontextprotocol.kotlin.sdk.*
55
import kotlinx.coroutines.runBlocking
66
import org.junit.jupiter.api.Test
@@ -77,7 +77,7 @@ class PromptIntegrationTest : KotlinTestBase() {
7777
)
7878
) { request ->
7979
val topic = request.arguments?.get("topic") ?: "general knowledge"
80-
val includeImage = request.arguments?.get("includeImage")?.toString()?.toBoolean() ?: true
80+
val includeImage = request.arguments?.get("includeImage")?.toBoolean() ?: true
8181

8282
val messages = mutableListOf<PromptMessage>()
8383

@@ -153,7 +153,7 @@ class PromptIntegrationTest : KotlinTestBase() {
153153
PromptMessage(
154154
role = Role.assistant,
155155
content = TextContent(text = "You're welcome! Let me know if you have more questions about $topic."),
156-
)
156+
),
157157
)
158158
)
159159
}
@@ -177,14 +177,13 @@ class PromptIntegrationTest : KotlinTestBase() {
177177
name = "optionalArg",
178178
description = "Optional argument",
179179
required = false,
180-
)
180+
),
181181
)
182182
) { request ->
183-
val arg1 = request.arguments?.get("requiredArg1")
184-
?: throw IllegalArgumentException("Missing required argument: requiredArg1")
185-
val arg2 = request.arguments["requiredArg2"]
186-
?: throw IllegalArgumentException("Missing required argument: requiredArg2")
187-
val optArg = request.arguments["optionalArg"] ?: "default"
183+
val args = request.arguments ?: emptyMap()
184+
val arg1 = args["requiredArg1"] ?: throw IllegalArgumentException("Missing required argument: requiredArg1")
185+
val arg2 = args["requiredArg2"] ?: throw IllegalArgumentException("Missing required argument: requiredArg2")
186+
val optArg = args["optionalArg"] ?: "default"
188187

189188
GetPromptResult(
190189
description = strictPromptDescription,
@@ -196,7 +195,7 @@ class PromptIntegrationTest : KotlinTestBase() {
196195
PromptMessage(
197196
role = Role.assistant,
198197
content = TextContent(text = "I received your arguments: $arg1, $arg2, and $optArg"),
199-
)
198+
),
200199
)
201200
)
202201
}
@@ -213,10 +212,10 @@ class PromptIntegrationTest : KotlinTestBase() {
213212
assertNotNull(testPrompt, "Test prompt should be in the list")
214213
assertEquals(testPromptDescription, testPrompt.description, "Prompt description should match")
215214

216-
assertNotNull(testPrompt.arguments, "Prompt arguments should not be null")
217-
assertTrue(testPrompt.arguments.isNotEmpty(), "Prompt arguments should not be empty")
215+
val arguments = testPrompt.arguments ?: error("Prompt arguments should not be null")
216+
assertTrue(arguments.isNotEmpty(), "Prompt arguments should not be empty")
218217

219-
val nameArg = testPrompt.arguments.find { it.name == "name" }
218+
val nameArg = arguments.find { it.name == "name" }
220219
assertNotNull(nameArg, "Name argument should be in the list")
221220
assertEquals("The name to greet", nameArg.description, "Argument description should match")
222221
assertEquals(true, nameArg.required, "Argument required flag should match")
@@ -264,8 +263,8 @@ class PromptIntegrationTest : KotlinTestBase() {
264263
val strictPrompt = promptsList.prompts.find { it.name == strictPromptName }
265264
assertNotNull(strictPrompt, "Strict prompt should be in the list")
266265

267-
assertNotNull(strictPrompt.arguments, "Prompt arguments should not be null")
268-
val requiredArgs = strictPrompt.arguments.filter { it.required == true }
266+
val argsDef = strictPrompt.arguments ?: error("Prompt arguments should not be null")
267+
val requiredArgs = argsDef.filter { it.required == true }
269268
assertEquals(2, requiredArgs.size, "Strict prompt should have 2 required arguments")
270269

271270
// test missing required arg
@@ -320,9 +319,9 @@ class PromptIntegrationTest : KotlinTestBase() {
320319
assertNotNull(userMessage, "User message should be in the list")
321320
val userContent = userMessage.content as? TextContent
322321
assertNotNull(userContent, "User message content should be TextContent")
323-
assertNotNull(userContent.text, "User message text should not be null")
324-
assertTrue(userContent.text.contains("value1"), "Message should contain first argument")
325-
assertTrue(userContent.text.contains("value2"), "Message should contain second argument")
322+
val userText = requireNotNull(userContent.text)
323+
assertTrue(userText.contains("value1"), "Message should contain first argument")
324+
assertTrue(userText.contains("value2"), "Message should contain second argument")
326325
}
327326

328327
@Test
@@ -348,15 +347,15 @@ class PromptIntegrationTest : KotlinTestBase() {
348347
assertNotNull(userMessage, "User message should be in the list")
349348
val userContent = userMessage.content as? TextContent
350349
assertNotNull(userContent, "User message content should be TextContent")
351-
assertNotNull(userContent.text, "User message text should not be null")
352-
assertTrue(userContent.text.contains(topic), "User message should contain the topic")
350+
val userText2 = requireNotNull(userContent.text)
351+
assertTrue(userText2.contains(topic), "User message should contain the topic")
353352

354353
val assistantMessage = result.messages.find { it.role == Role.assistant }
355354
assertNotNull(assistantMessage, "Assistant message should be in the list")
356355
val assistantContent = assistantMessage.content as? TextContent
357356
assertNotNull(assistantContent, "Assistant message content should be TextContent")
358-
assertNotNull(assistantContent.text, "Assistant message text should not be null")
359-
assertTrue(assistantContent.text.contains(topic), "Assistant message should contain the topic")
357+
val assistantText = requireNotNull(assistantContent.text)
358+
assertTrue(assistantText.contains(topic), "Assistant message should contain the topic")
360359

361360
val resultNoImage = client.getPrompt(
362361
GetPromptRequest(
@@ -402,11 +401,11 @@ class PromptIntegrationTest : KotlinTestBase() {
402401
for (message in result.messages) {
403402
val content = message.content as? TextContent
404403
assertNotNull(content, "Message content should be TextContent")
405-
assertNotNull(content.text, "Message text should not be null")
404+
val text = requireNotNull(content.text)
406405

407406
// Either the message contains the topic or it's a generic conversation message
408-
val containsTopic = content.text.contains(topic)
409-
val isGenericMessage = content.text.contains("thank you") || content.text.contains("welcome")
407+
val containsTopic = text.contains(topic)
408+
val isGenericMessage = text.contains("thank you") || text.contains("welcome")
410409

411410
assertTrue(
412411
containsTopic || isGenericMessage,

src/jvmTest/kotlin/integration/kotlin/ResourceEdgeCasesTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/ResourceEdgeCasesTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
44
import io.modelcontextprotocol.kotlin.sdk.*
55
import kotlinx.coroutines.launch
66
import kotlinx.coroutines.runBlocking

src/jvmTest/kotlin/integration/kotlin/ResourceIntegrationTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/ResourceIntegrationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
44
import io.modelcontextprotocol.kotlin.sdk.*
55
import org.junit.jupiter.api.Test
66
import kotlin.test.assertEquals

src/jvmTest/kotlin/integration/kotlin/ToolEdgeCasesTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/ToolEdgeCasesTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.assertCallToolResult
4-
import integration.utils.TestUtils.assertJsonProperty
5-
import integration.utils.TestUtils.assertTextContent
6-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertCallToolResult
4+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertJsonProperty
5+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertTextContent
6+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
77
import io.modelcontextprotocol.kotlin.sdk.*
88
import kotlinx.coroutines.delay
99
import kotlinx.coroutines.launch

src/jvmTest/kotlin/integration/kotlin/ToolIntegrationTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/ToolIntegrationTest.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package integration.kotlin
1+
package io.modelcontextprotocol.kotlin.sdk.integration.kotlin
22

3-
import integration.utils.TestUtils.assertCallToolResult
4-
import integration.utils.TestUtils.assertJsonProperty
5-
import integration.utils.TestUtils.assertTextContent
6-
import integration.utils.TestUtils.runTest
3+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertCallToolResult
4+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertJsonProperty
5+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.assertTextContent
6+
import io.modelcontextprotocol.kotlin.sdk.integration.utils.TestUtils.runTest
77
import io.modelcontextprotocol.kotlin.sdk.*
88
import kotlinx.coroutines.runBlocking
99
import kotlinx.serialization.json.*
@@ -293,9 +293,7 @@ class ToolIntegrationTest : KotlinTestBase() {
293293

294294
val content = toolResult.content.firstOrNull() as? TextContent
295295
assertNotNull(content, "Tool result content should be TextContent")
296-
assertNotNull(content.text, "Text content should not be null")
297-
val contentText = content.text
298-
296+
val contentText = requireNotNull(content.text)
299297

300298
assertTrue(contentText.contains("Operation"), "Result should contain operation")
301299
assertTrue(contentText.contains("multiply"), "Result should contain multiply operation")

src/jvmTest/kotlin/integration/typescript/KotlinClientTypeScriptServerEdgeCasesTest.kt renamed to kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/KotlinClientTypeScriptServerEdgeCasesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package integration.typescript
1+
package io.modelcontextprotocol.kotlin.sdk.integration.typescript
22

33
import io.ktor.client.*
44
import io.ktor.client.engine.cio.*

0 commit comments

Comments
 (0)