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

tech.harmonysoft.oss.http.server.mock.request.condition.JsonBodyPathToMatcherCondition.kt Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
package tech.harmonysoft.oss.http.server.mock.request.condition

import org.mockserver.model.HttpRequest
import tech.harmonysoft.oss.jackson.JsonHelper
import tech.harmonysoft.oss.test.matcher.Matcher

data class JsonBodyPathToMatcherCondition(
    val path2matcher: Map,
    val jsonHelper: JsonHelper
) : DynamicRequestCondition {

    override fun matches(request: HttpRequest): Boolean {
        val byPath = jsonHelper.byPath(request.bodyAsJsonOrXmlString)
        return path2matcher.all { (path, matcher) ->
            byPath[path]?.let { actualValue ->
                matcher.matches(actualValue.toString())
            } ?: false
        }
    }

    override fun toString(): String {
        return "target JSON request has the following values: ${path2matcher.entries.joinToString {
            "a value at path '${it.key}' ${it.value}"
        }}"
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy