aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/scala/com/softwaremill/sttp/streaming/AkkaHttpStreamingTests.scala
blob: 25a8d6e43908a2bc73e18d426a62f6be0bd86bec (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
29
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.AkkaHttpHandler
import com.softwaremill.sttp.{ForceWrappedValue, SttpHandler}

import scala.concurrent.Future

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

  override implicit val handler: SttpHandler[Future, Source[ByteString, Any]] =
    AkkaHttpHandler.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(_ + _)

}