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 should return success [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] is not equal to ...