• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

테스트 실행이 잘 안되어서 질문 드립니다.

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

·

답변을 작성해보세요.

0

kim님의 프로필

kim

질문자

2020.02.01

contentType을 2번 실행했네요

진짜 자기가 실수하는 테스트는 너무 안보이네요 ㅠㅠ

0

테스트 코드를 잘 보시면 실수하신게 보일겁니다. 급하게 코딩하시느라 실수하신거 같습니다. 시간을 좀 더 드리겠습니다.