https://docs.spring.io/spring-hateoas/docs/1.2.0-SNAPSHOT/reference/html/
Spring HATEOAS - Reference Documentation
Example 47. Configuring WebTestClient when using Spring Boot @SpringBootTest @AutoConfigureWebTestClient (1) class WebClientBasedTests { @Test void exampleTest(@Autowired WebTestClient.Builder builder, @Autowired HypermediaWebTestClientConfigurer configure
docs.spring.io
스프링 래퍼런스에 따르면 헤이토스의 표현 모델은 총 4가지가 있습니다.
class RepresentationModel
class EntityModel
class CollectionModel
class PagedModel
그 중 Entity와 Collection은 Representation을 상속받고,
Paged는 Collection을 상속받기 때문에 결국 Representation모델을 상속받아 사용합니다.
EntityModel -|> RepresentationModel
CollectionModel -|> RepresentationModel
PagedModel -|> CollectionModel
표현 모델만 테스트할 컨트롤을 아래와 같이 만들었습니다.
RepresentationModel은 아래와 같이 상속받은 모델을 사용합니다.
1
2
3
4
5
6
7
|
@Getter
@Setter
public class PersonModel extends RepresentationModel<PersonModel>
{
String firstName, lastName;
}
|
그 외 표현모델에서는 RepresentationModel을 상속받지않고 기본생성자만 선언하여 작성한 Person 객체를 사용했습니다.
아래는 mockMvc를 통해 위 컨트롤러를 테스트한 코드입니다.
테스트 결과입니다.
Body에 이동할 링크가 "_links"로 선언된 것을 확인할 수 있습니다.
'- Spring' 카테고리의 다른 글
[Spring Hateoas1.2] ModelAssembler, ModelProcessor (0) | 2020.09.02 |
---|---|
[Spring Hateoas 1.2] HTTP Method에 헤이토스 적용 (0) | 2020.08.27 |
[Spring Hateoas 1.2] 소개 및 프로젝트 설정 (0) | 2020.08.21 |
[Spring Batch] cannot be cast to org.springframework.batch.item.~ (0) | 2020.07.31 |
[Spring Batch] If you want to run this job again, change the parameters. (0) | 2020.07.17 |