-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
테스트 실행이 잘 안되어서 질문 드립니다.
20.01.31 12:32 작성 조회수 130
0
@Test
void createEvent() throws Exception {
Event event = Event.builder()
.name("Spring")
.description("Rest Api")
.beginEnrollmentDateTime(LocalDateTime.of(2020, 01, 31, 14, 50, 11))
.closeEnrollmentDateTime(LocalDateTime.of(2020,2,8, 00,00,00))
.baseProce(100)
.maxPrice(200)
.limitOfEnrollment(100)
.location("Seoul")
.build();
mockMvc.perform(post("/api/events")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaTypes.HAL_JSON_VALUE)
.contentType(objectMapper.writeValueAsString(event)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("id").exists());
}
@Controller
@RequestMapping(value = "/api/events", produces = MediaTypes.HAL_JSON_VALUE)
public class EventController {
@PostMapping
public ResponseEntity createEvent(@RequestBody Event event){
URI createUri = linkTo(EventController.class).slash("{id}").toUri();
event.setId(10l);
return ResponseEntity.created(createUri).body(event);
}
}
이렇게 실행시 415 에러가 발생하고 있습니다. MediaType을 정상적으로 준 것 같은데 에러가 왜 발생하는지 모르겠습니다.
답변을 작성해보세요.
답변 2