-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusing_links.groovy
30 lines (30 loc) · 1023 Bytes
/
using_links.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
@Test
void testNextAndPreviousHeaders() {
Client cl = ClientBuilder.newClient()
int id = 1
WebTarget target = cl.target("http://localhost:1234/people/$id")
def resp = target.request().get(Response.class)
def next = resp.getLink('next').uri
assert next.toString()[-1] == (++id).toString()
println 'following next links...'
while (next) {
println "Accessing $next"
target = cl.target(next)
resp = target.request().get(Response.class)
next = resp.getLink('next')?.uri
if (next)
assert next.toString()[-1] == (++id).toString()
}
println 'following prev links...'
def prev = resp.getLink('prev').uri
assert prev.toString()[-1] == (--id).toString()
while (prev) {
println "Accessing $prev"
target = cl.target(prev)
resp = target.request().get(Response.class)
prev = resp.getLink('prev')?.uri
if (prev)
assert prev.toString()[-1] == (--id).toString()
}
cl.close()
}