-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo_groupsTest.java
More file actions
218 lines (175 loc) · 9.41 KB
/
todo_groupsTest.java
File metadata and controls
218 lines (175 loc) · 9.41 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package tests;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
public class todo_groupsTest {
protected static final String BASE_URL = "https://api.ibrohhm.com";
protected static final String AUTH_TOKEN = "Bearer ya29.a0AeDClZC8nYhUyVJYCUao0K6jvSVUTsrswntLP8ec1xl-jLBXLDbP67xotP4UMWFLNo9lw329kbc_-qAE1RnF1FZNsi1nNGUHKrxMo-WA2jRNwvPh6c5LMtleWnnRpUV2CsR7z-bPzztd_k638WGnDmAesWXNb9bl7-b2a9zVaCgYKARISARISFQHGX2MisUvGiCN32M1l6eDza4NxQg0175";
@BeforeClass
public void setup() {
// Set the base URI for the API
RestAssured.baseURI = BASE_URL;
}
@Test
public void testGetEndpoint() {
// Send GET request to the tick-list page with the Authorization token
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Set Authorization header with Bearer token
.when()
.get("/todo-groups"); // Use the correct endpoint
// Print the response to verify content
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Example assertion to verify status code (optional)
assert response.getStatusCode() == 200 : "Expected status code 200, but got " + response.getStatusCode();
}
@Test
public void testCreateTodo() {
// Membuat payload untuk request
Map<String, Object> payload = new HashMap<>();
payload.put("name", "tes tiket"); // Ganti dengan ID grup yang valid
payload.put("note", "task baru"); // Task baru
// Mengirim POST request ke endpoint /todos
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.header("Content-Type", "application/json") // Menentukan format payload
.body(payload) // Menambahkan payload ke body request
.when()
.post("/todo-groups"); // Endpoint untuk membuat todo
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 200 : "Expected status code 200, but got " + response.getStatusCode();
assert response.jsonPath().getString("data.name").equals("tes tiket") : "tes mismatch!";
assert response.jsonPath().getString("data.note").equals("task baru") : "Note mismatch!";
}
@Test
public void testCreateTodoInvalidPayload() { // ini udah dicoba tapi payload yang kosong bisa, yang invalid tidak jelas seperti apa :)
// Membuat payload invalid (data kosong)
Map<String, Object> payload = new HashMap<>();
payload.put("name", ""); // Field "name" kosong
payload.put("note", ""); // Field "note" kosong
// Mengirim POST request ke endpoint /todo-groups dengan payload invalid
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.header("Content-Type", "application/json") // Menentukan format payload
.body(payload) // Menambahkan payload ke body request
.when()
.post("/todo-groups"); // Endpoint untuk membuat todo group
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 400 || response.getStatusCode() == 422 :
"Expected status code 400 or 422, but got " + response.getStatusCode();
}
@Test
public void testGetTodoById() {
// Mengirim GET request ke endpoint /todo-groups/{ticketId}
Response getResponse = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Token autentikasi
.when()
.get("/todo-groups/11"); // Endpoint untuk mendapatkan tiket berdasarkan ID
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + getResponse.getStatusCode());
System.out.println("Response Body: " + getResponse.asString());
// Memastikan respons status 200
assert getResponse.getStatusCode() == 200 :
"Expected status code 200, but got " + getResponse.getStatusCode();
}
@Test
public void testGetNotExistTodoById() {
// Mengirim GET request ke endpoint /todo-groups/{ticketId}
Response getResponse = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Token autentikasi
.when()
.get("/todo-groups/18"); // Endpoint untuk mendapatkan tiket berdasarkan ID
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + getResponse.getStatusCode());
System.out.println("Response Body: " + getResponse.asString());
// Memastikan respons status 200
assert getResponse.getStatusCode() == 404 :
"Expected status code 404, but got " + getResponse.getStatusCode();
}
@Test
public void testPutTodo() {
// Membuat payload untuk request
Map<String, Object> payload = new HashMap<>();
payload.put("name", "tes tiket update"); // Ganti dengan ID grup yang valid
payload.put("note", "task baru"); // Task baru
// Mengirim POST request ke endpoint /todos
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.header("Content-Type", "application/json") // Menentukan format payload
.body(payload) // Menambahkan payload ke body request
.when()
.patch("/todo-groups/15"); // Endpoint untuk membuat todo
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 200 : "Expected status code 200, but got " + response.getStatusCode();
}
@Test
public void testPutNotExistTodo() {
// Membuat payload untuk request
Map<String, Object> payload = new HashMap<>();
payload.put("name", "tes tiket update"); // Ganti dengan ID grup yang valid
payload.put("note", "task baru"); // Task baru
// Mengirim POST request ke endpoint /todos
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.header("Content-Type", "application/json") // Menentukan format payload
.body(payload) // Menambahkan payload ke body request
.when()
.patch("/todo-groups/17"); // Endpoint untuk membuat todo
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 404 : "Expected status code 404, but got " + response.getStatusCode();
}
@Test
public void testDeleteTodo() {
// Mengirim POST request ke endpoint /todos
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.when()
.delete("/todo-groups/15"); // Endpoint untuk membuat todo
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 200 : "Expected status code 200, but got " + response.getStatusCode();
}
@Test
public void testDeleteInvalidTodo() {
// Mengirim POST request ke endpoint /todos
Response response = RestAssured
.given()
.header("Authorization", AUTH_TOKEN) // Menyertakan token autentikasi
.when()
.delete("/todo-groups/15"); // Endpoint untuk membuat todo
// Menampilkan status dan respons body untuk debugging
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.asString());
// Memvalidasi hasil sesuai dengan expected result
assert response.getStatusCode() == 404 : "Expected status code 404, but got " + response.getStatusCode();
}
}