aboutsummaryrefslogtreecommitdiff
path: root/implementations/monix
diff options
context:
space:
mode:
authorSam Guymer <sam@guymer.me>2018-05-17 20:11:22 +1000
committerSam Guymer <sam@guymer.me>2018-05-19 00:37:52 +1000
commit92e10991df0d168d1972d4618fcc7e02e2e0a0fa (patch)
tree14e0d112fd47856a8c87ad1782d51a928b01bbf6 /implementations/monix
parent588395d018c258eb74f60ad95bad706698bdf915 (diff)
downloadsttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.gz
sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.bz2
sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.zip
Move backend tests into their projects
Instead of having a single project which tests all backends, each backend now implements a http test trait along with a streaming test trait if it supports streaming. The test http server has been moved into its own project and is started automatically before running a backends test. This allows each backend to be tested without the possibility of dependency eviction from another backend or the test http server. It also has the side effect of parallelizing the tests providing a speed up when run with multiple cores.
Diffstat (limited to 'implementations/monix')
-rw-r--r--implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/MonixTestStreamingBackend.scala22
-rw-r--r--implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/package.scala2
2 files changed, 15 insertions, 9 deletions
diff --git a/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/MonixTestStreamingBackend.scala b/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/MonixTestStreamingBackend.scala
index 3f84ec3..f1b262b 100644
--- a/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/MonixTestStreamingBackend.scala
+++ b/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/MonixTestStreamingBackend.scala
@@ -1,21 +1,27 @@
package com.softwaremill.sttp.impl.monix
-import java.nio.ByteBuffer
-
-import com.softwaremill.sttp.testing.streaming.{ConvertToFuture, TestStreamingBackend}
+import com.softwaremill.sttp.testing.ConvertToFuture
+import com.softwaremill.sttp.testing.streaming.TestStreamingBackend
import monix.eval.Task
import monix.reactive.Observable
-trait MonixTestStreamingBackend extends TestStreamingBackend[Task, Observable[ByteBuffer]] {
+trait MonixTestStreamingBackend[T] extends TestStreamingBackend[Task, Observable[T]] {
+
+ def toByteArray(v: T): Array[Byte]
+ def fromByteArray(v: Array[Byte]): T
override implicit def convertToFuture: ConvertToFuture[Task] = convertMonixTaskToFuture
- override def bodyProducer(body: String): Observable[ByteBuffer] =
- Observable.fromIterable(body.getBytes("utf-8").map(b => ByteBuffer.wrap(Array(b))))
+ override def bodyProducer(body: String): Observable[T] =
+ Observable
+ .fromIterable(
+ body.getBytes("utf-8")
+ )
+ .map(v => fromByteArray(Array(v)))
- override def bodyConsumer(stream: Observable[ByteBuffer]): Task[String] =
+ override def bodyConsumer(stream: Observable[T]): Task[String] =
stream
- .flatMap(bb => Observable.fromIterable(bb.array()))
+ .flatMap(v => Observable.fromIterable(toByteArray(v)))
.toListL
.map(bs => new String(bs.toArray, "utf8"))
diff --git a/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/package.scala b/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/package.scala
index f77aa93..02fef8b 100644
--- a/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/package.scala
+++ b/implementations/monix/src/test/scala/com/softwaremill/sttp/impl/monix/package.scala
@@ -3,7 +3,7 @@ package com.softwaremill.sttp.impl
import scala.concurrent.Future
import _root_.monix.eval.Task
-import com.softwaremill.sttp.testing.streaming.ConvertToFuture
+import com.softwaremill.sttp.testing.ConvertToFuture
package object monix {