-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCookieRequestSpec.groovy
51 lines (44 loc) · 1.61 KB
/
CookieRequestSpec.groovy
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
package grails.plugin.cookie
import org.grails.web.servlet.mvc.GrailsWebRequest
import org.grails.web.util.WebUtils
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.mock.web.MockServletContext
import spock.lang.Specification
import spock.lang.Unroll
import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletRequest
abstract class CookieRequestSpec extends Specification {
protected HttpServletRequest request = new MockHttpServletRequest()
protected obj
def setup() {
def mockWebRequest = new GrailsWebRequest(request, new MockHttpServletResponse(), new MockServletContext())
WebUtils.storeGrailsWebRequest(mockWebRequest)
}
def cleanup() {
WebUtils.clearGrailsWebRequest()
}
@Unroll
def "findCookie() return cookie and is case-sensitive by name: #name #expectedCookieName"() {
given:
def cookie = new Cookie('cookie_name', 'cookie_val')
request.cookies = [cookie]
expect:
obj.findCookie(name)?.name == expectedCookieName
where:
name | expectedCookieName
'cookie_name' | 'cookie_name'
'CoOkIe_NaMe' | null
}
@Unroll
def "getCookie() return cookie value and is case-sensitive by name: #name #expectedValue"() {
given:
request.cookies = [new Cookie('cookie_name', 'cookie_val')]
expect:
obj.getCookie(name) == expectedValue
where:
name | expectedValue
'cookie_name' | 'cookie_val'
'CoOkIe_NaMe' | null
}
}