|
| 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 application.presenter.database |
| 10 | + |
| 11 | +import application.presenter.database.model.TimeSeriesDataType |
| 12 | +import application.presenter.database.model.TimeSeriesRoomEnvironmentalData |
| 13 | +import application.presenter.database.model.TimeSeriesRoomMetadata |
| 14 | +import application.presenter.database.serialization.toRoomEnvironmentalData |
| 15 | +import application.presenter.database.serialization.toTimeSeries |
| 16 | +import entity.environment.Humidity |
| 17 | +import entity.environment.LightUnit |
| 18 | +import entity.environment.Luminosity |
| 19 | +import entity.environment.Presence |
| 20 | +import entity.environment.Temperature |
| 21 | +import entity.environment.TemperatureUnit |
| 22 | +import entity.zone.RoomEnvironmentalData |
| 23 | +import entity.zone.RoomID |
| 24 | +import io.kotest.core.spec.style.StringSpec |
| 25 | +import io.kotest.matchers.shouldBe |
| 26 | +import java.time.Instant |
| 27 | + |
| 28 | +class DBSerializationTest : StringSpec({ |
| 29 | + val roomId = RoomID("test") |
| 30 | + val dateTime = Instant.now() |
| 31 | + val roomEnvironmentalData = RoomEnvironmentalData( |
| 32 | + Temperature(33.0, TemperatureUnit.CELSIUS), |
| 33 | + Humidity(55.0), |
| 34 | + Luminosity(150.0, LightUnit.LUX), |
| 35 | + Presence(true) |
| 36 | + ) |
| 37 | + val timeSeries = mapOf( |
| 38 | + TimeSeriesDataType.TEMPERATURE to TimeSeriesRoomEnvironmentalData( |
| 39 | + dateTime, |
| 40 | + TimeSeriesRoomMetadata(roomId, TimeSeriesDataType.TEMPERATURE, TemperatureUnit.CELSIUS.toString()), |
| 41 | + 33.0 |
| 42 | + ), |
| 43 | + TimeSeriesDataType.HUMIDITY to TimeSeriesRoomEnvironmentalData( |
| 44 | + dateTime, |
| 45 | + TimeSeriesRoomMetadata(roomId, TimeSeriesDataType.HUMIDITY), |
| 46 | + 55.0 |
| 47 | + ), |
| 48 | + TimeSeriesDataType.LUMINOSITY to TimeSeriesRoomEnvironmentalData( |
| 49 | + dateTime, |
| 50 | + TimeSeriesRoomMetadata(roomId, TimeSeriesDataType.LUMINOSITY, LightUnit.LUX.toString()), |
| 51 | + 150.0 |
| 52 | + ), |
| 53 | + TimeSeriesDataType.PRESENCE to TimeSeriesRoomEnvironmentalData( |
| 54 | + dateTime, |
| 55 | + TimeSeriesRoomMetadata(roomId, TimeSeriesDataType.PRESENCE), |
| 56 | + 1.0 |
| 57 | + ), |
| 58 | + ) |
| 59 | + |
| 60 | + "It should be possible to convert a map of time series data to the room environmental data" { |
| 61 | + timeSeries.toRoomEnvironmentalData() shouldBe roomEnvironmentalData |
| 62 | + } |
| 63 | + |
| 64 | + "It should be possible to obtain the time series from the environmental data of a room" { |
| 65 | + roomEnvironmentalData.toTimeSeries(dateTime, roomId) shouldBe timeSeries |
| 66 | + } |
| 67 | +}) |
0 commit comments