在具有 swagger 支持的 scalatra 应用程序上调用原型 spec3 测试用例时,测试失败。
这是测试/规范代码:ServletSpec.scala
class ServletSpec extends ScalatraSpec { def is =
"Calling the generated swagger client" ^
"should return success" ! swaggerClient^
end
addServlet(classOf[TestController], "/api/*")
def swaggerClient = get("/api/account") {
status must_== 200
response.body must_==
"""my json response"""
}
}
TestController 看起来像:package com.newco
import org.scalatra._
import org.scalatra.swagger._
//sample - see http://www.scalatra.org/guides/swagger.html
// JSON-related libraries
import org.json4s.{DefaultFormats, Formats}
// JSON handling support from Scalatra
import org.scalatra.json._
class TestController(implicit val swagger: Swagger) extends ScalatraServlet
with JacksonJsonSupport with JValueResult {
protected val applicationName = Some("AppName")
protected val applicationDescription = "description."
// Sets up automatic case class to JSON output serialization
protected implicit val jsonFormats: Formats = DefaultFormats
// Before every action runs, set the content type to be in JSON format.
before() {
contentType = formats("json")
}
val getAccount =
(apiOperation[GetAccountResponse]("getAccount")
summary "Get users account information"
notes "Returns the users profile"
parameter queryParam[AccessToken]("accessToken").description("Access token returned from authentication service")
)
get("/account", operation(getAccount)){
SampleData.getAccountResponse
}
}
sbt 测试失败并出现以下错误(没有可用的详细跟踪):[error] x 应该返回成功 [error] ' [error] [error] [error] Error 500 com.acme.TestController [error] [error] [error]
HTTP 错误:500
[错误]访问 /api/account 时出现问题。原因:[错误]
com.acme.TestController[错误]
Powered by Jetty:// [error]
[error] [error] [error] ' [error] 不等于...