diff options
author | adamw <adam@warski.org> | 2017-07-15 19:48:53 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-15 19:48:53 +0200 |
commit | c5e966faed086bc07463246df4be37690431585e (patch) | |
tree | f6aae64919238e815f0d6eb79513dd705be81cfb /tests/src/test/scala/com/softwaremill | |
parent | b053c91551b924100fa8261e4f405bc40ce53147 (diff) | |
download | sttp-c5e966faed086bc07463246df4be37690431585e.tar.gz sttp-c5e966faed086bc07463246df4be37690431585e.tar.bz2 sttp-c5e966faed086bc07463246df4be37690431585e.zip |
Form data
Diffstat (limited to 'tests/src/test/scala/com/softwaremill')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala index 1ad5fc0..8cfaec8 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala @@ -1,6 +1,7 @@ package com.softwaremill.sttp import java.io.ByteArrayInputStream +import java.nio.ByteBuffer import java.time.{ZoneId, ZonedDateTime} import akka.stream.ActorMaterializer @@ -31,8 +32,12 @@ class BasicTests m.toList.sortBy(_._1).map(p => s"${p._1}=${p._2}").mkString(" ") private val serverRoutes = - path("echo") { - get { + pathPrefix("echo") { + path("form_params") { + formFieldMap { params => + complete(paramsToString(params)) + } + } ~ get { parameterMap { params => complete( List("GET", "/echo", paramsToString(params)) @@ -188,7 +193,12 @@ class BasicTests fc should be(expectedPostEchoResponse) } - name should "post a byte buffer" in {} + name should "post a byte buffer" in { + val response = + postEcho.body(ByteBuffer.wrap(testBodyBytes)).send(responseAsString) + val fc = forceResponse.force(response).body + fc should be(expectedPostEchoResponse) + } name should "post a file" in { val f = File.newTemporaryFile().write(testBody) @@ -207,6 +217,24 @@ class BasicTests fc should be(expectedPostEchoResponse) } finally f.delete() } + + name should "post form data" in { + val response = sttp + .post(uri"$endpoint/echo/form_params") + .body("a" -> "b", "c" -> "d") + .send(responseAsString) + val fc = forceResponse.force(response).body + fc should be("a=b c=d") + } + + name should "post form data with special characters" in { + val response = sttp + .post(uri"$endpoint/echo/form_params") + .body("a=" -> "/b", "c:" -> "/d") + .send(responseAsString) + val fc = forceResponse.force(response).body + fc should be("a==/b c:=/d") + } } def headerTests(): Unit = { |