forked from cho-log/spring-learning-test
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRestClientTest.java
More file actions
69 lines (52 loc) · 2.01 KB
/
RestClientTest.java
File metadata and controls
69 lines (52 loc) · 2.01 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
package cholog;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@SpringBootTest
public class RestClientTest {
@Autowired
private TodoClientWithRestClient todoClient;
@Test
public void testGetTodos() {
List<Todo> todos = todoClient.getTodos();
assertThat(todos).isNotEmpty();
}
@Test
public void testGetTodoWithId() {
Todo todo = todoClient.getTodoById(1L);
assertThat(todo.getTitle()).isNotEmpty();
}
@Test
public void testGetTodoWithNonExistentId() {
Long nonExistentId = 9999L;
assertThatThrownBy(() -> todoClient.getTodoById(nonExistentId))
.isInstanceOf(TodoException.NotFound.class);
}
@Test
public void testCreateTodo() {
Todo newTodo = new Todo(2L, 2L, "New Todo", false);
Todo createdTodo = todoClient.createTodo(newTodo);
assertThat(createdTodo).isNotNull();
assertThat(createdTodo.getTitle()).isEqualTo(newTodo.getTitle());
}
@Test
public void testUpdateTodo() {
testCreateTodo();
Todo updatedTodo = new Todo(2L, 2L, "Updated Todo", true);
Todo resultTodo = todoClient.updateTodo(2L, updatedTodo);
assertThat(resultTodo).isNotNull();
assertThat(resultTodo.getTitle()).isEqualTo("Updated Todo");
}
@Test
public void testDeleteTodo() {
todoClient.deleteTodo(2L);
//삭제된 후, 해당 id로 getTodoById를 호출하면 TodoException.NotFound 예외가 발생하는지를 검증
// 예외를 발생하는지 -> NotFound class 인지
// assertThatThrownBy(() -> todoClient.getTodoById(2L)).isInstanceOf(TodoException.NotFound.class);
}
}