Skip to content

MockMvc wrapper allowing to easily test Spring HATEOAS HAL(-FORMS) endpoints

License

Notifications You must be signed in to change notification settings

Cosium/hal-mock-mvc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central

HAL Mock MVC

MockMvc wrapper allowing to easily test Spring HATEOAS HAL(-FORMS) endpoints.

Quick start

  1. Add the spring-boot-starter dependency:
    <dependency>
       <groupId>com.cosium.hal_mock_mvc</groupId>
       <artifactId>hal-mock-mvc-spring-boot-starter</artifactId>
       <version>${hal-mock-mvc.version}</version>
       <scope>test</scope>
    </dependency>
  2. Annotate your test class with AutoConfigureHalMockMvc and inject HalMockMvc:
    @AutoConfigureHalMockMvc
    @SpringBootTest
    class MyTest {
      @Autowired
      private HalMockMvc halMockMvc;
    
      @Test
      void test() {
        halMockMvc
           .follow("current-user")
           .get()
           .andExpect(status().isOk())
           .andExpect(jsonPath("$.alias").value("jdoe"));
      }
    }

Prerequisites

  • Java 17+
  • Spring dependencies matching Spring Boot 3 and above.

Genesis

This project was created following spring-projects/spring-hateoas#733 discussion.