Skip to content

Commit f5d9a5f

Browse files
author
Kristel
committed
test refactoring
1 parent 4f30190 commit f5d9a5f

14 files changed

+244
-219
lines changed

tado-api-test/src/test/kotlin/tadoclient/apis/DeviceApi_IT.kt

+2-38
Original file line numberDiff line numberDiff line change
@@ -126,48 +126,12 @@ class DeviceApi_IT (
126126
verifyNested(zoneControl, endpoint, endpoint, typeName,
127127
nullAllowedProperties = listOf(
128128
"$typeName.duties.driver",
129-
// "$typeName.duties.drivers",
130-
"$typeName.duties.leader",
131-
"$typeName.duties.leaders",
132-
"$typeName.duties.ui",
133-
"$typeName.duties.uis"),
134-
stopAtProperties = listOf(
135-
"$typeName.duties.driver",
136129
"$typeName.duties.drivers",
137130
"$typeName.duties.leader",
138131
"$typeName.duties.leaders",
139132
"$typeName.duties.ui",
140-
"$typeName.duties.uis"))
141-
142-
// verify duties.driver
143-
zoneControl.duties?.driver?.let {
144-
verifyDevice(it, endpoint, "$endpoint.duties.driver")
145-
}
146-
147-
// verify duties.leader
148-
zoneControl.duties?.leader?.let {
149-
verifyDevice(it, endpoint, "$endpoint.duties.leader")
150-
}
151-
152-
// verify duties.ui
153-
zoneControl.duties?.ui?.let {
154-
verifyDevice(it, endpoint, "$endpoint.duties.ui")
155-
}
156-
157-
// verify duties.drivers
158-
zoneControl.duties?.drivers?.let {
159-
it.forEachIndexed { i, device -> verifyDevice(device, endpoint, "$endpoint.duties.drivers[$i]")}
160-
}
161-
162-
// verify duties.leaders
163-
zoneControl.duties?.leaders?.let {
164-
it.forEachIndexed { i, device -> verifyDevice(device, endpoint, "$endpoint.duties.leaders[$i]")}
165-
}
166-
167-
// verify duties.leaders
168-
zoneControl.duties?.uis?.let {
169-
it.forEachIndexed { i, device -> verifyDevice(device, endpoint, "$endpoint.uis.uis[$i]") }
170-
}
133+
"$typeName.duties.uis")
134+
)
171135
}
172136

173137
@Test

tado-api-test/src/test/kotlin/tadoclient/apis/ReportApi_IT.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.springframework.web.client.RestClient
1212
import tadoclient.Application
1313
import tadoclient.TadoConfig
1414
import tadoclient.models.ZoneType
15+
import tadoclient.verify.ZONE_TYPE
1516
import tadoclient.verify.assertCorrectResponse
1617
import tadoclient.verify.verifyDayReport
1718
import java.time.LocalDate
@@ -46,6 +47,6 @@ class ReportApi_IT (
4647
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/dayReport"
4748
val dayReport = assertCorrectResponse { tadoStrictReportAPI.getZoneDayReport(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, LocalDate.of(2024, Month.JANUARY, 11)) }
4849
assertNotNull(dayReport)
49-
verifyDayReport(ZoneType.HEATING, dayReport, endpoint)
50+
verifyDayReport(dayReport, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
5051
}
5152
}

