I got hit by this stuff today when moving some tests from one package to 
another disabled responseAs[String] completely (earlier, it worked in some 
endpoints, but not in others). The answer is to import 
akka.http.scaladsl.unmarshalling.Unmarshaller._ in tests, which mixes in 
PredefinedFromEntityUnmarshallers, which contain an unmarshaller to string. 
Second, it is necessary to import 
akka.http.scaladsl.marshalling.Marshaller._ in the file where the route is 
defined, so that string responses are marshalled correctly (if you don't do 
it, your response bodies unmarshalled in tests will contain an extra set of 
double quotes).

On Thursday, June 11, 2015 at 1:04:28 PM UTC+3, [email protected] wrote:
>
> Hi,
>
> I am using akka-http and the corresponding testkit version 1.0-RC3. The 
> following code 
>
> Put(s"/authentication/user/oscar", oscarDataNoEmail) ~> 
> addCredentials(credentials) ~> authRoute ~> check {
>
>   responseAs[String] === "Hi"
>   response.status === StatusCodes.BadRequest
> }
>
> results in Could not unmarshal response to type 'java.lang.String' for 
> `responseAs` assertion: akka.http.scaladsl.un
> marshalling.Unmarshaller$UnsupportedContentTypeException: Unsupported 
> Content-Type, supported: application/json. Then it says 
>  Response was: HttpResponse(400 Bad 
> Request,List(Access-Control-Allow-Origin: http://localhost, Access-Con
> trol-Allow-Credentials: true, Access-Control-Allow-Headers: Authorization, 
> Content-Type, X-Requested-With),HttpEntit
> y.Strict(text/plain; charset=UTF-8,ByteString(84, 104, 101, 32, 114, 101, 
> 113, 117, 101, 115, 116, 32, 99, 111, 110,
> 116, 97, 105, 110, 115, 32, 98, 97, 100, 32, 115, 121, 110, 116, 97, 120, 
> 32, 111, 114, 32, 99, 97, 110, 110, 111, 
> 116, 32, 98, 101, 32, 102, 117, 108, 102, 105, 108, 108, 101, 100, 
> 46)),HttpProtocol(HTTP/1.1)) (AuthenticationManag
> ementSpec.scala:137). So if the response has content type text/plain, why 
> the heck does the testkit try to unmarshal it with an application/json 
> unmarshaller and how to point it in the right direction?
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to