aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/softwaremill/sttp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/scala/com/softwaremill/sttp')
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/HttpURLConnectionHttpTest.scala10
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala37
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/TryHttpURLConnectionHttpTest.scala12
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/EvalScala.scala11
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala14
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala16
6 files changed, 80 insertions, 20 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/HttpURLConnectionHttpTest.scala b/core/src/test/scala/com/softwaremill/sttp/HttpURLConnectionHttpTest.scala
new file mode 100644
index 0000000..807209a
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/HttpURLConnectionHttpTest.scala
@@ -0,0 +1,10 @@
+package com.softwaremill.sttp
+
+import com.softwaremill.sttp.testing.ConvertToFuture
+import com.softwaremill.sttp.testing.HttpTest
+
+class HttpURLConnectionHttpTest extends HttpTest[Id] {
+
+ override implicit val backend: SttpBackend[Id, Nothing] = HttpURLConnectionBackend()
+ override implicit val convertToFuture: ConvertToFuture[Id] = ConvertToFuture.id
+}
diff --git a/core/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/core/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
new file mode 100644
index 0000000..4336a0c
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
@@ -0,0 +1,37 @@
+package com.softwaremill.sttp
+
+import com.softwaremill.sttp.testing.EvalScala
+import org.scalatest.{FlatSpec, Matchers}
+
+import scala.tools.reflect.ToolBoxError
+
+class IllTypedTests extends FlatSpec with Matchers {
+ "compilation" should "fail when trying to stream using the default backend" in {
+ val thrown = intercept[ToolBoxError] {
+ EvalScala("""
+ import com.softwaremill.sttp._
+
+ class MyStream[T]()
+
+ implicit val sttpBackend = HttpURLConnectionBackend()
+ sttp.get(uri"http://example.com").response(asStream[MyStream[Byte]]).send()
+ """)
+ }
+
+ thrown.getMessage should include(
+ "could not find implicit value for parameter backend: com.softwaremill.sttp.SttpBackend[R,MyStream[Byte]]"
+ )
+ }
+
+ "compilation" should "fail when trying to send a request without giving an URL" in {
+ val thrown = intercept[ToolBoxError] {
+ EvalScala("""
+ import com.softwaremill.sttp._
+ implicit val sttpBackend = HttpURLConnectionBackend()
+ sttp.send()
+ """)
+ }
+
+ thrown.getMessage should include("This is a partial request, the method & url are not specified")
+ }
+}
diff --git a/core/src/test/scala/com/softwaremill/sttp/TryHttpURLConnectionHttpTest.scala b/core/src/test/scala/com/softwaremill/sttp/TryHttpURLConnectionHttpTest.scala
new file mode 100644
index 0000000..aad1669
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/TryHttpURLConnectionHttpTest.scala
@@ -0,0 +1,12 @@
+package com.softwaremill.sttp
+
+import scala.util.Try
+
+import com.softwaremill.sttp.testing.ConvertToFuture
+import com.softwaremill.sttp.testing.HttpTest
+
+class TryHttpURLConnectionHttpTest extends HttpTest[Try] {
+
+ override implicit val backend: SttpBackend[Try, Nothing] = TryHttpURLConnectionBackend()
+ override implicit val convertToFuture: ConvertToFuture[Try] = ConvertToFuture.scalaTry
+}
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/EvalScala.scala b/core/src/test/scala/com/softwaremill/sttp/testing/EvalScala.scala
new file mode 100644
index 0000000..255755d
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/EvalScala.scala
@@ -0,0 +1,11 @@
+package com.softwaremill.sttp.testing
+
+object EvalScala {
+ import scala.tools.reflect.ToolBox
+
+ def apply(code: String): Any = {
+ val m = scala.reflect.runtime.currentMirror
+ val tb = m.mkToolBox()
+ tb.eval(tb.parse(code))
+ }
+}
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
index aa0af07..27a6eda 100644
--- a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
@@ -3,16 +3,22 @@ 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
+import com.softwaremill.sttp.testing.ConvertToFuture
+
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._
+ implicit def backend: SttpBackend[R, S]
+
+ implicit def convertToFuture: ConvertToFuture[R]
+
+ def bodyProducer(body: String): S
+
+ def bodyConsumer(stream: S): R[String]
"stream request body" in {
sttp
@@ -58,7 +64,7 @@ trait StreamingTest[R[_], S] extends AsyncFreeSpec with Matchers with BeforeAndA
}
override protected def afterAll(): Unit = {
- testStreamingBackend.backend.close()
+ 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
deleted file mode 100644
index 3ea63a3..0000000
--- a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/TestStreamingBackend.scala
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.softwaremill.sttp.testing.streaming
-
-import com.softwaremill.sttp.SttpBackend
-import com.softwaremill.sttp.testing.ConvertToFuture
-
-import scala.language.higherKinds
-
-trait TestStreamingBackend[R[_], S] {
- implicit def backend: SttpBackend[R, S]
-
- implicit def convertToFuture: ConvertToFuture[R]
-
- def bodyProducer(body: String): S
-
- def bodyConsumer(stream: S): R[String]
-}