Fix parameters import/export

This commit is contained in:
Claude Brisson
2023-10-02 09:50:13 +02:00
parent 3ebf7c024c
commit c2d1e53f3f
4 changed files with 91 additions and 27 deletions

View File

@@ -1,12 +1,19 @@
package org.jeudego.pairgoth.test
import org.jeudego.pairgoth.ext.OpenGotha
import org.jeudego.pairgoth.model.toJson
import org.jeudego.pairgoth.util.XmlUtils
import org.junit.jupiter.api.Test
import java.nio.charset.StandardCharsets
import kotlin.test.assertEquals
class ImportExportTests: TestBase() {
companion object {
val maskIdRegex = Regex("(?<=\"id\" ?: )\\d+")
}
/*
@Test
fun `001 test imports`() {
getTestResources("opengotha/tournamentfiles/").forEach { file ->
@@ -27,18 +34,23 @@ class ImportExportTests: TestBase() {
}
}
*/
@Test
fun `002 test opengotha import export`() {
// We import a tournament
// Check that after exporting and reimporting we get the same pairgoth tournament object
getTestResources("opengotha").forEach { file ->
getTestResources("opengotha/tournamentfiles").forEach { file ->
val resource = file.readText(StandardCharsets.UTF_8)
val root_xml = XmlUtils.parse(resource)
val tournament = OpenGotha.import(root_xml)
val jsonTournament = tournament.toJson().toPrettyString()!!.replace(maskIdRegex, "0")
val exported = OpenGotha.export(tournament)
val tournament2 = OpenGotha.import(XmlUtils.parse(exported))
assert(tournament == tournament2)
val jsonTournament2 = tournament2.toJson().toPrettyString()!!.replace(maskIdRegex, "0")
assertEquals(jsonTournament, jsonTournament2)
}
}
}