diff options
author | Sam Guymer <sam@guymer.me> | 2018-05-17 20:11:22 +1000 |
---|---|---|
committer | Sam Guymer <sam@guymer.me> | 2018-05-19 00:37:52 +1000 |
commit | 92e10991df0d168d1972d4618fcc7e02e2e0a0fa (patch) | |
tree | 14e0d112fd47856a8c87ad1782d51a928b01bbf6 /akka-http-backend | |
parent | 588395d018c258eb74f60ad95bad706698bdf915 (diff) | |
download | sttp-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 'akka-http-backend')
2 files changed, 52 insertions, 0 deletions
diff --git a/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpClientHttpTest.scala b/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpClientHttpTest.scala new file mode 100644 index 0000000..fe72794 --- /dev/null +++ b/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpClientHttpTest.scala @@ -0,0 +1,12 @@ +package com.softwaremill.sttp.akkahttp + +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} + +import scala.concurrent.Future + +class AkkaHttpClientHttpTest extends HttpTest[Future] { + + override implicit val backend: SttpBackend[Future, Nothing] = AkkaHttpBackend() + override implicit val convertToFuture: ConvertToFuture[Future] = ConvertToFuture.future +} diff --git a/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpStreamingTests.scala b/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpStreamingTests.scala new file mode 100644 index 0000000..e8ab9d7 --- /dev/null +++ b/akka-http-backend/src/test/scala/com/softwaremill/sttp/akkahttp/AkkaHttpStreamingTests.scala @@ -0,0 +1,40 @@ +package com.softwaremill.sttp.akkahttp + +import akka.NotUsed +import akka.actor.ActorSystem +import akka.stream.{ActorMaterializer, Materializer} +import akka.stream.scaladsl.Source +import akka.util.ByteString +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.testing.ConvertToFuture +import com.softwaremill.sttp.testing.streaming.{StreamingTest, TestStreamingBackend} + +import scala.concurrent.Future + +class AkkaHttpStreamingTest extends StreamingTest[Future, Source[ByteString, Any]] { + + private implicit val actorSystem: ActorSystem = ActorSystem("sttp-test") + private implicit val materializer: ActorMaterializer = ActorMaterializer() + + override val testStreamingBackend: TestStreamingBackend[Future, Source[ByteString, Any]] = + new AkkaHttpTestStreamingBackend(actorSystem) +} + +class AkkaHttpTestStreamingBackend( + actorSystem: ActorSystem +)(implicit materializer: Materializer) + extends TestStreamingBackend[Future, Source[ByteString, Any]] { + + override implicit val backend: SttpBackend[Future, Source[ByteString, Any]] = + AkkaHttpBackend.usingActorSystem(actorSystem) + + override implicit val convertToFuture: ConvertToFuture[Future] = + ConvertToFuture.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(_ + _) + +} |