Hoverfly Ktor клиент Apache Kotlin
Я попытался сделать юнит-тест с Hoverfly, чтобы издеваться над внешним API.
companion object {
@ClassRule @JvmField
val hoverflyRule: HoverflyRule = HoverflyRule.inSimulationMode(dsl(
service("people.zoho.com")
.get("/people/api/forms/P_EmployeeView/records").queryParam("authtoken","TOKEN")
.willReturn(success("{test:test}", "application/json"))
))
}
Когда я использую клиент Apache с ktor, это не работает. Но с другим клиентом, таким как Khttp, это работает. Есть идеи почему?
1 ответ
Вы должны установить системный прокси по умолчанию в Apache
config: http://hoverfly.readthedocs.io/projects/hoverfly-java/en/latest/pages/misc/misc.html
пример с ktor(0.9.3-alpha-3)
:
class ApplicationMockupTest {
companion object {
@ClassRule
@JvmField
val hoverflyRule: HoverflyRule = HoverflyRule.inSimulationMode(
dsl(
service("people.zoho.com:443")
.get("/people/api/forms/P_EmployeeView/records")
.queryParam("authtoken", "TOKEN")
.willReturn(success("{j:gr}", "application/json"))
)
)
}
@Test
fun exampleTest() = runBlocking<Unit> {
val client = HttpClient(Apache.setupDefaultProxy())
val token = "TOKEN"
val url = "https://people.zoho.com/people/api/forms/P_EmployeeView/records?authtoken=$token"
val requestString = client.get<String>(url)
hoverflyRule.verifyAll()
Unit
}
fun HttpClientEngineFactory<ApacheEngineConfig>.setupDefaultProxy() = config {
customizeClient {
useSystemProperties()
}
}
}