|
| 1 | +/* |
| 2 | + * Copyright (c) 2023. Smart Operating Block |
| 3 | + * |
| 4 | + * Use of this source code is governed by an MIT-style |
| 5 | + * license that can be found in the LICENSE file or at |
| 6 | + * https://opensource.org/licenses/MIT. |
| 7 | + */ |
| 8 | + |
| 9 | +package instracture.parser |
| 10 | + |
| 11 | +import infrastructure.digitaltwins.DTEventParser |
| 12 | +import io.kotest.core.spec.style.StringSpec |
| 13 | +import io.kotest.matchers.shouldBe |
| 14 | +import io.kotest.matchers.shouldNotBe |
| 15 | + |
| 16 | +/** |
| 17 | + * Test the parsing of Digital Twin Events. |
| 18 | + */ |
| 19 | +class TestEventParser : StringSpec({ |
| 20 | + |
| 21 | + val parser = DTEventParser() |
| 22 | + |
| 23 | + val temperatureUpdateEvent = readFileFromResources("/SampleTemperatureUpdateEvent.json") |
| 24 | + val humidityUpdateEvent = readFileFromResources("/SampleHumidityUpdateEvent.json") |
| 25 | + val luminosityUpdateEvent = readFileFromResources("/SampleLuminosityUpdateEvent.json") |
| 26 | + val trackingEvent = readFileFromResources("/SampleTrackingEvent.json") |
| 27 | + |
| 28 | + "DT parser should parse room event of temperature update" { |
| 29 | + val event = parser.parseEvent(temperatureUpdateEvent) |
| 30 | + event shouldNotBe null |
| 31 | + event.key shouldBe "ROOM_EVENT" |
| 32 | + } |
| 33 | + |
| 34 | + "DT parser should parse room event of humidity update" { |
| 35 | + val event = parser.parseEvent(humidityUpdateEvent) |
| 36 | + event shouldNotBe null |
| 37 | + event.key shouldBe "ROOM_EVENT" |
| 38 | + } |
| 39 | + |
| 40 | + "DT parser should parse room event of luminosity update" { |
| 41 | + val event = parser.parseEvent(luminosityUpdateEvent) |
| 42 | + event shouldNotBe null |
| 43 | + event.key shouldBe "ROOM_EVENT" |
| 44 | + } |
| 45 | + |
| 46 | + "DT parser should parse tracking event" { |
| 47 | + val event = parser.parseEvent(trackingEvent) |
| 48 | + event shouldNotBe null |
| 49 | + event.key shouldBe "TRACKING_EVENT" |
| 50 | + } |
| 51 | +}) |
| 52 | + |
| 53 | +fun readFileFromResources(path: String): String = |
| 54 | + object {}.javaClass.getResource(path)!!.readText() |
0 commit comments