Loading statistics/src/test/java/cz/muni/fi/pa165/statistics/statistics/UserStatisticsControllerTest.java +13 −11 Original line number Diff line number Diff line package cz.muni.fi.pa165.statistics.statistics; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; Loading @@ -14,7 +13,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @SpringBootTest @AutoConfigureMockMvc Loading Loading @@ -42,14 +41,9 @@ public class UserStatisticsControllerTest { String response = mockMvc.perform(get(URL + "/all?userId=" + statisticCreateDto.getUserId()) .contentType(CONTENT_TYPE) .content(objectMapper.writeValueAsString(statisticCreateDto))) //.andExpect(status().is4xxClientError()) .andReturn() .getResponse() .getContentAsString(); /*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() { }); assertEquals(userStatisticsDto, l);*/ } @Test Loading @@ -63,13 +57,21 @@ public class UserStatisticsControllerTest { + "&houseId=" + statisticCreateDto.getHouseId()) .contentType(CONTENT_TYPE) .content(objectMapper.writeValueAsString(statisticCreateDto))) //.andExpect(status().is4xxClientError()) .andReturn() .getResponse() .getContentAsString(); /*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() { }); } assertEquals(userStatisticsDto, l);*/ @Test void createStatisticsTest() throws Exception { StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build(); statisticCreateDto.setMonthNum(3); String jsonBody = objectMapper.writeValueAsString(statisticCreateDto); String response = mockMvc.perform(post(URL) .contentType(CONTENT_TYPE) .content(jsonBody)) .andReturn() .getResponse() .getContentAsString(); } } Loading
statistics/src/test/java/cz/muni/fi/pa165/statistics/statistics/UserStatisticsControllerTest.java +13 −11 Original line number Diff line number Diff line package cz.muni.fi.pa165.statistics.statistics; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; Loading @@ -14,7 +13,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @SpringBootTest @AutoConfigureMockMvc Loading Loading @@ -42,14 +41,9 @@ public class UserStatisticsControllerTest { String response = mockMvc.perform(get(URL + "/all?userId=" + statisticCreateDto.getUserId()) .contentType(CONTENT_TYPE) .content(objectMapper.writeValueAsString(statisticCreateDto))) //.andExpect(status().is4xxClientError()) .andReturn() .getResponse() .getContentAsString(); /*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() { }); assertEquals(userStatisticsDto, l);*/ } @Test Loading @@ -63,13 +57,21 @@ public class UserStatisticsControllerTest { + "&houseId=" + statisticCreateDto.getHouseId()) .contentType(CONTENT_TYPE) .content(objectMapper.writeValueAsString(statisticCreateDto))) //.andExpect(status().is4xxClientError()) .andReturn() .getResponse() .getContentAsString(); /*List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() { }); } assertEquals(userStatisticsDto, l);*/ @Test void createStatisticsTest() throws Exception { StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build(); statisticCreateDto.setMonthNum(3); String jsonBody = objectMapper.writeValueAsString(statisticCreateDto); String response = mockMvc.perform(post(URL) .contentType(CONTENT_TYPE) .content(jsonBody)) .andReturn() .getResponse() .getContentAsString(); } }