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

pl.allegro.tech.servicemesh.envoycontrol.assertions.ResponseAssertions.kt Maven / Gradle / Ivy

There is a newer version: 0.22.4
Show newest version
package pl.allegro.tech.servicemesh.envoycontrol.assertions

import okhttp3.Response
import org.assertj.core.api.ObjectAssert
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension

fun ObjectAssert.isOk(): ObjectAssert {
    matches { it.isSuccessful }
    return this
}

fun ObjectAssert.isForbidden(): ObjectAssert {
    matches({
        it.body?.close()
        it.code == 403
    }, "is forbidden")
    return this
}

fun ObjectAssert.isUnreachable(): ObjectAssert {
    matches({
        it.body?.close()
        it.code == 503 || it.code == 504
    }, "is unreachable")
    return this
}

fun ObjectAssert.isFrom(echoServiceExtension: EchoServiceExtension): ObjectAssert {
    matches {
        it.body?.use { it.string().contains(echoServiceExtension.container().response) } ?: false
    }
    return this
}

fun ObjectAssert.isEitherFrom(vararg echoContainers: EchoServiceExtension): ObjectAssert {
    matches {
        val serviceResponse = it.body?.string() ?: ""
        echoContainers.any { containerExtension -> serviceResponse.contains(containerExtension.container().response) }
    }
    return this
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy