|
20 | 20 | import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; |
21 | 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
22 | 22 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
| 23 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
23 | 24 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
24 | 25 |
|
25 | 26 | @WebMvcTest(controllers = ComposerController.class) |
@@ -77,6 +78,60 @@ public class ComposerControllerTest extends ControllerTestSupport { |
77 | 78 | )); |
78 | 79 | } |
79 | 80 |
|
| 81 | + @Test |
| 82 | + void ์๊ณก๊ฐ๋ฅผ_์์ ํ๋ค() throws Exception { |
| 83 | + // given |
| 84 | + Long composerId = 1L; |
| 85 | + Map<String, Object> requestBody = Map.of( |
| 86 | + "koreanName", "๋ฒ ํ ๋ฒค", |
| 87 | + "englishName", "Ludwig van Beethoven", |
| 88 | + "gender", "MALE", |
| 89 | + "nationality", "๋
์ผ", |
| 90 | + "birthYear", 1770, |
| 91 | + "deathYear", 1827, |
| 92 | + "bio", "๋
์ผ์ ์๊ณก๊ฐ", |
| 93 | + "era", "CLASSICAL", |
| 94 | + "continent", "EUROPE" |
| 95 | + ); |
| 96 | + Cookie cookie = new Cookie(COOKIE_NAME, "access_token"); |
| 97 | + |
| 98 | + // when |
| 99 | + ResultActions result = mockMvc.perform(put("/composers/{composerId}", composerId) |
| 100 | + .contentType(MediaType.APPLICATION_JSON) |
| 101 | + .content(objectMapper.writeValueAsString(requestBody)) |
| 102 | + .cookie(cookie) |
| 103 | + ); |
| 104 | + |
| 105 | + // then |
| 106 | + result.andExpect(status().isNoContent()) |
| 107 | + .andDo(restDocsHandler.document( |
| 108 | + resource(ResourceSnippetParameters.builder() |
| 109 | + .tag("Composer API") |
| 110 | + .summary("์๊ณก๊ฐ ์์ ") |
| 111 | + .description("๊ด๋ฆฌ์๊ฐ ์๊ณก๊ฐ ์ ๋ณด๋ฅผ ์์ ํฉ๋๋ค.") |
| 112 | + .pathParameters( |
| 113 | + parameterWithName("composerId").description("์์ ํ ์๊ณก๊ฐ ID") |
| 114 | + ) |
| 115 | + .requestFields( |
| 116 | + fieldWithPath("koreanName").type(JsonFieldType.STRING).description("ํ๊ตญ์ด ์ด๋ฆ"), |
| 117 | + fieldWithPath("englishName").type(JsonFieldType.STRING).description("์์ด ์ด๋ฆ"), |
| 118 | + fieldWithPath("nativeName").type(JsonFieldType.STRING).description("์์ด ์ด๋ฆ").optional(), |
| 119 | + fieldWithPath("gender").type(JsonFieldType.STRING).description("์ฑ๋ณ (MALE / FEMALE / UNKNOWN)"), |
| 120 | + fieldWithPath("nationality").type(JsonFieldType.STRING).description("๊ตญ์ "), |
| 121 | + fieldWithPath("birthYear").type(JsonFieldType.NUMBER).description("์ถ์ ์ฐ๋"), |
| 122 | + fieldWithPath("deathYear").type(JsonFieldType.NUMBER).description("์ฌ๋ง ์ฐ๋"), |
| 123 | + fieldWithPath("bio").type(JsonFieldType.STRING).description("์๊ฐ"), |
| 124 | + fieldWithPath("era").type(JsonFieldType.STRING).description("์๋ (MEDIEVAL_RENAISSANCE / BAROQUE / CLASSICAL / ROMANTIC / MODERN_CONTEMPORARY)"), |
| 125 | + fieldWithPath("continent").type(JsonFieldType.STRING).description("๋๋ฅ (ASIA / NORTH_AMERICA / EUROPE / SOUTH_AMERICA / AFRICA_OCEANIA)") |
| 126 | + ) |
| 127 | + .build() |
| 128 | + ), |
| 129 | + requestCookies( |
| 130 | + cookieWithName(COOKIE_NAME).description("์ ์ ์ ํ ํฐ") |
| 131 | + ) |
| 132 | + )); |
| 133 | + } |
| 134 | + |
80 | 135 | @Test |
81 | 136 | void ์๊ณก๊ฐ๋ฅผ_์ญ์ ํ๋ค() throws Exception { |
82 | 137 | // given |
|
0 commit comments