blob: d3c7b89b4e6889f522208a37143ef82be73b8783 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package com.softwaremill.sttp
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import com.softwaremill.sttp.streaming._
import com.typesafe.scalalogging.StrictLogging
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
import scala.language.higherKinds
class StreamingTests
extends FlatSpec
with Matchers
with BeforeAndAfterAll
with StrictLogging
with TestHttpServer
with ForceWrapped {
override val serverRoutes: Route =
path("echo") {
post {
parameterMap { _ =>
entity(as[String]) { body: String =>
complete(body)
}
}
}
}
override def port = 51824
val body = "streaming test"
var closeHandlers: List[() => Unit] = Nil
runTests("Akka Http", new AkkaStreamingTests(actorSystem))
runTests("Monix Async Http Client", new MonixAHCStreamingTests)
runTests("Monix OkHttp", new MonixOKHStreamingTests)
runTests("fs2 Async Http Client", new Fs2StreamingTests)
def runTests[R[_], S](
name: String,
testStreamingHandler: TestStreamingHandler[R, S]): Unit = {
import testStreamingHandler._
closeHandlers = handler.close _ :: closeHandlers
name should "stream request body" in {
val response = sttp
.post(uri"$endpoint/echo")
.streamBody(bodyProducer(body))
.send()
.force()
response.body shouldBe body
}
it should "receive a stream" in {
val response = sttp
.post(uri"$endpoint/echo")
.body(body)
.response(asStream[S])
.send()
.force()
bodyConsumer(response.body).force() shouldBe body
}
it should "receive a stream from an https site" in {
val response = sttp
// of course, you should never rely on the internet being available
// in tests, but that's so much easier than setting up an https
// testing server
.get(uri"https://softwaremill.com")
.response(asStream[S])
.send()
.force()
bodyConsumer(response.body).force() should include("</div>")
}
}
override protected def afterAll(): Unit = {
closeHandlers.foreach(_())
super.afterAll()
}
}
|