支持招摇过市的scalatra应用的spec2测试失败
在支持招摇过市的scalatra应用程序上调用原型spec3测试用例时,测试失败 以下是测试/规范代码: ServletSpec.scala支持招摇过市的scalatra应用的spec2测试失败,scala,specs2,scalatra,swagger,Scala,Specs2,Scalatra,Swagger,在支持招摇过市的scalatra应用程序上调用原型spec3测试用例时,测试失败 以下是测试/规范代码: ServletSpec.scala class ServletSpec extends ScalatraSpec { def is = "Calling the generated swagger client" ^ "should return success" ! swaggerClient^
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看起来像:
包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测试失败,出现以下错误(无详细跟踪):
[错误]x应返回成功
com.acme.TestController
[错误]'
com.acme.TestController
[错误]
com.acme.TestController
[错误]
com.acme.TestController
[错误]错误500 com.acme.TestController
com.acme.TestController
[错误]
com.acme.TestController
[错误]
com.acme.TestController
[错误]HTTP错误:500
com.acme.TestController
[错误]访问/api/帐户时出现问题。原因:
com.acme.TestController
[错误]com.acme.TestController
com.acme.TestController
[错误]由码头供电:// com.acme.TestController [错误]
com.acme.TestController [错误] com.acme.TestController [错误] com.acme.TestController [错误]' com.acme.TestController [错误]不等于 com.acme.TestController
…解决方案是将spec2行更改为:
addServlet(classOf[TestController], "api/*")
致:
Swagger注释导致控制器类是抽象的,不能作为声明的类型实例化。这种映射servlet的替代方法有效