[스프링 부트] chapter 23. 스프링 웹 MVC 10부 Spring HATEOS

스프링 웹 MVC 10부 Spring HATEOS

Hypermedia As The Engine Of Application State

@RestController
public class SampleController { 

    @GetMapping("/hello") 
    public Resource<Hello> hello() { 
        Hello hello = new Hello();
        hello.setPrefix("Hey"); 
        hello.setName("juho");

        Resource<Hello> helloResource = new Resource<>(hello); 
        helloResource.add(linkTo(methodOn(SampleController.class).hello()).withSelfRel()); 

        return helloResource; 
    }
} 
@RunWith(SpringRunner.class) 
@WebMvcTest(SampleController.class) 
public class SampleControllerTest { 
    @Autowired 
    MockMvc mockMvc;

    @Test 
    public void hello() throws Exception { 
        mockMvc.perform(get("/hello")) 
                .andDo(print()) 
                .andExpect(status().isOk()) 
                .andExpect(jsonPath("$._links.self").exists()); 
    } 
} 

@RunWith(SpringRunner.class) 
@WebMvcTest(SampleController.class) 
public class SampleControllerTest { 
    @Autowired 
    MockMvc mockMvc; 

    @Test 
    public void hello() throws Exception { 
        mockMvc.perform(get("/hello")) 
                .andDo(print()) 
                .andExpect(status().isOk()) 
                .andExpect(jsonPath("$._links.self").exists()); 
    } 
}  

ObjectMapper 제공

LinkDiscovers 제공