Skip to content

Commit d8893a0

Browse files
author
Robert Winkler
committed
Refactored Integration Tests
1 parent 487a6f6 commit d8893a0

File tree

13 files changed

+113
-157
lines changed

13 files changed

+113
-157
lines changed

kotlin-wot-integration-tests/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ plugins {
55
}
66

77
dependencies {
8-
api(project(":kotlin-wot"))
98
api(project(":kotlin-wot-binding-http"))
9+
//api(project(":kotlin-wot-binding-websocket"))
1010
api(project(":kotlin-wot-binding-mqtt"))
11-
api(project(":kotlin-wot-reflection"))
1211
api(project(":kotlin-wot-spring-boot-starter"))
1312
implementation("ai.ancf.lmos:arc-azure-client:0.111.0")
1413
api("ai.ancf.lmos:arc-spring-boot-starter:0.111.0")
1514

1615
//implementation("dev.langchain4j:langchain4j-azure-open-ai:0.35.0")
1716
//implementation("dev.langchain4j:langchain4j:0.35.0")
17+
testImplementation("org.springframework.boot:spring-boot-starter-test")
1818
testImplementation("com.hivemq:hivemq-mqtt-client:1.3.3")
1919
implementation("org.testcontainers:testcontainers:1.20.3")
2020
}

kotlin-wot-integration-tests/src/main/kotlin/integration/AgentConfiguration.kt

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.arc.spring.Agents
44
import ai.ancf.lmos.arc.spring.Functions
5+
import ai.ancf.lmos.wot.Wot
6+
import ai.ancf.lmos.wot.thing.schema.genericReadProperty
57
import org.springframework.context.annotation.Bean
68
import org.springframework.context.annotation.Configuration
79

@@ -12,18 +14,40 @@ class AgentConfiguration {
1214
@Bean
1315
fun myAgent(agent: Agents) = agent {
1416
name = "My Agent"
15-
prompt { "you are a helpful weather agent." }
17+
prompt { "You are a helpful agent which can control devices." }
1618
model = { "GPT-4o" }
19+
tools {
20+
+"getResources"
21+
}
1722
}
1823

1924

2025
@Bean
21-
fun myFunction(function: Functions) = function(
22-
name = "g",
23-
description = "Returns real-time weather information for any location",
26+
fun getResources(function: Functions, wot: Wot) = function(
27+
name = "getResources",
28+
description = "Returns the resources available in the coffee machine.",
2429
) {
30+
31+
val thingDescription =
32+
wot.requestThingDescription("http://remotelab.esi.cit.tum.de:8080/virtual-coffee-machine-1_1")
33+
34+
val testThing = wot.consume(thingDescription)
35+
36+
val availableResources = testThing.genericReadProperty<Resources>("allAvailableResources")
37+
38+
"""
39+
The coffee machine has the following resources available:
40+
- Milk: ${availableResources.milk} ml
41+
- Water: ${availableResources.water} ml
42+
- Chocolate: ${availableResources.chocolate} grams
43+
- Coffee Beans: ${availableResources.coffeeBeans} grams
2544
"""
26-
The weather is good in Berlin. It is 20 degrees celsius.
27-
"""
2845
}
29-
}
46+
}
47+
48+
data class Resources(
49+
val milk: Int,
50+
val water: Int ,
51+
val chocolate : Int,
52+
val coffeeBeans: Int
53+
)

kotlin-wot-integration-tests/src/main/kotlin/integration/HttpAgent.kt

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

kotlin-wot-integration-tests/src/main/kotlin/integration/MqttAgent.kt

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

kotlin-wot-integration-tests/src/main/kotlin/integration/Util.kt

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

kotlin-wot-integration-tests/src/main/resources/application.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ arc:
99

1010
wot:
1111
servient:
12+
http:
13+
server:
14+
host: localhost
15+
port: 8080
1216
mqtt:
1317
server:
1418
enabled: false

kotlin-wot-integration-tests/src/test/kotlin/integration/AgentBuilderTest.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ai.ancf.lmos.wot.integration
2+
3+
import ai.ancf.lmos.wot.Wot
4+
import ai.ancf.lmos.wot.thing.schema.genericReadProperty
5+
import kotlinx.coroutines.test.runTest
6+
import org.springframework.beans.factory.annotation.Autowired
7+
import org.springframework.boot.test.context.SpringBootTest
8+
import kotlin.test.Test
9+
import kotlin.test.assertNotNull
10+
11+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
12+
class ThingAgentApplicationTest {
13+
14+
private var port: Int = 8080
15+
16+
@Autowired
17+
private lateinit var wot: Wot
18+
19+
@Test
20+
fun testGenericReadProperty() = runTest {
21+
// Construct the dynamic server URL
22+
val serverUrl = "http://localhost:$port/agent"
23+
24+
// Request the Thing Description
25+
val thingDescription = wot.requestThingDescription(serverUrl)
26+
// Consume the Thing
27+
val testThing = wot.consume(thingDescription)
28+
29+
// Read the Model Configuration property
30+
val modelConfiguration = testThing.genericReadProperty<ModelConfiguration>("modelConfiguration")
31+
assertNotNull(modelConfiguration, "Model Configuration should not be null")
32+
33+
println("Model Configuration: $modelConfiguration")
34+
35+
36+
}
37+
}
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package integration
1+
package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.wot.Servient
44
import ai.ancf.lmos.wot.Wot
55
import ai.ancf.lmos.wot.binding.http.HttpProtocolClientFactory
66
import ai.ancf.lmos.wot.binding.http.HttpsProtocolClientFactory
7-
import ai.ancf.lmos.wot.thing.schema.DataSchemaValue
7+
import ai.ancf.lmos.wot.thing.schema.genericReadProperty
88
import kotlinx.coroutines.test.runTest
99
import kotlin.test.Test
1010

@@ -19,11 +19,21 @@ class TestSimpleCoffeeMachine {
1919
val wot = Wot.create(servient)
2020

2121
val thingDescription =
22-
wot.requestThingDescription("https://zion.vaimee.com/things/urn:uuid:7ba2bca0-a7f6-47b3-bdce-498caa33bbaf")
22+
wot.requestThingDescription("http://remotelab.esi.cit.tum.de:8080/virtual-coffee-machine-1_1")
2323

24-
val coffeeMachine = wot.consume(thingDescription)
25-
val resources = coffeeMachine.readProperty("resources").value() as DataSchemaValue.ObjectValue
24+
val testThing = wot.consume(thingDescription)
25+
val status = testThing.genericReadProperty<String>("status")
2626

27-
println(resources)
27+
val availableResources = testThing.genericReadProperty<Resources>("allAvailableResources")
28+
29+
println(status)
30+
println(availableResources)
2831
}
29-
}
32+
}
33+
34+
data class Resources(
35+
val milk: Int,
36+
val water: Int ,
37+
val chocolate : Int,
38+
val coffeeBeans: Int
39+
)

kotlin-wot-reflection/src/main/kotlin/reflection/ExposedThingBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ object ExposedThingBuilder {
471471
} else{
472472
exposedThing.setPropertyReadHandler(name) { _ ->
473473
val value = property.getter.call(instance)
474+
474475
InteractionInput.Value(DataSchemaValue.toDataSchemaValue(value))
475476
}
476477
}

0 commit comments

Comments
 (0)