0

I have the following test

"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)
    }
  }
}

And the following service code 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)) }

When I run it, I get the following error - "java.lang.IllegalArgumentException: requirement failed: account_subtype = [info] at scala.Predef$.require(Predef.scala:224)"

As per [doc][1], this

[1]: http://doc.akka.io/docs/akka/2.4.3/scala/http/routing-dsl/case-class-extraction.html "doc" this should result in a ValidationRejections, which will be translated by the default rejection handler to a BadRequest

EugeneMi
  • 3,475
  • 3
  • 38
  • 57
  • The documentation is about another `as` so it's not exactly the same. But you are still right that this should work. Could you file an issue with a reproducer? – jrudolph Oct 26 '16 at 14:08
  • Btw. WDYM with 'I get the following error - "java.lang.IllegalArgumentException: requirement failed: account_subtype = [info] at scala.Predef$.require(Predef.scala:224)'? Is it logged? Or where does the exception end up? – jrudolph Oct 26 '16 at 14:08

0 Answers0