
tech.harmonysoft.oss.http.server.mock.request.condition.PartialJsonMatchCondition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harmonysoft-http-mock-server-test Show documentation
Show all versions of harmonysoft-http-mock-server-test Show documentation
Common general-purpose Kotlin utility
package tech.harmonysoft.oss.http.server.mock.request.condition
import org.mockserver.model.HttpRequest
import tech.harmonysoft.oss.json.JsonApi
import tech.harmonysoft.oss.test.binding.DynamicBindingContext
import tech.harmonysoft.oss.test.json.CommonJsonUtil
class PartialJsonMatchCondition(
private val expectedRawJson: String,
private val expectedParsedJson: Any,
private val jsonApi: JsonApi,
private val context: DynamicBindingContext
) : DynamicRequestCondition {
override fun matches(request: HttpRequest): Boolean {
val actualParsedJson = jsonApi.parseJson(request.bodyAsJsonOrXmlString)
val result = CommonJsonUtil.compareAndBind(
expected = expectedParsedJson,
actual = actualParsedJson,
strict = false
)
return if (result.errors.isEmpty()) {
context.storeBindings(result.boundDynamicValues)
true
} else {
false
}
}
override fun toString(): String {
return expectedRawJson
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy