Add test for Swiss pairings
This commit is contained in:
@@ -7,12 +7,12 @@ import org.junit.jupiter.api.MethodOrderer.MethodName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestMethodOrder
|
||||
import java.io.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
|
||||
@TestMethodOrder(MethodName::class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class BasicTests: TestBase() {
|
||||
@@ -38,6 +38,27 @@ class BasicTests: TestBase() {
|
||||
)
|
||||
)
|
||||
|
||||
val aSimpleSwissTournament = Json.Object(
|
||||
"type" to "INDIVIDUAL",
|
||||
"name" to "Simple Swiss",
|
||||
"shortName" to "simple-swiss",
|
||||
"startDate" to "2023-05-10",
|
||||
"endDate" to "2023-05-12",
|
||||
"country" to "FR",
|
||||
"location" to "Grenoble",
|
||||
"online" to false,
|
||||
"timeSystem" to Json.Object(
|
||||
"type" to "FISCHER",
|
||||
"mainTime" to 1800,
|
||||
"increment" to 15
|
||||
),
|
||||
"rounds" to 4,
|
||||
"pairing" to Json.Object(
|
||||
"type" to "SWISS",
|
||||
"method" to "SPLIT_AND_SLIP"
|
||||
)
|
||||
)
|
||||
|
||||
val aTeamTournament = Json.Object(
|
||||
"type" to "TEAM2",
|
||||
"name" to "Mon Tournoi par équipes",
|
||||
@@ -184,4 +205,20 @@ class BasicTests: TestBase() {
|
||||
// TODO check pairing
|
||||
// val expected = """"["id":1,"w":5,"b":6,"h":3,"r":"?"]"""
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `008 simple swiss tournament`() {
|
||||
var resp = TestAPI.post("/api/tour", aSimpleSwissTournament).asObject()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
aTournamentID = resp.getInt("id")
|
||||
resp = TestAPI.post("/api/tour/$aTeamTournamentID/part", aPlayer).asObject()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
|
||||
val inputStream: InputStream = getTestFile("aSimpleSwiss/PlayersList.json").inputStream()
|
||||
|
||||
val inputString = inputStream.bufferedReader().use { it.readText() }
|
||||
println(inputString)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -5,22 +5,9 @@ import org.jeudego.pairgoth.api.ApiHandler
|
||||
import org.jeudego.pairgoth.web.ApiServlet
|
||||
import org.jeudego.pairgoth.web.SSEServlet
|
||||
import org.jeudego.pairgoth.web.WebappManager
|
||||
import org.mockito.kotlin.argumentCaptor
|
||||
import org.mockito.kotlin.doAnswer
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.mock
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringReader
|
||||
import java.io.StringWriter
|
||||
import org.mockito.kotlin.*
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipException
|
||||
import java.util.zip.ZipFile
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
|
||||
@@ -96,3 +83,5 @@ object TestAPI {
|
||||
// Get a list of resources
|
||||
|
||||
fun getTestResources(path: String) = File("${System.getProperty("user.dir")}/src/test/resources/$path").listFiles()
|
||||
|
||||
fun getTestFile(path: String) = File("${System.getProperty("user.dir")}/src/test/resources/$path")
|
18
api-webapp/src/test/resources/aSimpleSwiss/PlayersList.json
Normal file
18
api-webapp/src/test/resources/aSimpleSwiss/PlayersList.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"name": "Burma",
|
||||
"firstname": "Nestor",
|
||||
"rating": "1600",
|
||||
"rank": "-5",
|
||||
"country": "FR",
|
||||
"club": "13Ma"
|
||||
},
|
||||
{
|
||||
"name": "Poirot",
|
||||
"firstname": "Hercule",
|
||||
"rating": "1700",
|
||||
"rank": "-1",
|
||||
"country": "FR",
|
||||
"club": "75Op"
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user