View Javadoc
1   package de.aikiit.bilanzanalyser.api;
2   
3   import org.junit.jupiter.api.Test;
4   import org.springframework.beans.factory.annotation.Autowired;
5   import org.springframework.boot.test.context.SpringBootTest;
6   import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
7   import org.springframework.test.web.servlet.MockMvc;
8   import tools.jackson.core.type.TypeReference;
9   import tools.jackson.databind.ObjectMapper;
10  
11  import java.util.List;
12  
13  import static org.assertj.core.api.Assertions.assertThat;
14  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
15  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16  
17  @SpringBootTest
18  @AutoConfigureMockMvc
19  class DataControllerITest {
20  
21      @Autowired
22      private MockMvc mockMvc;
23  
24      @Autowired
25      private ObjectMapper objectMapper;
26  
27      @Test
28      void shouldReturnDataItems() throws Exception {
29          String response = mockMvc.perform(get("/api/dataitems")).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
30  
31          List<DataItem> result = objectMapper.readValue(response, new TypeReference<>() {
32          });
33  
34          assertThat(result).hasSize(5);
35  
36          // structure checks
37          assertThat(result.get(0).name()).isNotBlank();
38          assertThat(result.get(0).value()).isGreaterThanOrEqualTo(0);
39  
40          assertThat(result).anyMatch(item -> item.name().equals("Bilanz rows"));
41          assertThat(result).anyMatch(item -> item.name().equals("Categories"));
42          assertThat(result).anyMatch(item -> item.name().equals("Payment"));
43          assertThat(result).anyMatch(item -> item.name().equals("Shop"));
44          assertThat(result).anyMatch(item -> item.name().equals("Source"));
45      }
46  }