org.http4k.hamkrest.request.kt Maven / Gradle / Ivy
package org.http4k.hamkrest
import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.has
import com.natpryce.hamkrest.matches
import com.natpryce.hamkrest.present
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Uri
import org.http4k.core.body.form
import org.http4k.core.cookie.Cookie
import org.http4k.core.cookie.cookie
import org.http4k.lens.QueryLens
fun hasQuery(lens: QueryLens, matcher: Matcher): Matcher = LensMatcher(httpMessageHas("Query '${lens.meta.name}'", { req: Request -> lens(req) }, matcher))
@JvmName("hasQueryNullableString")
fun hasQuery(name: String, matcher: Matcher): Matcher = httpMessageHas("Query '$name'", { req: Request -> req.query(name) }, matcher)
fun hasQuery(name: String, matcher: Matcher): Matcher = httpMessageHas("Query '$name'", { req: Request -> req.query(name) }, present(matcher))
fun hasQuery(name: String, expected: CharSequence): Matcher = hasQuery(name, equalTo(expected))
fun hasQuery(name: String, expected: Regex): Matcher = hasQuery(name, present(matches(expected)))
fun hasQuery(name: String, expected: List): Matcher = httpMessageHas("Queries '$name'", { req: Request -> req.queries(name) }, equalTo(expected))
@JvmName("hasFormNullableString")
fun hasForm(name: String, matcher: Matcher): Matcher = httpMessageHas("Form '$name'", { req: Request -> req.form(name) }, present(matcher))
fun hasForm(name: String, matcher: Matcher): Matcher = httpMessageHas("Form '$name'", { req: Request -> req.form(name) }, present(matcher))
fun hasForm(name: String, expected: Regex): Matcher = hasForm(name, matches(expected))
fun hasForm(name: String, expected: CharSequence): Matcher = hasForm(name, equalTo(expected))
fun hasMethod(expected: Method): Matcher = httpMessageHas("Method", { req: Request -> req.method }, equalTo(expected))
fun hasUri(expected: Regex): Matcher = hasUri(has(Uri::toString, matches(expected)))
fun hasUri(expected: Uri): Matcher = hasUri(equalTo(expected))
fun hasUri(expected: String): Matcher = hasUri(has(Uri::toString, equalTo(expected)))
fun hasUri(expected: Matcher): Matcher = httpMessageHas("Uri", { req: Request -> req.uri }, expected)
fun hasCookie(expected: Cookie): Matcher = hasCookie(expected.name, equalTo(expected))
fun hasCookie(name: String, expected: Regex): Matcher = hasCookie(name, hasCookieValue(matches(expected)))
fun hasCookie(name: String, expected: String): Matcher = hasCookie(name, hasCookieValue(expected))
fun hasCookie(name: String, matcher: Matcher): Matcher = httpMessageHas("Cookie '$name'", { r: Request -> r.cookie(name)!! }, matcher)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy