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

tech.harmonysoft.oss.http.server.mock.request.condition.PartialJsonMatchCondition.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.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