aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala
blob: d8fbb8217ee4d2f8c41c971a9860fc565fbd06f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.softwaremill.sttp.streaming

import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import com.softwaremill.sttp.akkahttp.AkkaHttpBackend
import com.softwaremill.sttp.{ForceWrappedValue, SttpBackend}

import scala.concurrent.Future

class AkkaHttpStreamingTests(actorSystem: ActorSystem)(implicit materializer: Materializer)
    extends TestStreamingBackend[Future, Source[ByteString, Any]] {

  override implicit val backend: SttpBackend[Future, Source[ByteString, Any]] =
    AkkaHttpBackend.usingActorSystem(actorSystem)

  override implicit val forceResponse: ForceWrappedValue[Future] =
    ForceWrappedValue.future

  override def bodyProducer(body: String): Source[ByteString, NotUsed] =
    Source.single(ByteString(body))

  override def bodyConsumer(stream: Source[ByteString, Any]): Future[String] =
    stream.map(_.utf8String).runReduce(_ + _)

}