요청 필드 문서화
@Test
@TestDescription("정상적으로 이벤트를 생성하는 테스트")
public void createEvent() throws Exception {
EventDto event = EventDto.builder()
.name("Spring")
.description("REST API Development with Spring")
.beginEnrollmentDateTime(LocalDateTime.of(2019, 4, 17, 20, 39))
.closeEnrollmentDateTime(LocalDateTime.of(2019, 4, 18, 20, 39))
.beginEventDateTime(LocalDateTime.of(2019, 4, 20, 9, 0))
.endEventDateTime(LocalDateTime.of(2019, 4, 20, 18, 0))
.location("스타트업 팩토리")
.basePrice(100)
.maxPrice(200)
.limitOfEnrollment(100)
.build();
mockMvc.perform(post("/api/events")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaTypes.HAL_JSON)
.content(objectMapper.writeValueAsString(event)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("id").exists())
.andExpect(header().exists(HttpHeaders.LOCATION))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_UTF8_VALUE))
.andExpect(jsonPath("free").value(false))
.andExpect(jsonPath("offline").value(true))
.andExpect(jsonPath("eventStatus").value(EventStatus.DRAFT.name()))
.andExpect(jsonPath("_links.self").exists())
.andExpect(jsonPath("_links.query-events").exists())
.andExpect(jsonPath("_links.update-event").exists())
.andDo(document("create-event",
links(
linkWithRel("self").description("link to self"),
linkWithRel("query-events").description("link to query events"),
linkWithRel("update-event").description("link to update an existing")
),
requestHeaders(
headerWithName(HttpHeaders.ACCEPT).description("accept header"),
headerWithName(HttpHeaders.CONTENT_TYPE).description("content type header")
),
requestFields(
fieldWithPath("name").description("name of new event"),
fieldWithPath("description").description("description of new event"),
fieldWithPath("beginEnrollmentDateTime").description("beginEnrollmentDateTime of new event"),
fieldWithPath("closeEnrollmentDateTime").description("closeEnrollmentDateTime of new event"),
fieldWithPath("beginEventDateTime").description("beginEventDateTime of new event"),
fieldWithPath("endEventDateTime").description("endEventDateTime of new event"),
fieldWithPath("location").description("location of new event"),
fieldWithPath("basePrice").description("basePrice of new event"),
fieldWithPath("maxPrice").description("maxPrice of new event"),
fieldWithPath("limitOfEnrollment").description("limitOfEnrollment of new event")
),
responseHeaders(
headerWithName(HttpHeaders.LOCATION).description("location header for created event"),
headerWithName(HttpHeaders.CONTENT_TYPE).description("content type header")
),
responseFields(
fieldWithPath("id").description("id of new event"),
fieldWithPath("name").description("name of new event"),
fieldWithPath("description").description("description of new event"),
fieldWithPath("beginEnrollmentDateTime").description("beginEnrollmentDateTime of new event"),
fieldWithPath("closeEnrollmentDateTime").description("closeEnrollmentDateTime of new event"),
fieldWithPath("beginEventDateTime").description("beginEventDateTime of new event"),
fieldWithPath("endEventDateTime").description("endEventDateTime of new event"),
fieldWithPath("location").description("location of new event"),
fieldWithPath("basePrice").description("basePrice of new event"),
fieldWithPath("maxPrice").description("maxPrice of new event"),
fieldWithPath("limitOfEnrollment").description("limitOfEnrollment of new event"),
fieldWithPath("free").description("it tells if this event if free"),
fieldWithPath("offline").description("it tells if this event if offline"),
fieldWithPath("eventStatus").description("event status"),
fieldWithPath("_links.self").description("link to self"),
fieldWithPath("_links.query-events").description("link to event list"),
fieldWithPath("_links.update-event").description("link to event update")
)
));
}
Relaxed 접두어