@Test
@TestDescription("기존의 이벤트를 하나 조회하기")
public void getEvent() throws Exception {
// Given
Event event = this.generateEvent(100);
this.mockMvc.perform(get("/api/events/{id}", event.getId()))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("name").exists())
.andExpect(jsonPath("id").exists())
.andExpect(jsonPath("_links.self").exists())
.andExpect(jsonPath("_links.profile").exists())
.andDo(document("get-an-event"));
}
@Test
@TestDescription("없는 이벤트 조회 했을때 404로 응답 받기")
public void getEvent404() throws Exception {
this.mockMvc.perform(get("/api/events/100"))
.andDo(print())
.andExpect(status().isNotFound());
}
@GetMapping("/{id}")
public ResponseEntity getEvent(@PathVariable Integer id) {
Optional<Event> optionalEvent = this.eventRepository.findById(id);
if (!optionalEvent.isPresent()) {
return ResponseEntity.notFound().build();
}
Event event = optionalEvent.get();
EventResource eventResource = new EventResource(event);
eventResource.add(new Link("/docs/index.html#resources-events-get").withRel("profile"));
return ResponseEntity.ok(eventResource);
}