tado-api-test/src/test/kotlin/tadoclient/apis/ZoneApi_IT.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ZoneApi_IT(
5858
fun getZoneCapabilities_HeatingZone() {
5959
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/capabilities"
6060
val zoneCapabilities = assertCorrectResponse { tadoStrictZoneAPI.getZoneCapabilities(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id) }
61-
verifyZoneCapabilities(Pair(ZoneType.HEATING, true), zoneCapabilities, endpoint)
61+
verifyZoneCapabilities(zoneCapabilities, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
6262
}
6363

6464
@Test
@@ -68,8 +68,8 @@ class ZoneApi_IT(
6868
fun getZoneCapabilities_HotWaterZone() {
6969
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/capabilities"
7070
val zoneCapabilities = assertCorrectResponse { tadoStrictZoneAPI.getZoneCapabilities(tadoConfig.home!!.id, tadoConfig.zone!!.hotWater!!.id) }
71-
verifyZoneCapabilities(Pair(ZoneType.HOT_WATER, tadoConfig.zone!!.hotWater!!.canSetTemperature), zoneCapabilities, endpoint)
72-
verifyZoneCapabilities(Pair(ZoneType.HOT_WATER, tadoConfig.zone!!.hotWater!!.canSetTemperature), zoneCapabilities, endpoint)
71+
verifyZoneCapabilities(zoneCapabilities, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HOT_WATER))
72+
verifyZoneCapabilities(zoneCapabilities, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HOT_WATER))
7373
}
7474

7575
@Test
@@ -120,7 +120,7 @@ class ZoneApi_IT(
120120
fun getZoneState_Heating() {
121121
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/state"
122122
val zoneState = assertCorrectResponse { tadoStrictZoneAPI.getZoneState(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id) }
123-
verifyZoneState(Pair(ZoneType.HEATING, true), zoneState, endpoint)
123+
verifyZoneState(zoneState, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
124124
}
125125

126126
@Test
@@ -130,7 +130,7 @@ class ZoneApi_IT(
130130
fun getZoneState_HotWater() {
131131
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/state"
132132
val zoneState = assertCorrectResponse { tadoStrictZoneAPI.getZoneState(tadoConfig.home!!.id, tadoConfig.zone!!.hotWater!!.id) }
133-
verifyZoneState(Pair(ZoneType.HOT_WATER, tadoConfig.zone!!.hotWater!!.canSetTemperature), zoneState, endpoint)
133+
verifyZoneState(zoneState, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HOT_WATER))
134134
}
135135

136136
@Test
@@ -158,13 +158,13 @@ class ZoneApi_IT(
158158
val zoneStates = assertCorrectResponse { tadoStrictZoneAPI.getZoneStates(tadoConfig.home!!.id) }
159159

160160
if (isHeatingZoneConfigured()) {
161-
verifyZoneState(Pair(ZoneType.HEATING, true), zoneStates.zoneStates?.get(tadoConfig.zone!!.heating!!.id.toString())!!, endpoint)
161+
verifyZoneState(zoneStates.zoneStates?.get(tadoConfig.zone!!.heating!!.id.toString())!!, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
162162
}
163163
if (isHotWaterZoneConfigured()) {
164-
verifyZoneState(Pair(ZoneType.HOT_WATER, tadoConfig.zone!!.hotWater!!.canSetTemperature), zoneStates.zoneStates?.get(tadoConfig.zone!!.hotWater!!.id.toString())!!, endpoint)
164+
verifyZoneState(zoneStates.zoneStates?.get(tadoConfig.zone!!.hotWater!!.id.toString())!!, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HOT_WATER))
165165
}
166166
if (isAirConZoneConfigured()) {
167-
verifyZoneState(Pair(ZoneType.AIR_CONDITIONING, true), zoneStates.zoneStates?.get(tadoConfig.zone!!.airCon!!.id.toString())!!, endpoint)
167+
verifyZoneState(zoneStates.zoneStates?.get(tadoConfig.zone!!.airCon!!.id.toString())!!, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.AIR_CONDITIONING))
168168
}
169169
}
170170

tado-api-test/src/test/kotlin/tadoclient/apis/ZoneControlApi_IT.kt

+26-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlin.test.assertEquals
1616
import kotlin.test.assertNotEquals
1717
import kotlin.test.assertNotNull
1818

19-
@SpringBootTest(classes = arrayOf( Application::class))
19+
@SpringBootTest(classes = [Application::class])
2020
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
2121
@DisplayName("tado API - zone control")
2222
class ZoneControlApi_IT(
@@ -32,8 +32,8 @@ class ZoneControlApi_IT(
3232
@Autowired
3333
tadoConfig: TadoConfig
3434
) : BaseTest(tadoConfig) {
35-
val tadoZoneControlAPI = ZoneControlApi(tadoRestClient)
36-
val tadoStrictZoneControlAPI = ZoneControlApi(tadoStrictRestClient)
35+
private val tadoZoneControlAPI = ZoneControlApi(tadoRestClient)
36+
private val tadoStrictZoneControlAPI = ZoneControlApi(tadoStrictRestClient)
3737

3838

3939
private var defaultZoneOverlayBeforeTest: DefaultZoneOverlay? = null
@@ -50,17 +50,17 @@ class ZoneControlApi_IT(
5050
@BeforeAll
5151
fun before() = try {
5252
defaultZoneOverlayBeforeTest = tadoZoneControlAPI.getDefaultZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
53-
earlyStartBeforeTest = tadoZoneControlAPI.getEarlyStart(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
54-
zoneOverlayBeforeTest = tadoZoneControlAPI.getZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
55-
zoneAwayConfigurationBeforeTest = tadoZoneControlAPI.getAwayConfiguration(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
56-
activeTimetableTypeBeforeStart = tadoZoneControlAPI.getActiveTimetableType(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
53+
earlyStartBeforeTest = tadoZoneControlAPI.getEarlyStart(tadoConfig.home.id, tadoConfig.zone.heating!!.id)
54+
zoneOverlayBeforeTest = tadoZoneControlAPI.getZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating.id)
55+
zoneAwayConfigurationBeforeTest = tadoZoneControlAPI.getAwayConfiguration(tadoConfig.home.id, tadoConfig.zone.heating.id)
56+
activeTimetableTypeBeforeStart = tadoZoneControlAPI.getActiveTimetableType(tadoConfig.home.id, tadoConfig.zone.heating.id)
5757
} catch (e: Exception) {
5858
// ignore
5959
}
6060

6161
// reset the overlay status to the state it had before we started running the tests
6262
// TODO: conditionally on presence of set-up
63-
@AfterAll()
63+
@AfterAll
6464
fun after() {
6565
// EarlyStart
6666
earlyStartBeforeTest?.let {
@@ -220,8 +220,8 @@ class ZoneControlApi_IT(
220220
tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay1)
221221

222222
// now we can test
223-
val zoneOverlay = assertCorrectResponse { tadoStrictZoneControlAPI.getZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id) }
224-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), zoneOverlay, endpoint)
223+
val zoneOverlay = assertCorrectResponse { tadoStrictZoneControlAPI.getZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id) }
224+
verifyZoneOverlay(zoneOverlay, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
225225
}
226226

227227
@Test
@@ -234,7 +234,7 @@ class ZoneControlApi_IT(
234234

235235
// now we can test
236236
assertHttpErrorStatus(HttpStatus.NOT_FOUND) {
237-
tadoStrictZoneControlAPI.getZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id)
237+
tadoStrictZoneControlAPI.getZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id)
238238
}
239239
}
240240

@@ -267,8 +267,8 @@ class ZoneControlApi_IT(
267267
power = Power.OFF),
268268
termination = ZoneOverlayTermination(typeSkillBasedApp = ZoneOverlayTerminationTypeSkillBasedApp.MANUAL)
269269
)
270-
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay) }
271-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), result, endpoint)
270+
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id, zoneOverlay) }
271+
verifyZoneOverlay(result, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
272272
}
273273

