我有以下测试
"adding a nominee with empty fields " should {
"be rejected" in {
val nominee = NomineeReq("Saving", "", "***", "29-08-1984", "Friend", "***", Some("***"), "1234", "****", "Some state", Some("****"))
Post("/v1/nominees/", nominee)
.withHeaders(List(httpHeaders.Authorization(httpHeaders.OAuth2BearerToken("4abf9af4-1910-437c-8510-1c8d4222901b")))) ~> Route.seal(route) ~> check {
status should be(StatusCodes.BadRequest)
}
}
}
以下服务代码
case class NomineeReq(
val account_type: String,
val account_subtype: String,
val name: String,
val dob: String,
val relationship: String,
val address1: String,
val address2: Option[String],
val pin_code: String,
val city: String,
val state: String,
val email: Option[String]){
require(account_type.nonEmpty, "account_type")
require(account_subtype.nonEmpty, "account_subtype =")
require(name.nonEmpty, "name.")
require(relationship.nonEmpty, "relationship")
require(address1.nonEmpty, "address1")
require(pin_code.nonEmpty, "pin_code")
require(city.nonEmpty, "city")
require(state.nonEmpty, "state")
require(email.nonEmpty, "email")
}
/**some code**/
(post & entity(as[NomineeReq])) { nominee =>
complete(setNominee(user.userId, nominee))
}
当我运行它时,我收到以下错误 - “java.lang.IllegalArgumentException:要求失败:account_subtype = [info] at scala.Predef $ .require(Predef.scala:224)“
根据[doc] [1],这个
[1]:http://doc.akka.io/docs/akka/2.4.3/scala/http/routing-dsl/case-class-extraction.html“doc”这应该导致ValidationRejections,它将由默认拒绝处理程序转换为BadRequest