-
Notifications
You must be signed in to change notification settings - Fork 137
/
GroovyRestClientSpec.groovy
63 lines (49 loc) · 1.28 KB
/
GroovyRestClientSpec.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
52
53
54
55
56
57
58
59
60
61
62
63
package com.manning.spock;
import groovyx.net.http.RESTClient
import spock.lang.*
/**
* Rest tests using Groovy Rest client
*
* @author Kostis
*
*/
@Stepwise
class GroovyRestClientSpec extends Specification {
@Shared
def client = new RESTClient("http://localhost:8080/rest-service-example/")
def "Simple status checker"() {
when: "a rest call is performed to the status page"
def response = client.get(path : "status")
then: "the correct message is expected"
with(response) {
data.text == "Up and Running"
status == 200
}
}
def "Cleaning all products"() {
given: "a rest call is performed that deletes everything"
client.delete(path : "products")
when: "a product list is requested"
def response = client.get(path : "products")
then: "it should be empty"
with(response) {
data.isEmpty()
status == 200
}
}
def "Creating a product"() {
when: "a new product is created"
def response = client.post(path : "products")
and: "product list is requested again"
def listResponse = client.get(path : "products")
then: "it should have default values"
with(response) {
data.name == "A product"
data.stock == 0
data.price == 0
status == 200
}
and: "product list should contain it"
listResponse.data.size() == 1
}
}