blob: c6132c9d73716d37a8930a4249a3e2c115211434 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package com.softwaremill.sttp
import org.scalatest.{FlatSpec, Matchers}
class RequestTests extends FlatSpec with Matchers {
"request cookies" should "be set from a name-value pair" in {
sttp
.cookie("k", "v")
.headers
.find(_._1 == CookieHeader)
.map(_._2) should be(Some("k=v"))
}
it should "be set from multiple name-value pairs" in {
sttp
.cookies("k1" -> "v1", "k2" -> "v2")
.headers
.find(_._1 == CookieHeader)
.map(_._2) should be(Some("k1=v1; k2=v2"))
}
it should "add multiple headers if invoked multiple times" in {
sttp
.cookie("k1", "v1")
.cookie("k2" -> "v2")
.headers
.filter(_._1 == CookieHeader)
.map(_._2)
.toSet should be(Set("k1=v1", "k2=v2"))
}
it should "set cookies from a response" in {
val response =
Response((),
0,
List((SetCookieHeader, "k1=v1"), (SetCookieHeader, "k2=v2")))
sttp
.cookies(response)
.headers
.find(_._1 == CookieHeader)
.map(_._2) should be(Some("k1=v1; k2=v2"))
}
"content length" should "be automatically set for a string body" in {
sttp
.body("test")
.headers
.find(_._1.equalsIgnoreCase(ContentLengthHeader))
.map(_._2) should be(Some("4"))
}
it should "be automatically set to the number of utf-8 bytes in a string" in {
sttp
.body("ąęć")
.headers
.find(_._1.equalsIgnoreCase(ContentLengthHeader))
.map(_._2) should be(Some("6"))
}
it should "not override an already specified content length" in {
sttp
.contentLength(10)
.body("a")
.headers
.find(_._1.equalsIgnoreCase(ContentLengthHeader))
.map(_._2) should be(Some("10"))
}
}
|