/
LocalDateControllerTest.java
62 lines (53 loc) · 2.16 KB
/
LocalDateControllerTest.java
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
package net.anyjava.blogcode.controller;
import net.anyjava.blogcode.BlogCodeApplication;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ComponentScan(basePackageClasses = BlogCodeApplication.class)
@WebMvcTest
class LocalDateControllerTest {
@Autowired
MockMvc mockMvc;
@DisplayName("LocalDate 파라미터를 받는 API 테스트 - default format")
@Test
void assetLocalDateGetAPIDefault() throws Exception {
// given
String url = "/localdate-default?createdAt=2020-01-01";
// when
// then
var res = mockMvc.perform(get(url))
.andExpect(status().isOk())
.andExpect(content().string("\"2020-01-01\""))
.andDo(print());
}
@DisplayName("LocalDate 파라미터를 받는 API 테스트 - custom format")
@Test
void assetLocalDateGetAPI() throws Exception {
// given
String url = "/localdate?createdAt=2020.01.01";
// when
// then
var res = mockMvc.perform(get(url))
.andExpect(status().isOk())
.andExpect(content().string("\"2020-01-01\""))
.andDo(print());
}
@DisplayName("LocalDate 파라미터를 받는 API 테스트 - 400 에러")
@Test
void assetLocalDateGetAPIFailed() throws Exception {
// given
String url = "/localdate?createdAt=20209999";
// when
// then
var res = mockMvc.perform(get(url))
.andExpect(status().is4xxClientError())
.andDo(print());
}
}