I'm trying to make a test in akka with Scala. I need to test if some image is ".jpeg". I my function, I've to see the ContentType -> MediaType. And in the function it's not a problem 'cause I get the image from the Computer, but to test I've to create a "Mock up".
I was trying first with ContentTypes:
val httpResponse = HttpEntity(ContentTypes.`text/plain(UTF-8)`,"image")
but the problem is, that it should be image/jpeg
and not text/...
but there's not that option.
Then, I was trying:
val httpResponse = HttpEntity(MediaTypes.`image/jpeg`, )
And that's pretty nice, but I don't know what to write after the comma. I don't even know, if it's so.
I was looking here but I didn't find an answer.
And I saw another posts, like this but I didn't help me.
I've found an answer for my question.
with:
val httpResponse = HttpEntity(MediaTypes.`image/jpeg`, )
after the comma should come an Array Byte.
In my case, it works so:
val httpResponse = HttpEntity(MediaTypes.`image/gif`, new Array[Byte](3))
'Cause for me it doesn't matter wich image I've. But if for you is important the image, than, you can create an Array[Byte] of your image, and that's it.
And the most interesting thing is that httpResponse.contentType
works and inside contentType
is a mediaType
Hope it can help someone.