Changeset View
Changeset View
Standalone View
Standalone View
src/test/java/net/wildfyre/http/RequestTest.kt
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | fun createTmpUser(): LoggedUser { | ||||
val username = "tmp${rnd.nextInt()}" | val username = "tmp${rnd.nextInt()}" | ||||
Request(POST, "/account/register/") | Request(POST, "/account/register/") | ||||
.addJson(JsonObject() | .addJson(JsonObject() | ||||
.add("username", username) | .add("username", username) | ||||
.add("email", "123456@wildfyre.net") | .add("email", "123456@wildfyre.net") | ||||
.add("password", password) | .add("password", password) | ||||
.add("captcha", "123456")) // the field cannot be blank, but is useless in test mode | .add("captcha", "123456")) // the field cannot be blank, but is useless in test mode | ||||
.getJson().asObject() | .getJson().asObject() | ||||
CLOVIS: @Info-Screen This is the request that breaks because of wrong captcha | |||||
WildFyre.disconnect() | WildFyre.disconnect() | ||||
return WildFyre.connect(username, password) | return WildFyre.connect(username, password) | ||||
} | } | ||||
@Test( timeout = 4000L ) | @Test( timeout = 4000L ) | ||||
fun testPatchMethod() { | fun testPatchMethod() { | ||||
val me = createTmpUser() | val me = createTmpUser() | ||||
val test = "This is a test" | val test = "This is a test" | ||||
me.setBio(test) | me.setBio(test) | ||||
assertEquals(test, me.bio()) | assertEquals(test, me.bio) | ||||
} | } | ||||
@Test( timeout = 4000L ) // timeout of 4 seconds | @Test( timeout = 4000L ) // timeout of 4 seconds | ||||
fun testMultipart() { | fun testMultipart() { | ||||
createTmpUser() | createTmpUser() | ||||
val f = resources["wf.png"] | val f = resources["wf.png"] | ||||
assertTrue("The file ${f.absolutePath} should exist!", f.exists()) | assertTrue("The file ${f.absolutePath} should exist!", f.exists()) | ||||
val json = Request(Method.PATCH, "/users/") | val json = Request(Method.PATCH, "/users/") | ||||
.addFile("avatar", f) | .addFile("avatar", f) | ||||
.addJson(JsonObject().add("bio", "test")) | .addJson(JsonObject().add("bio", "test")) | ||||
.addToken() | .addToken() | ||||
.getJson() | .getJson() | ||||
println(json.toString(PRETTY_PRINT)) | println(json.toString(PRETTY_PRINT)) | ||||
} | } | ||||
companion object { | companion object { | ||||
// The inspector *thinks* it's possible, but it's not, | // The inspector *thinks* it's possible, but it's not, | ||||
// because it needs to be done when the class is loaded | // because it needs to be done when the class is loaded | ||||
// (init) and NOT when the variables are instantiated. | // (init) and NOT when the variables are instantiated. | ||||
@Suppress("JoinDeclarationAndAssignment") | @Suppress("JoinDeclarationAndAssignment") | ||||
internal val token: String | @JvmField internal val token: String | ||||
internal val resources = File("src/test/resources") | @JvmField internal val resources = File("src/test/resources") | ||||
init { | init { | ||||
token = Request(POST, "/account/auth/") | token = Request(POST, "/account/auth/") | ||||
.addJson(JsonObject() | .addJson(JsonObject() | ||||
.add("username", "user") | .add("username", "user") | ||||
.add("password", "password123")) | .add("password", "password123")) | ||||
.getJson().asObject() | .getJson().asObject() | ||||
.getString("token", null) | .getString("token", null) | ||||
Show All 17 Lines |
@Info-Screen This is the request that breaks because of wrong captcha