本文整理汇总了Scala中com.wix.hoopoe.http.testkit.EmbeddedHttpProbe类的典型用法代码示例。如果您正苦于以下问题:Scala EmbeddedHttpProbe类的具体用法?Scala EmbeddedHttpProbe怎么用?Scala EmbeddedHttpProbe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EmbeddedHttpProbe类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PaymentexpressDriver
//设置package包名称以及导入依赖的类
package com.wix.pay.paymentexpress.testkit
import com.wix.hoopoe.http.testkit.EmbeddedHttpProbe
import com.wix.pay.paymentexpress.model.{TransactionRequest, TransactionResponse}
import com.wix.pay.paymentexpress.{TransactionRequestParser, TransactionResponseParser}
import spray.http._
class PaymentexpressDriver(port: Int) {
private val probe = new EmbeddedHttpProbe(port, EmbeddedHttpProbe.NotFoundHandler)
private val transactionRequestParser = new TransactionRequestParser
private val transactionResponseParser = new TransactionResponseParser
def startProbe() {
probe.doStart()
}
def stopProbe() {
probe.doStop()
}
def resetProbe() {
probe.handlers.clear()
}
def aRequestFor(request: TransactionRequest): RequestCtx = {
new RequestCtx(request)
}
class RequestCtx(request: TransactionRequest) {
def returns(response: TransactionResponse) {
probe.handlers += {
case HttpRequest(
HttpMethods.POST,
Uri.Path("/"),
_,
entity,
_) if isStubbedRequestEntity(entity) =>
HttpResponse(
status = StatusCodes.OK,
entity = HttpEntity(ContentType(MediaTypes.`application/xml`), transactionResponseParser.stringify(response)))
}
}
private def isStubbedRequestEntity(entity: HttpEntity): Boolean = {
val parsedRequest = transactionRequestParser.parse(entity.asString)
request == parsedRequest
}
}
}