aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-19 14:45:11 +0200
committeradamw <adam@warski.org>2017-07-19 14:45:11 +0200
commit5aaac06c2d5ea122470ee7b27277ac0747e767d1 (patch)
treeb63519364f12c952cf1b9100ae8706e2877a0324 /tests
parent4cde9e296663eecd866e0e4e38a955e0c6c05f62 (diff)
downloadsttp-5aaac06c2d5ea122470ee7b27277ac0747e767d1.tar.gz
sttp-5aaac06c2d5ea122470ee7b27277ac0747e767d1.tar.bz2
sttp-5aaac06c2d5ea122470ee7b27277ac0747e767d1.zip
How the response should be handled is now part of the request definition
Diffstat (limited to 'tests')
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala44
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala8
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala8
3 files changed, 34 insertions, 26 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
index f5a1796..621968b 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
@@ -121,6 +121,8 @@ class BasicTests
val testBodyBytes = testBody.getBytes("UTF-8")
val expectedPostEchoResponse = "POST /echo this is the body"
+ val sttpIgnore = com.softwaremill.sttp.ignore
+
parseResponseTests()
parameterTests()
bodyTests()
@@ -131,13 +133,13 @@ class BasicTests
def parseResponseTests(): Unit = {
name should "parse response as string" in {
- val response = postEcho.body(testBody).send(responseAsString).force()
+ val response = postEcho.body(testBody).send().force()
response.body should be(expectedPostEchoResponse)
}
name should "parse response as a byte array" in {
val response =
- postEcho.body(testBody).send(responseAsByteArray).force()
+ postEcho.body(testBody).response(asByteArray).send().force()
val fc = new String(response.body, "UTF-8")
fc should be(expectedPostEchoResponse)
}
@@ -147,7 +149,8 @@ class BasicTests
val response = sttp
.post(uri"$endpoint/echo/form_params/as_params")
.body(params: _*)
- .send(responseAsParams)
+ .response(asParams)
+ .send()
.force()
response.body.toList should be(params)
}
@@ -157,7 +160,7 @@ class BasicTests
name should "make a get request with parameters" in {
val response = sttp
.get(uri"$endpoint/echo?p2=v2&p1=v1")
- .send(responseAsString)
+ .send()
.force()
response.body should be("GET /echo p1=v1 p2=v2")
@@ -166,20 +169,20 @@ class BasicTests
def bodyTests(): Unit = {
name should "post a string" in {
- val response = postEcho.body(testBody).send(responseAsString).force()
+ val response = postEcho.body(testBody).send().force()
response.body should be(expectedPostEchoResponse)
}
name should "post a byte array" in {
val response =
- postEcho.body(testBodyBytes).send(responseAsString).force()
+ postEcho.body(testBodyBytes).send().force()
response.body should be(expectedPostEchoResponse)
}
name should "post an input stream" in {
val response = postEcho
.body(new ByteArrayInputStream(testBodyBytes))
- .send(responseAsString)
+ .send()
.force()
response.body should be(expectedPostEchoResponse)
}
@@ -187,7 +190,7 @@ class BasicTests
name should "post a byte buffer" in {
val response = postEcho
.body(ByteBuffer.wrap(testBodyBytes))
- .send(responseAsString)
+ .send()
.force()
response.body should be(expectedPostEchoResponse)
}
@@ -195,7 +198,7 @@ class BasicTests
name should "post a file" in {
val f = File.newTemporaryFile().write(testBody)
try {
- val response = postEcho.body(f.toJava).send(responseAsString).force()
+ val response = postEcho.body(f.toJava).send().force()
response.body should be(expectedPostEchoResponse)
} finally f.delete()
}
@@ -204,7 +207,7 @@ class BasicTests
val f = File.newTemporaryFile().write(testBody)
try {
val response =
- postEcho.body(f.toJava.toPath).send(responseAsString).force()
+ postEcho.body(f.toJava.toPath).send().force()
response.body should be(expectedPostEchoResponse)
} finally f.delete()
}
@@ -213,7 +216,7 @@ class BasicTests
val response = sttp
.post(uri"$endpoint/echo/form_params/as_string")
.body("a" -> "b", "c" -> "d")
- .send(responseAsString)
+ .send()
.force()
response.body should be("a=b c=d")
}
@@ -222,7 +225,7 @@ class BasicTests
val response = sttp
.post(uri"$endpoint/echo/form_params/as_string")
.body("a=" -> "/b", "c:" -> "/d")
- .send(responseAsString)
+ .send()
.force()
response.body should be("a==/b c:=/d")
}
@@ -232,7 +235,7 @@ class BasicTests
val getHeaders = sttp.get(uri"$endpoint/set_headers")
name should "read response headers" in {
- val response = getHeaders.send(ignoreResponse).force()
+ val response = getHeaders.response(sttpIgnore).send().force()
response.headers should have length (6)
response.headers("Cache-Control").toSet should be(
Set("no-cache", "max-age=1000"))
@@ -248,7 +251,7 @@ class BasicTests
val getHeaders = sttp.post(uri"$endpoint/set_headers")
name should "return 405 when method not allowed" in {
- val response = getHeaders.send(ignoreResponse).force()
+ val response = getHeaders.response(sttpIgnore).send().force()
response.code should be(405)
response.isClientError should be(true)
}
@@ -257,7 +260,11 @@ class BasicTests
def cookiesTests(): Unit = {
name should "read response cookies" in {
val response =
- sttp.get(uri"$endpoint/set_cookies").send(ignoreResponse).force()
+ sttp
+ .get(uri"$endpoint/set_cookies")
+ .response(sttpIgnore)
+ .send()
+ .force()
response.cookies should have length (3)
response.cookies.toSet should be(
Set(
@@ -274,7 +281,8 @@ class BasicTests
name should "read response cookies with the expires attribute" in {
val response = sttp
.get(uri"$endpoint/set_cookies/with_expires")
- .send(ignoreResponse)
+ .response(sttpIgnore)
+ .send()
.force()
response.cookies should have length (1)
val c = response.cookies(0)
@@ -296,7 +304,7 @@ class BasicTests
name should "return a 401 when authorization fails" in {
val req = secureBasic
- val resp = req.send(responseAsString).force()
+ val resp = req.send().force()
resp.code should be(401)
resp.header("WWW-Authenticate") should be(
Some("""Basic realm="test realm",charset=UTF-8"""))
@@ -304,7 +312,7 @@ class BasicTests
name should "perform basic authorization" in {
val req = secureBasic.auth.basic("adam", "1234")
- val resp = req.send(responseAsString).force()
+ val resp = req.send().force()
resp.code should be(200)
resp.body should be("Hello, adam!")
}
diff --git a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
index caf6632..0d0c012 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala
@@ -8,16 +8,16 @@ class IllTypedTests extends FlatSpec with Matchers {
import akka.stream.scaladsl.Source
import akka.util.ByteString
import java.net.URI
- implicit val sttpHandler = HttpConnectionSttpHandler
- sttp.get(new URI("http://example.com")).send(responseAsStream[Source[ByteString, Any]])
+ implicit val sttpHandler = HttpURLConnectionSttpHandler
+ sttp.get(new URI("http://example.com")).response(asStream[Source[ByteString, Any]]).send()
""" shouldNot typeCheck
}
"compilation" should "fail when trying to send a request without giving an URL" in {
"""
import java.net.URI
- implicit val sttpHandler = HttpConnectionSttpHandler
- sttp.send(responseAsString)
+ implicit val sttpHandler = HttpURLConnectionSttpHandler
+ sttp.send()
""" shouldNot typeCheck
}
}
diff --git a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala
index ab77753..95a8bed 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/StreamingTests.scala
@@ -8,7 +8,6 @@ import com.softwaremill.sttp.akkahttp.AkkaHttpSttpHandler
import com.typesafe.scalalogging.StrictLogging
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
-import com.softwaremill.sttp.akkahttp._
class StreamingTests
extends FlatSpec
@@ -42,8 +41,8 @@ class StreamingTests
"Akka HTTP" should "stream request body" in {
val response = sttp
.post(uri"$endpoint/echo")
- .body(Source.single(ByteString(body)))
- .send(responseAsString)
+ .streamBody(Source.single(ByteString(body)))
+ .send()
.futureValue
response.body should be(body)
@@ -53,7 +52,8 @@ class StreamingTests
val response = sttp
.post(uri"$endpoint/echo")
.body(body)
- .send(responseAsStream[Source[ByteString, Any]])
+ .response(asStream[Source[ByteString, Any]])
+ .send()
.futureValue
val responseBody = response.body.runReduce(_ ++ _).futureValue.utf8String