Skip to content

Commit 4d01607

Browse files
authored
test: add noop test (#49)
1 parent f291a37 commit 4d01607

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

src/main/java/at/ac/uibk/dps/cirrina/io/parsing/CsmParser.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ object CsmParser {
6666
return builder.build()
6767
}
6868

69+
fun parseCsml(mainModulePath: URI): Csml = parseCsml(mainModulePath.toString())
70+
6971
/**
7072
* Parse a CSML Pkl module at a path. Returns an instance of Csml upon success. Any errors will
7173
* result in an IllegalArgumentException being thrown.

src/test/java/at/ac/uibk/dps/cirrina/data/DefaultDescriptions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ object DefaultDescriptions {
88
const val timeout: String = "src/test/resources/pkl/timeout/main.pkl"
99

1010
const val pingPong: String = "src/test/resources/pkl/pingPong/main.pkl"
11+
12+
const val noop: String = "src/test/resources/pkl/noop/main.pkl"
1113
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package at.ac.uibk.dps.cirrina.runtime
2+
3+
import at.ac.uibk.dps.cirrina.cirrina.Runtime
4+
import at.ac.uibk.dps.cirrina.data.DefaultDescriptions
5+
import at.ac.uibk.dps.cirrina.execution.`object`.event.Event
6+
import at.ac.uibk.dps.cirrina.execution.`object`.event.EventHandler
7+
import at.ac.uibk.dps.cirrina.execution.service.RandomServiceImplementationSelector
8+
import at.ac.uibk.dps.cirrina.execution.service.ServiceImplementationBuilder
9+
import at.ac.uibk.dps.cirrina.utils.TestUtils.loggingOpenTelemetry
10+
import at.ac.uibk.dps.cirrina.utils.TestUtils.mockPersistentContext
11+
import java.time.Duration
12+
import org.junit.jupiter.api.Test
13+
import org.junit.jupiter.api.assertDoesNotThrow
14+
import org.junit.jupiter.api.assertTimeout
15+
16+
class NoopTest {
17+
18+
@Test
19+
fun testNoopExecute() {
20+
// Must finish within five seconds
21+
assertTimeout(Duration.ofSeconds(5)) {
22+
// Should not throw any exception
23+
assertDoesNotThrow {
24+
// Mock the event handler
25+
val mockEventHandler =
26+
object : EventHandler() {
27+
override fun close() {}
28+
29+
override fun sendEvent(event: Event, source: String) = propagateEvent(event)
30+
31+
override fun subscribe(topic: String) {}
32+
33+
override fun unsubscribe(topic: String) {}
34+
35+
override fun subscribe(source: String, subject: String) {}
36+
37+
override fun unsubscribe(source: String, subject: String) {}
38+
}
39+
40+
// Mock the persistent context
41+
val mockPersistentContext = mockPersistentContext()
42+
43+
// Create a map from service types to service implementations
44+
val services = ServiceImplementationBuilder.from(listOf()).build()
45+
val serviceImplementationSelector = RandomServiceImplementationSelector(services)
46+
47+
// Create and run the runtime using a single state machine.
48+
Runtime(
49+
loggingOpenTelemetry(),
50+
serviceImplementationSelector,
51+
mockEventHandler,
52+
mockPersistentContext,
53+
)
54+
.run(DefaultDescriptions.noop, listOf("stateMachine"))
55+
}
56+
}
57+
}
58+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
amends "modulepath:/pkl/csm/Csml.pkl"
2+
import "noopStateMachine.pkl"
3+
4+
name = "noop"
5+
version = "3.0.0"
6+
stateMachines {
7+
new noopStateMachine.StateMachine {}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "modulepath:/pkl/csm/Csml.pkl"
2+
3+
class StateMachine extends Csml.StateMachineDescription {
4+
name = "stateMachine"
5+
states {
6+
new Csml.StateDescription {
7+
name = "a"
8+
initial = true
9+
terminal = true
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)