-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
NingWSRequestSpec.scala
47 lines (37 loc) · 1.43 KB
/
NingWSRequestSpec.scala
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
package play.libs.ws.ning
import org.specs2.mock.Mockito
import org.specs2.mutable._
class NingWSRequestSpec extends Specification with Mockito {
"NingWSRequest" should {
"should respond to getMethod" in {
val client = mock[NingWSClient]
val request = new NingWSRequest(client, "http://example.com")
request.buildRequest().getMethod must be_==("GET")
}
"should set virtualHost appropriately" in {
val client = mock[NingWSClient]
val request = new NingWSRequest(client, "http://example.com")
request.setVirtualHost("foo.com")
val actual = request.buildRequest().getVirtualHost()
actual must beEqualTo("foo.com")
}
"should support setting a request timeout" in {
requestWithTimeout(1000) must beEqualTo(1000)
}
"should support setting an infinite request timeout" in {
requestWithTimeout(-1) must beEqualTo(-1)
}
"should not support setting a request timeout < -1" in {
requestWithTimeout(-2) must throwA[IllegalArgumentException]
}
"should not support setting a request timeout > Integer.MAX_VALUE" in {
requestWithTimeout(Int.MaxValue.toLong + 1) must throwA[IllegalArgumentException]
}
}
def requestWithTimeout(timeout: Long) = {
val client = mock[NingWSClient]
val request = new NingWSRequest(client, "http://example.com")
request.setRequestTimeout(timeout)
request.buildRequest().getRequestTimeout()
}
}