必須パラメーター adId を必要とする scalatest を使用して POST スプレー ルートをテストしようとしています。そしてそれを機能させることはできません。私のコードは次のとおりです
import akka.actor._
import akka.event.LoggingReceive
import akka.testkit.{TestProbe}
import com.ss.rg.service.ad.AdImporterServiceActor.{GetImportStatus, StatusOfImport}
import org.scalatest.{MustMatchers, WordSpecLike}
import spray.http.{StatusCodes, MediaTypes}
import spray.testkit.ScalatestRouteTest
class AdServiceApiTest extends WordSpecLike with MustMatchers with ScalatestRouteTest{
"AdService REST api " must{
"POST for import witout mandatory parameters should fail with " in{
val p = TestProbe()
val addressServiceMock = system.actorOf(Props(classOf[AdServiceActorMock],p.ref))
Post("/service/ad/import") ~> new AdServiceApi(addressServiceMock).route ~>check{
handled must be(false)
status must be (StatusCodes.BadRequest)
}
}
}
テストは失敗しますが、別の理由で
Request was rejected with List(MissingQueryParamRejection(adId))
org.scalatest.exceptions.TestFailedException: Request was rejected with List(MissingQueryParamRejection(adId))
at spray.testkit.ScalatestInterface$class.failTest(ScalatestInterface.scala:25)
at com.ss.rg.api.ad.AdServiceApiTest.failTest(AdServiceApiTest.scala:19)
at spray.testkit.RouteResultComponent$RouteResult$$anonfun$response$1$$anonfun$apply$1.apply(RouteResultComponent.scala:97)
at spray.testkit.RouteResultComponent$RouteResult$$anonfun$response$1$$anonfun$apply$1.apply(RouteResultComponent.scala:95)
at scala.Option.foreach(Option.scala:236)
at spray.testkit.RouteResultComponent$RouteResult$$anonfun$response$1.apply(RouteResultComponent.scala:94)
...
ステータスすらチェックされていないようです。私には完全にクリアされていない2番目のことは、実際にspray-testkitでadIdパラメータを設定する方法ですか? 1 つの方法は、ヘッダーを設定することですが、より良い方法が存在することに驚かないでしょう。
スプレーテストキットの経験が豊富な人がコメントできますか?
どうも