Skip to content

Commit d389377

Browse files
fix: Fix the type for GetCompositeSchedule [COT-342] (#29)
* `scheduleStart`: `Int` -> `ZonedDateTime`
1 parent 7a2ea40 commit d389377

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kotlinVersion=2.1.21
22
javaToolChainVersion=17
3-
libraryVersion=1.0.6
3+
libraryVersion=1.0.7
44
org.gradle.jvmargs=-Xmx4096m
55
org.gradle.warning.mode=all

v16/src/main/kotlin/com/monta/library/ocpp/v16/smartcharge/GetCompositeSchedule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.monta.library.ocpp.common.chargingprofile.ChargingRateUnit
44
import com.monta.library.ocpp.common.profile.Feature
55
import com.monta.library.ocpp.common.profile.OcppConfirmation
66
import com.monta.library.ocpp.common.profile.OcppRequest
7+
import java.time.ZonedDateTime
78

89
object GetCompositeScheduleFeature : Feature {
910
override val name: String = "GetCompositeSchedule"
@@ -25,6 +26,6 @@ data class GetCompositeScheduleRequest(
2526
data class GetCompositeScheduleConfirmation(
2627
val status: GetCompositeScheduleStatus,
2728
val connectorId: Int? = null,
28-
val scheduleStart: Int? = null,
29+
val scheduleStart: ZonedDateTime? = null,
2930
val chargingSchedule: ChargingSchedule? = null
3031
) : OcppConfirmation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[
2+
3,
3+
"d16cd067-9506-441e-902b-af1b9b15b8e4",
4+
{
5+
"status": "Accepted",
6+
"connectorId": 1,
7+
"scheduleStart": "2025-05-22T08:29:27.000Z",
8+
"chargingSchedule": {
9+
"duration": 60,
10+
"chargingRateUnit": "A",
11+
"chargingSchedulePeriod": [
12+
{
13+
"startPeriod": 0,
14+
"limit": 32,
15+
"numberPhases": 1
16+
}
17+
],
18+
"minChargingRate": 0
19+
}
20+
}
21+
]

0 commit comments

Comments
 (0)