Getting .UnsupportedOperationException: NoMaterializer does not provide an ExecutionContext Error

心已入冬 提交于 2020-01-22 02:26:30

问题


When I am trying to run the following test case

class QuestionsControllerUnitSpec extends PlaySpec with BeforeAndAfterAll with BeforeAndAfterEach with OneAppPerSuiteWithComponents{

{
...
  "newQuestion" should {
    "should return error if the size of the body in the request is more than the maximum allowed size" in {
      val testEnv = new QuestionsControllerSpecTestEnv(components=components)
      val body =
        s"""
           |{
           | "practice-question":{
           | "description": "some description",
           | "hints": ["hint1","hint2"],
           | "image": ["image1 data","image2 data","image3 data"],
           | "success-test": "success test",
           | "fail-test": "fail test",
           | "tags": ["${testEnv.tag}","${testEnv.tag}"],
           | "title":"some title",
           | "answer": "some answer",
           | "references":["ref1","ref2"]
           | }
           |}
        """.stripMargin

      val sizeConfig = Map("maxAllowedBodySize"-> 10)
      val maxBodySizeConfig = Map("codingJedi" -> sizeConfig )
      val newConfiguration = Configuration.from(maxBodySizeConfig)
      val questionControllerTestEnv = new QuestionsControllerSpecTestEnv(Some(newConfiguration),components)

      val jsonBody = Json.parse(body)

      val request = new FakeRequest(FakeRequest("POST","ws/questions/new-question")).withAuthenticator(testEnv.testEnv.loginInfo)(testEnv.testEnv.fakeEnv).withBody(AnyContentAsJson(jsonBody))
      val response = questionControllerTestEnv.questionsController.newQuestion(request)
      val responseBody = contentAsJson(response)(Timeout(Duration(5000,"millis")),testEnv.testEnv.mat)
      println(s"received response body ${responseBody}")
      val result = (responseBody \ "result").get.as[String]
      val additionalInfo = (responseBody \ "additional-info").get.as[String]
      result mustBe "error"
      additionalInfo mustBe components.messagesApi("error.entityTooLarge")(components.langs.availables(0))
    }
  }

...
}

I am getting error java.lang.UnsupportedOperationException: NoMaterializer does not provide an ExecutionContext. What does it mean and how can I solve it?

The test case is suppose to reject an incoming request with 413 response

If I don't pass the materializer to contentAsJson, I get error Error:(1480, 39) could not find implicit value for parameter mat: akka.stream.Materializer val responseBody = contentAsJson(response)

来源:https://stackoverflow.com/questions/57577155/getting-unsupportedoperationexception-nomaterializer-does-not-provide-an-execu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!