All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.hamkrest.httpMessage.kt Maven / Gradle / Ivy

package org.http4k.hamkrest

import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.anything
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.has
import com.natpryce.hamkrest.matches
import com.natpryce.hamkrest.present
import org.http4k.core.Body
import org.http4k.core.ContentType
import org.http4k.core.HttpMessage
import org.http4k.format.Json
import org.http4k.lens.BodyLens
import org.http4k.lens.Header
import org.http4k.lens.HeaderLens

fun  hasHeader(lens: HeaderLens, matcher: Matcher): Matcher = LensMatcher(has("Header '${lens.meta.name}'", { req: HttpMessage -> lens(req) }, matcher))

@JvmName("hasBodyNullableString")
fun hasHeader(name: String, matcher: Matcher): Matcher = has("Header '$name'", { m: HttpMessage -> m.header(name) }, matcher)

fun hasHeader(name: String, matcher: Matcher): Matcher = has("Header '$name'", { m: HttpMessage -> m.header(name) }, present(matcher))

fun hasHeader(name: String, expected: CharSequence): Matcher = hasHeader(name, equalTo(expected))

fun hasHeader(name: String, expected: Regex): Matcher = hasHeader(name, present(matches(expected)))

fun hasHeader(name: String): Matcher = has("Header '$name'", { m: HttpMessage -> m.header(name) }, present(anything))

fun hasHeader(name: String, expected: List): Matcher = has("Header '$name'", { m: HttpMessage -> m.headerValues(name) }, equalTo(expected))

fun hasContentType(expected: ContentType): Matcher = has("Content-Type", { m: HttpMessage -> Header.CONTENT_TYPE(m) }, equalTo(expected))

fun hasBody(expected: Matcher): Matcher = has("Body", { m: HttpMessage -> m.body }, expected)

@JvmName("hasBodyNullableString")
fun hasBody(expected: Matcher): Matcher = has("Body", { m: HttpMessage -> m.bodyString() }, expected)

@JvmName("hasBodyString")
fun hasBody(expected: Matcher): Matcher = has("Body", { m: HttpMessage -> m.bodyString() }, expected)

fun hasBody(expected: CharSequence): Matcher = hasBody(equalTo(expected))

fun hasBody(expected: Regex): Matcher = hasBody(present(matches(expected)))

fun  hasBody(lens: BodyLens, matcher: Matcher): Matcher = LensMatcher(has("Body", { m: HttpMessage -> lens(m) }, matcher))

fun  Json.hasBody(expected: NODE): Matcher = has("Body", { m: HttpMessage -> parse(m.bodyString()) }, equalTo(expected))

fun  Json.hasBody(expected: Matcher): Matcher = has("Body", { m: HttpMessage -> parse(m.bodyString()) }, expected)

fun  Json.hasBody(expected: String): Matcher = has("Body", { m: HttpMessage -> compactify(m.bodyString()) }, equalTo(compactify(expected)))




© 2015 - 2025 Weber Informatics LLC | Privacy Policy