274274
// result:
@@ -293,8 +293,8 @@ class ZoneControlApi_IT(
293293
),
294294
termination = ZoneOverlayTermination(typeSkillBasedApp = ZoneOverlayTerminationTypeSkillBasedApp.MANUAL)
295295
)
296-
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay) }
297-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), result, endpoint)
296+
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id, zoneOverlay) }
297+
verifyZoneOverlay(result, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
298298
}
299299

300300
// Result:
@@ -339,8 +339,8 @@ class ZoneControlApi_IT(
339339
),
340340
termination = ZoneOverlayTermination(typeSkillBasedApp = ZoneOverlayTerminationTypeSkillBasedApp.TADO_MODE)
341341
)
342-
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay) }
343-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), result, endpoint)
342+
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id, zoneOverlay) }
343+
verifyZoneOverlay(result, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
344344
}
345345

346346

@@ -365,8 +365,8 @@ class ZoneControlApi_IT(
365365
),
366366
termination = ZoneOverlayTermination(typeSkillBasedApp = ZoneOverlayTerminationTypeSkillBasedApp.NEXT_TIME_BLOCK)
367367
)
368-
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay) }
369-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), result, endpoint)
368+
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id, zoneOverlay) }
369+
verifyZoneOverlay(result, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
370370
}
371371

372372
// Result:
@@ -396,8 +396,8 @@ class ZoneControlApi_IT(
396396
durationInSeconds = 1000
397397
)
398398
)
399-
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, zoneOverlay) }
400-
verifyZoneOverlay(Pair(ZoneType.HEATING, true), result, endpoint)
399+
val result = assertCorrectResponse { tadoStrictZoneControlAPI.setZoneOverlay(tadoConfig.home.id, tadoConfig.zone.heating!!.id, zoneOverlay) }
400+
verifyZoneOverlay(result, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
401401
}
402402

