forked from cho-log/spring-learning-test
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRestTemplateTest.java
More file actions
60 lines (46 loc) · 1.76 KB
/
RestTemplateTest.java
File metadata and controls
60 lines (46 loc) · 1.76 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
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 RestTemplateTest {
@Autowired
private TodoClientWithRestTemplate todoClient;
@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() {
// DELETE 요청을 보내고 상태 코드 확인
HttpStatusCode deleteStatus = todoClient.deleteTodo(3L);
assertThat(deleteStatus).isEqualTo(HttpStatus.OK); // 204 No Content 확인
}
}