From 63e244227ca9d7824d9ec99b558d5bcedf704136 Mon Sep 17 00:00:00 2001 From: adamw Date: Mon, 10 Jul 2017 14:56:48 +0200 Subject: More tests, fixing path-related issues, uniformly escaping expressions --- .../softwaremill/sttp/UriInterpolatorTests.scala | 56 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'tests/src/test/scala/com/softwaremill') diff --git a/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala b/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala index 4a71163..d7719fd 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala @@ -8,26 +8,33 @@ class UriInterpolatorTests extends FunSuite with Matchers { val v1 = "y" val v2 = "a c" val v2queryEncoded = "a+c" - val v2hostEncoded = "a%20c" + val v2encoded = "a%20c" + val v3 = "a?=&c" + val v3encoded = "a%3F%3D%26c" + val v4 = "f/g" + val v4encoded = "f%2Fg" val secure = true val testData: List[(String, List[(URI, String)])] = List( "basic" -> List( (uri"http://example.com", "http://example.com"), - (uri"http://example.com?x=y", "http://example.com?x=y") + (uri"http://example.com/", "http://example.com/"), + (uri"http://example.com?x=y", "http://example.com?x=y"), + (uri"http://example.com/a/b/c", "http://example.com/a/b/c"), + (uri"http://example.com/a/b/c/", "http://example.com/a/b/c/"), + (uri"http://example.com/a/b/c?x=y&h=j", + "http://example.com/a/b/c?x=y&h=j") ), "scheme" -> List( (uri"http${if (secure) "s" else ""}://example.com", s"https://example.com"), (uri"${if (secure) "https" else "http"}://example.com", s"https://example.com"), - (uri"${if (secure) "https://" else "http://"}example.com", - s"https://example.com"), (uri"example.com?a=$v2", s"example.com?a=$v2queryEncoded") ), "authority" -> List( (uri"http://$v1.com", s"http://$v1.com"), - (uri"http://$v2.com", s"http://$v2hostEncoded.com"), + (uri"http://$v2.com", s"http://$v2encoded.com"), (uri"http://$None.example.com", s"http://example.com"), (uri"http://$None.$None.example.com", s"http://example.com"), (uri"http://${Some("sub")}.example.com", s"http://sub.example.com"), @@ -40,9 +47,27 @@ class UriInterpolatorTests extends FunSuite with Matchers { "authority with parameters" -> List( (uri"http://$v1.com?x=$v2", s"http://$v1.com?x=$v2queryEncoded") ), + "path" -> List( + (uri"http://example.com/$v1", s"http://example.com/$v1"), + (uri"http://example.com/$v1/", s"http://example.com/$v1/"), + (uri"http://example.com/$v2", s"http://example.com/$v2encoded"), + (uri"http://example.com/$v2/$v1", s"http://example.com/$v2encoded/$v1"), + (uri"http://example.com/$v1/p/$v4", + s"http://example.com/$v1/p/$v4encoded"), + (uri"http://example.com/a/${List(v2, "c", v4)}/b", + s"http://example.com/a/$v2encoded/c/$v4encoded/b") + ), + "path with parameters" -> List( + (uri"http://example.com/$v1?x=$v2", + s"http://example.com/$v1?x=$v2queryEncoded"), + (uri"http://example.com/$v1/$v2?x=$v2", + s"http://example.com/$v1/$v2encoded?x=$v2queryEncoded") + ), "query parameter values" -> List( (uri"http://example.com?x=$v1", s"http://example.com?x=$v1"), - (uri"http://example.com?x=$v2", s"http://example.com?x=$v2queryEncoded") + (uri"http://example.com/?x=$v1", s"http://example.com/?x=$v1"), + (uri"http://example.com?x=$v2", s"http://example.com?x=$v2queryEncoded"), + (uri"http://example.com?x=$v3", s"http://example.com?x=$v3encoded") ), "optional query parameters" -> List( (uri"http://example.com?a=$None", s"http://example.com"), @@ -52,9 +77,22 @@ class UriInterpolatorTests extends FunSuite with Matchers { (uri"http://example.com?a=${Some(v1)}&c=d", s"http://example.com?a=$v1&c=d") ), - "embed whole url" -> List( - (uri"${"http://example.com/a/b?x=y&1=2"}", - s"http://example.com/a/b?x=y&1=2") + "parameter collections" -> List( + (uri"http://example.com?${Seq("a" -> "b", v2 -> v1, v1 -> v2)}", + s"http://example.com?a=b&$v2queryEncoded=$v1&$v1=$v2queryEncoded"), + (uri"http://example.com?${Seq("a" -> "b", "a" -> "c")}", + s"http://example.com?a=b&a=c"), + (uri"http://example.com?${Map("a" -> "b")}", s"http://example.com?a=b"), + (uri"http://example.com?x=y&${Map("a" -> "b")}", + s"http://example.com?x=y&a=b"), + (uri"http://example.com?x=y&${Map("a" -> None)}", + s"http://example.com?x=y"), + (uri"http://example.com?x=y&${Map("a" -> Some("b"))}", + s"http://example.com?x=y&a=b") + ), + "everything" -> List( + (uri"${"http"}://$v1.$v2.com/$v1/$v2?$v1=$v2&$v3=$v4#$v1", + s"http://$v1.$v2encoded.com/$v1/$v2encoded?$v1=$v2queryEncoded&$v3encoded=$v4encoded#$v1") ) ) -- cgit v1.2.3