aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/softwaremill/sttp/testing/streaming
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/scala/com/softwaremill/sttp/testing/streaming')
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/ConvertToFuture.scala26
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala65
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala1
3 files changed, 66 insertions, 26 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/ConvertToFuture.scala b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/ConvertToFuture.scala
deleted file mode 100644
index 9438890..0000000
--- a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/ConvertToFuture.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.softwaremill.sttp.testing.streaming
-
-import com.softwaremill.sttp.Id
-import scala.concurrent.Future
-import scala.language.higherKinds
-import scala.util.Try
-
-trait ConvertToFuture[R[_]] {
- def toFuture[T](value: R[T]): Future[T]
-}
-
-object ConvertToFuture {
-
- val id: ConvertToFuture[Id] = new ConvertToFuture[Id] {
- override def toFuture[T](value: Id[T]): Future[T] =
- Future.successful(value)
- }
-
- val future: ConvertToFuture[Future] = new ConvertToFuture[Future] {
- override def toFuture[T](value: Future[T]): Future[T] = value
- }
-
- val scalaTry: ConvertToFuture[Try] = new ConvertToFuture[Try] {
- override def toFuture[T](value: Try[T]): Future[T] = Future.fromTry(value)
- }
-}
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
new file mode 100644
index 0000000..aa0af07
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
@@ -0,0 +1,65 @@
+package com.softwaremill.sttp.testing.streaming
+
+import com.softwaremill.sttp._
+import com.softwaremill.sttp.testing.ForceWrapped
+import org.scalatest.{AsyncFreeSpec, BeforeAndAfterAll, Matchers}
+
+import scala.language.higherKinds
+
+trait StreamingTest[R[_], S] extends AsyncFreeSpec with Matchers with BeforeAndAfterAll with ForceWrapped {
+
+ private val endpoint = "localhost:51823"
+ private val body = "streaming test"
+
+ val testStreamingBackend: TestStreamingBackend[R, S]
+ import testStreamingBackend._
+
+ "stream request body" in {
+ sttp
+ .post(uri"$endpoint/streaming/echo")
+ .streamBody(bodyProducer(body))
+ .send()
+ .toFuture()
+ .map { response =>
+ response.unsafeBody shouldBe body
+ }
+ }
+
+ "receive a stream" in {
+ sttp
+ .post(uri"$endpoint/streaming/echo")
+ .body(body)
+ .response(asStream[S])
+ .send()
+ .toFuture()
+ .flatMap { response =>
+ bodyConsumer(response.unsafeBody).toFuture()
+ }
+ .map { responseBody =>
+ responseBody shouldBe body
+ }
+ }
+
+ "receive a stream from an https site" in {
+ 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()
+ .toFuture()
+ .flatMap { response =>
+ bodyConsumer(response.unsafeBody).toFuture()
+ }
+ .map { responseBody =>
+ responseBody should include("</div>")
+ }
+ }
+
+ override protected def afterAll(): Unit = {
+ testStreamingBackend.backend.close()
+ super.afterAll()
+ }
+
+}
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala
index 266c402..3ea63a3 100644
--- a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala
@@ -1,6 +1,7 @@
package com.softwaremill.sttp.testing.streaming
import com.softwaremill.sttp.SttpBackend
+import com.softwaremill.sttp.testing.ConvertToFuture
import scala.language.higherKinds