अक्का मार्ग TestKit नहीं कर सकता unmarshall प्रतिक्रिया के रूप में स्ट्रिंग

0

सवाल

मैं निम्न परीक्षण है:

 "fail if date is wrongly formatted" in {
    val endpoint = s"/api/prof?date=wrongdate"
    Get(endpoint) ~> check {
      status shouldBe StatusCodes.BadRequest
      val resp = responseAs[String]
      resp shouldBe "could not be parsed"
    }
 }

हालांकि, परीक्षण में विफल रहता है के साथ निम्नलिखित हैं:

Could not unmarshal response to type 'java.lang.String' for `responseAs` assertion: akka.http.scaladsl.unmarshalling.Unmarshaller$UnsupportedContentTypeException: Unsupported Content-Type [Some(text/plain; charset=UTF-8)], supported: application/json

Response was: HttpResponse(400 Bad Request,List(),HttpEntity.Strict(text/plain; charset=UTF-8,106 bytes total),HttpProtocol(HTTP/1.1))

कैसे मैं प्राप्त कर सकते हैं प्रतिक्रिया के रूप में शरीर के एक स्ट्रिंग है?

akka akka-http scala scala-2.12
2021-11-23 15:46:11
1

सबसे अच्छा जवाब

1

शायद आप एक अंतर्निहित unmarshaller के लिए JSON के दायरे में है, इसलिए है कि ऊपर उठाया है के रूप में unmarshaller में अपने परीक्षण.

जोड़ने की तरह कुछ

implicit val responseBodyUnmarshaller =
  Unmarshaller.strict[HttpResponse, HttpEntity](_.entity)
    .andThen(Unmarshaller.stringUnmarshaller)

पता होना चाहिए ।

2021-11-23 17:52:23

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................