diff options
author | Omar Alejandro Mainegra Sarduy <omainegra@gmail.com> | 2017-08-04 18:14:51 -0400 |
---|---|---|
committer | Omar Alejandro Mainegra Sarduy <omainegra@gmail.com> | 2017-08-04 19:21:29 -0400 |
commit | 436ba7dc5afbecbe529b68835a8a4473bd92e56b (patch) | |
tree | 760fa6470a6baedfd704564ec81a0491cb264683 /tests/src | |
parent | b217185d8bd4297aef1e91b34f295620a1832e0b (diff) | |
download | sttp-436ba7dc5afbecbe529b68835a8a4473bd92e56b.tar.gz sttp-436ba7dc5afbecbe529b68835a8a4473bd92e56b.tar.bz2 sttp-436ba7dc5afbecbe529b68835a8a4473bd92e56b.zip |
Include unit tests
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 7 | ||||
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala | 74 |
2 files changed, 74 insertions, 7 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 36c82ef..6d383f5 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -20,6 +20,7 @@ import com.softwaremill.sttp.asynchttpclient.cats.CatsAsyncHttpClientHandler import com.softwaremill.sttp.asynchttpclient.future.FutureAsyncHttpClientHandler import com.softwaremill.sttp.asynchttpclient.monix.MonixAsyncHttpClientHandler import com.softwaremill.sttp.asynchttpclient.scalaz.ScalazAsyncHttpClientHandler +import com.softwaremill.sttp.okhttp.monix.OkHttpMonixClientHandler import com.softwaremill.sttp.okhttp.{ OkHttpFutureClientHandler, OkHttpSyncClientHandler @@ -136,8 +137,10 @@ class BasicTests ForceWrappedValue.catsIo) runTests("OkHttpSyncClientHandler")(OkHttpSyncClientHandler(), ForceWrappedValue.id) - runTests("OkHttpSyncClientHandler - Future")(OkHttpFutureClientHandler(), - ForceWrappedValue.future) + runTests("OkHttpAsyncClientHandler - Future")(OkHttpFutureClientHandler(), + ForceWrappedValue.future) + runTests("OkHttpAsyncClientHandler - Monix")(OkHttpMonixClientHandler(), + ForceWrappedValue.monixTask) def runTests[R[_]](name: String)( implicit handler: SttpHandler[R, Nothing], diff --git a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala index 5f04126..5820153 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala @@ -8,6 +8,7 @@ import akka.stream.scaladsl.Source import akka.util.ByteString import com.softwaremill.sttp.akkahttp.AkkaHttpSttpHandler import com.softwaremill.sttp.asynchttpclient.monix.MonixAsyncHttpClientHandler +import com.softwaremill.sttp.okhttp.monix.OkHttpMonixClientHandler import com.typesafe.scalalogging.StrictLogging import monix.reactive.Observable import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers} @@ -36,10 +37,12 @@ class StreamingTests override def port = 51824 val akkaHandler = AkkaHttpSttpHandler.usingActorSystem(actorSystem) - val monixHandler = MonixAsyncHttpClientHandler() + val monixAsyncHttpClient = MonixAsyncHttpClientHandler() + val monixOkHttpClient = OkHttpMonixClientHandler() akkaStreamingTests() - monixStreamingTests() + monixAsyncHttpClientStreamingTests() + monixOkHttpClientStreamingTests() val body = "streaming test" @@ -70,8 +73,8 @@ class StreamingTests } } - def monixStreamingTests(): Unit = { - implicit val handler = monixHandler + def monixOkHttpClientStreamingTests(): Unit = { + implicit val handler = monixOkHttpClient import monix.execution.Scheduler.Implicits.global val body = "streaming test" @@ -131,9 +134,70 @@ class StreamingTests } } + def monixAsyncHttpClientStreamingTests(): Unit = { + implicit val handler = monixAsyncHttpClient + import monix.execution.Scheduler.Implicits.global + + val body = "streaming test" + + "Monix OkHttp Client" should "stream request body" in { + val source = Observable.fromIterable( + body.getBytes("utf-8").map(b => ByteBuffer.wrap(Array(b)))) + + val response = sttp + .post(uri"$endpoint/echo") + .streamBody(source) + .send() + .runAsync + .futureValue + + response.body should be(body) + } + + it should "receive a stream" in { + val response = sttp + .post(uri"$endpoint/echo") + .body(body) + .response(asStream[Observable[ByteBuffer]]) + .send() + .runAsync + .futureValue + + val bytes = response.body + .flatMap(bb => Observable.fromIterable(bb.array())) + .toListL + .runAsync + .futureValue + .toArray + + new String(bytes, "utf-8") should be(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[Observable[ByteBuffer]]) + .send() + .runAsync + .futureValue + + val bytes = response.body + .flatMap(bb => Observable.fromIterable(bb.array())) + .toListL + .runAsync + .futureValue + .toArray + + new String(bytes, "utf-8") should include("</div>") + } + } + override protected def afterAll(): Unit = { akkaHandler.close() - monixHandler.close() + monixAsyncHttpClient.close() super.afterAll() } } |