diff --git a/tests/src/test/scala/org/mdedetrich/pekko/http/JsonSupportSpec.scala b/tests/src/test/scala/org/mdedetrich/pekko/http/JsonSupportSpec.scala index bbdb783..f89ad25 100644 --- a/tests/src/test/scala/org/mdedetrich/pekko/http/JsonSupportSpec.scala +++ b/tests/src/test/scala/org/mdedetrich/pekko/http/JsonSupportSpec.scala @@ -21,8 +21,9 @@ import org.apache.pekko import pekko.actor.ActorSystem import pekko.http.scaladsl.marshalling.Marshal import pekko.http.scaladsl.model.HttpCharsets.`UTF-8` +import pekko.http.scaladsl.model.HttpEntity.ChunkStreamPart import pekko.http.scaladsl.model.MediaTypes.`application/json` -import pekko.http.scaladsl.model.{HttpEntity, RequestEntity, UniversalEntity} +import pekko.http.scaladsl.model.{HttpEntity, RequestEntity} import pekko.http.scaladsl.unmarshalling.Unmarshal import pekko.stream.scaladsl.{Keep, Sink, Source} import pekko.util.ByteString @@ -149,6 +150,15 @@ class JsonSupportSpec } } + "A valid, lazily streamed chunked json entity" should { + val lazyChunkedEntity = mkEntity(goodJson, chunked = true) + "produce the proper type" in { + Unmarshal(lazyChunkedEntity).to[Foo].map { + _ shouldBe foo + } + } + } + "A complete, lazily streamed json entity with superfluous content" should { val entity = mkEntity(goodJson + incompleteJson) "produce the proper type" in { @@ -307,12 +317,17 @@ class JsonSupportSpec } } - def mkEntity(s: String, strict: Boolean = false): UniversalEntity = + def mkEntity(s: String, strict: Boolean = false, chunked: Boolean = false): HttpEntity = if (strict) { HttpEntity(`application/json`, s) } else { - val source = Source.fromIterator(() => s.grouped(8).map(ByteString(_))) - HttpEntity(`application/json`, s.length.toLong, source) + if (chunked) { + val source = Source.fromIterator(() => s.grouped(1).map(bs => ChunkStreamPart(ByteString(bs)))) + HttpEntity.Chunked(`application/json`, source) + } else { + val source = Source.fromIterator(() => s.grouped(8).map(ByteString(_))) + HttpEntity(`application/json`, s.length.toLong, source) + } } override def afterAll(): Unit = {