403403
@Test
@@ -417,7 +417,7 @@ class ZoneControlApi_IT(
417417
val endpoint = "GET /homes/{homeId}/zones/{zoneId}/schedule/awayConfiguration"
418418
val awayConfiguration = assertCorrectResponse { tadoStrictZoneControlAPI.getAwayConfiguration(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id) }
419419
assertNotNull(awayConfiguration)
420-
verifyZoneAwayConfiguration(Pair(ZoneType.HEATING, true), awayConfiguration, endpoint)
420+
verifyZoneAwayConfiguration(awayConfiguration, endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
421421
}
422422

423423
@Test
@@ -495,7 +495,7 @@ class ZoneControlApi_IT(
495495
}
496496
assertNotNull(timetableBlocks)
497497
assertNotEquals(0, timetableBlocks.size)
498-
verifyTimetableBlock(Pair(ZoneType.HEATING, true), timetableBlocks[0], endpoint)
498+
verifyTimetableBlock(timetableBlocks[0], endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
499499
}
500500

501501
@Test
@@ -509,7 +509,7 @@ class ZoneControlApi_IT(
509509
}
510510
assertNotNull(timetableBlocks)
511511
assertNotEquals(0, timetableBlocks.size)
512-
verifyTimetableBlock(Pair(ZoneType.HEATING, true), timetableBlocks[0], endpoint)
512+
verifyTimetableBlock(timetableBlocks[0], endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
513513
}
514514

515515
@Test
@@ -524,10 +524,10 @@ class ZoneControlApi_IT(
524524
// ... and use that as the input for the PUT call
525525
// returned 500 Internal Server Error: "Please contact customer support"
526526
val response = assertCorrectResponse {
527-
tadoStrictZoneControlAPI.setTimetableBlocksForDayType(tadoConfig.home!!.id, tadoConfig.zone!!.heating!!.id, TimetableTypeId._1, DayType.SATURDAY, timetableBlocks)
527+
tadoStrictZoneControlAPI.setTimetableBlocksForDayType(tadoConfig.home.id, tadoConfig.zone.heating!!.id, TimetableTypeId._1, DayType.SATURDAY, timetableBlocks)
528528
}
529529
assertNotNull(timetableBlocks)
530530
assertNotEquals(0, response.size)
531-
verifyTimetableBlock(Pair(ZoneType.HEATING, true), response[0], endpoint)
531+
verifyTimetableBlock(response[0], endpoint, ancestorObjectProps = mapOf(ZONE_TYPE to ZoneType.HEATING))
532532
}
533533
}

tado-api-test/src/test/kotlin/tadoclient/config/RestClientConfig.kt

+13-12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ open class RestClientConfig(
4949
// this won't take effect for some reason
5050
@Bean
5151
open fun tadoJsonCustomizer(): Jackson2ObjectMapperBuilderCustomizer {
52-
println("#### tadoJsonCustomizer ####")
52+
println("init tadoJsonCustomizer")
5353
return Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
5454
builder
5555
// neither of these two options work...
@@ -61,7 +61,7 @@ open class RestClientConfig(
6161
@Bean
6262
@Primary
6363
open fun jackson2ObjectMapperBuilder(): Jackson2ObjectMapperBuilder {
64-
println("$$$$ jackson2ObjectMapperBuilder $$$$")
64+
println("init jackson2ObjectMapperBuilder")
6565
return Jackson2ObjectMapperBuilder()
6666
// neither of these two options work...
6767
.failOnUnknownProperties(true)
@@ -70,7 +70,7 @@ open class RestClientConfig(
7070

7171
@Bean // Convertor method
7272
open fun messageConverter() : MappingJackson2HttpMessageConverter{
73-
println("%%%% messageConverter %%%%")
73+
println("init messageConverter")
7474
val builder = Jackson2ObjectMapperBuilder()
7575
.failOnUnknownProperties(true)
7676
.featuresToEnable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
@@ -90,18 +90,19 @@ open class RestClientConfig(
9090
.messageConverters { converters ->
9191
// println("message converters:")
9292
if (strict) {
93+
System.out.println("init strict RestClient")
9394
converters.forEach {
9495
// println(" " + it.javaClass.simpleName)
9596
if (it is MappingJackson2HttpMessageConverter) {
96-
println(
97-
"FAIL_ON_UNKNOWN_PROPERTIES enabled: ${
98-
it.objectMapper.deserializationConfig.isEnabled(
99-
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
100-
)
101-
}"
102-
)
103-
println("converter: $it")
104-
println("object mapper: ${it.objectMapper}")
97+
// println(
98+
// "FAIL_ON_UNKNOWN_PROPERTIES enabled: ${
99+
// it.objectMapper.deserializationConfig.isEnabled(
100+
// DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
101+
// )
102+
// }"
103+
// )
104+
// println("converter: $it")
105+
// println("object mapper: ${it.objectMapper}")
105106
it.objectMapper.enable(
106107
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
107108
)

0 commit comments

Comments
 (0)