|
| 1 | +package com.monta.library.ocpp.profiles.serialization |
| 2 | + |
| 3 | +import com.monta.library.ocpp.TestUtils |
| 4 | +import com.monta.library.ocpp.common.chargingprofile.ChargingRateUnit |
| 5 | +import com.monta.library.ocpp.common.serialization.Message |
| 6 | +import com.monta.library.ocpp.common.serialization.MessageSerializer |
| 7 | +import com.monta.library.ocpp.common.serialization.ParsingResult |
| 8 | +import com.monta.library.ocpp.common.serialization.SerializationMode |
| 9 | +import com.monta.library.ocpp.v16.error.OcppErrorResponderV16 |
| 10 | +import com.monta.library.ocpp.v16.smartcharge.GetCompositeScheduleConfirmation |
| 11 | +import com.monta.library.ocpp.v16.smartcharge.GetCompositeScheduleStatus |
| 12 | +import io.kotest.core.spec.style.StringSpec |
| 13 | +import io.kotest.matchers.nulls.shouldNotBeNull |
| 14 | +import io.kotest.matchers.shouldBe |
| 15 | +import io.kotest.matchers.types.shouldBeInstanceOf |
| 16 | + |
| 17 | +class GetCompositeScheduleSerializationTest : StringSpec({ |
| 18 | + val messageSerializer = MessageSerializer(SerializationMode.OCPP_1_6, OcppErrorResponderV16) |
| 19 | + |
| 20 | + "parse a valid get composite schedule response" { |
| 21 | + val jsonString = TestUtils.getFileAsString("smartcharge/get-composite-schedule-resp.json") |
| 22 | + val parsingResult = messageSerializer.parse(jsonString) |
| 23 | + |
| 24 | + parsingResult.shouldBeInstanceOf<ParsingResult.Success<Message.Response>>() |
| 25 | + val ocppMessage = parsingResult.value |
| 26 | + |
| 27 | + ocppMessage.shouldBeInstanceOf<Message.Response>() |
| 28 | + ocppMessage.uniqueId shouldBe "d16cd067-9506-441e-902b-af1b9b15b8e4" |
| 29 | + ocppMessage.payload shouldBe TestUtils.toJsonNode("{\"status\":\"Accepted\",\"connectorId\":1,\"scheduleStart\":\"2025-05-22T08:29:27.000Z\",\"chargingSchedule\":{\"duration\":60,\"chargingRateUnit\":\"A\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":32,\"numberPhases\":1}],\"minChargingRate\":0}}") |
| 30 | + |
| 31 | + val response = messageSerializer.deserializePayload(ocppMessage, GetCompositeScheduleConfirmation::class.java) |
| 32 | + response.shouldBeInstanceOf<ParsingResult.Success<GetCompositeScheduleConfirmation>>() |
| 33 | + val payload = response.value |
| 34 | + payload.status shouldBe GetCompositeScheduleStatus.Accepted |
| 35 | + payload.connectorId shouldBe 1 |
| 36 | + payload.scheduleStart.toString() shouldBe "2025-05-22T08:29:27Z" |
| 37 | + payload.chargingSchedule shouldNotBeNull { |
| 38 | + chargingRateUnit shouldBe ChargingRateUnit.A |
| 39 | + duration shouldBe 60 |
| 40 | + minChargingRate shouldBe 0.0 |
| 41 | + chargingSchedulePeriod shouldNotBeNull { |
| 42 | + size shouldBe 1 |
| 43 | + this[0].startPeriod shouldBe 0 |
| 44 | + this[0].limit shouldBe 32.0 |
| 45 | + this[0].numberPhases shouldBe 1 |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +}) |
0 commit comments