尝试测试解析multipartFormData的播放函数
def requestBulkSiteSbcActionConfirm = Action.async(parse.multipartFormData) { request => ....
我创建的测试是
val temporartyFile = TemporaryFile("test")
val filePart = FilePart("key: String", "test.csv", None, temporartyFile)
val multipartFormData: MultipartFormData[TemporaryFile] = MultipartFormData(Map(),Seq(filePart), Seq())
val request: Request[AnyContentAsMultipartFormData] = FakeRequest().withHeaders(("Content-Type"->"multipart/form-data")).withMultipartFormDataBody(multipartFormData)
val pw = new PrintWriter(filePart.ref.file)
pw.write(s"$TestSiteId_1, ${AdLeft.id}, on\n")
pw.write(s"$TestSiteId_2, ${AdRight.id}, off\n")
pw.close()
val acc: Accumulator[ByteString, Result] = controller.requestBulkSiteSbcActionConfirm().apply(request)
哪些例外
- valid file sbc command list *** FAILED ***
[info] java.util.NoSuchElementException: None.get
[info] at scala.None$.get(Option.scala:347)
[info] at scala.None$.get(Option.scala:345)
[info] at play.api.mvc.BodyParsers$parse$$anonfun$multipartFormData$1.apply(ContentTypes.scala:657)
[info] at play.api.mvc.BodyParsers$parse$$anonfun$multipartFormData$1.apply(ContentTypes.scala:656)
[info] at play.api.mvc.BodyParser$$anon$8.apply(Action.scala:258)
[info] at play.api.mvc.BodyParser$$anon$8.apply(Action.scala:257)
[info] at play.api.mvc.Action$class.apply(Action.scala:103)
[info] at play.api.mvc.ActionBuilder$$anon$2.apply(Action.scala:455)
[info] at controllers.SbcConfigControllerTest$$anonfun$2$$anonfun$apply$mcV$sp$1.apply$mcV$sp(SbcConfigControllerTest.scala:64)
[info] at controllers.SbcConfigControllerTest$$anonfun$2$$anonfun$apply$mcV$sp$1.apply(SbcConfigControllerTest.scala:55)
答案 0 :(得分:1)
Play的某些内部部分仍然使用全局状态执行,看起来你只是命中一个:https://github.com/playframework/playframework/blob/2.5.x/framework/src/play/src/main/scala/play/api/mvc/ContentTypes.scala#L657
这应该随着游戏2.6而改变,但同时您应该在测试中启动应用程序以使其正常工作