-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
118 lines (99 loc) · 3.3 KB
/
test.sh
File metadata and controls
118 lines (99 loc) · 3.3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
echo
echo "------------------"
echo "Removing data"
echo "------------------"
sh clean.sh
echo
echo "------------------"
echo "Testing POST"
echo "------------------"
echo
testOK=0
testFAIL=0
addToOK() {
((testOK=testOK+1))
}
addToFail() {
((testFAIL=testFAIL+1))
}
validate() {
if [[ "$1" == *"$2"* ]]; then
echo "$2" TEST OK
addToOK
else
echo "$2" TEST FAIL, the actual result is
echo "$1"
addToFail
fi
}
succesPost=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Sponges","unitPrice":99,"unitSize":8,"unitType":"ITEM"}' \
http://localhost:1234/product)
failPostConflict=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Sponges","unitPrice":99,"unitSize":8,"unitType":"ITEM"}' \
http://localhost:1234/product)
failPostWrongPrice=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Foobar","unitPrice":4,"unitSize":8,"unitType":"ITEM"}' \
http://localhost:1234/product)
failPostWrongSize=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Foobar","unitPrice":55,"unitSize":0,"unitType":"ITEM"}' \
http://localhost:1234/product)
failPostWrongItemType=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Foobar","unitPrice":55,"unitSize":23,"unitType":"BOX"}' \
http://localhost:1234/product)
failPostMissingParam=$(curl --header "Content-Type: application/json" \
--request POST \
--data '{"name":"Foobar","unitPrice":55,"unitSize":30}' \
http://localhost:1234/product)
echo
echo "------------------"
echo "Testing PUT"
echo "------------------"
echo
succesPut=$(curl --header "Content-Type: application/json" \
--request PUT \
--data '{"name":"Sponges","unitPrice":199,"unitSize":8,"unitType":"ITEM"}' \
http://localhost:1234/product)
failPut=$(curl --header "Content-Type: application/json" \
--request PUT \
--data '{"name":"Spongebob","unitPrice":199,"unitSize":8,"unitType":"ITEM"}' \
http://localhost:1234/product)
echo
echo "------------------"
echo "Testing GET"
echo "------------------"
echo
succesGet=$(curl --request GET http://localhost:1234/product/Sponges)
succesGetAll=$(curl --request GET http://localhost:1234/product)
failGet=$(curl --request GET http://localhost:1234/product/idontexist)
echo
echo "------------------"
echo "Testing DELETE"
echo "------------------"
echo
succesDelete=$(curl --request DELETE http://localhost:1234/product/Sponges)
failDelete=$(curl --request DELETE http://localhost:1234/product/idontexist)
echo
validate "$succesPost" "Product registered"
validate "$failPostConflict" "Product already exists"
validate "$failPostWrongPrice" "Price must be 5 or higher"
validate "$failPostWrongSize" "Size must be 1 or higher"
validate "$failPostWrongItemType" "\"unitType\": \"BOX is not a valid choice"
validate "$failPostMissingParam" "\"unitType\": \"Missing required parameter"
validate "$succesPut" "Product updated"
validate "$failPut" "Product not found"
validate "$succesGet" "Product found"
validate "$succesGetAll" "1 Product(s) found"
validate "$failGet" "Product not found"
validate "$succesDelete" "Product removed"
validate "$failDelete" "Product not found"
echo
echo Test Summary:
echo "$testOK" Tests Passed
echo "$testFAIL" Tests Failed
echo