Skip to content
Snippets Groups Projects
Commit 026dadbc authored by Marek Skácelík's avatar Marek Skácelík
Browse files

Merge branch 'issue-34' into 'milestone-3'

changed App class names

See merge request !52
parents 02b84bcd 11086d2b
No related branches found
No related tags found
2 merge requests!79Final merge to main,!52changed App class names
Pipeline #
......@@ -4,8 +4,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public class ElectricityPricesApplication {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
SpringApplication.run(ElectricityPricesApplication.class, args);
}
}
......@@ -4,9 +4,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public class EmailApplication {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
SpringApplication.run(EmailApplication.class, args);
}
}
......@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class AppTest {
public class EmailApplicationTest {
@Test
void contextLoads() {}
}
package cz.muni.fi.pa165.statistics;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import cz.muni.fi.pa165.statistics.statistics.StatisticCreateDto;
import cz.muni.fi.pa165.statistics.statistics.StatisticService;
import cz.muni.fi.pa165.statistics.statistics.UserStatisticsDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import java.util.ArrayList;
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;
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application-test.properties")
public class StatisticsControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private StatisticService statisticService;
private final static String URL = "/api/user-statistics";
private final static String CONTENT_TYPE = "application/json";
@Test
void findAllByUserTest() throws Exception {
StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build();
statisticCreateDto.setMonthNum(3);
List<UserStatisticsDto> l = new ArrayList<>();
assertEquals(statisticService.findAllUserStatistics(statisticCreateDto.getUserId()), l);
String response = mockMvc.perform(get(URL + "/all?userId=" + statisticCreateDto.getUserId())
.contentType(CONTENT_TYPE)
.content(objectMapper.writeValueAsString(statisticCreateDto)))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {});
assertEquals(userStatisticsDto, l);
}
@Test
void findHouseStatisticsByUserTest() throws Exception {
StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build();
statisticCreateDto.setMonthNum(3);
List<UserStatisticsDto> l = new ArrayList<>();
assertEquals(statisticService.findAllUserStatisticsByHouse(statisticCreateDto.getUserId(), statisticCreateDto.getHouseId()), l);
String response = mockMvc.perform(get(URL + "/user?userId=" + statisticCreateDto.getUserId()
+ "&houseId=" + statisticCreateDto.getHouseId())
.contentType(CONTENT_TYPE)
.content(objectMapper.writeValueAsString(statisticCreateDto)))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {});
assertEquals(userStatisticsDto, l);
}
}
package cz.muni.fi.pa165.statistics;
package cz.muni.fi.pa165.statistics.statistics;
import cz.muni.fi.pa165.statistics.statistics.StatisticRepository;
import cz.muni.fi.pa165.statistics.statistics.UserStatistic;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@DataJpaTest
public class UnitTestUserStatisticsJPA {
public class StatisticsRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
......
package cz.muni.fi.pa165.statistics;
package cz.muni.fi.pa165.statistics.statistics;
import cz.muni.fi.pa165.statistics.statistics.StatisticRepository;
import cz.muni.fi.pa165.statistics.statistics.StatisticService;
import cz.muni.fi.pa165.statistics.statistics.UserStatistic;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
......
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;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import java.util.ArrayList;
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;
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application-test.properties")
public class UserStatisticsControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private StatisticService statisticService;
private final static String URL = "/api/user-statistics";
private final static String CONTENT_TYPE = "application/json";
@Test
void findAllByUserTest() throws Exception {
StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build();
statisticCreateDto.setMonthNum(3);
List<UserStatisticsDto> l = new ArrayList<>();
assertEquals(statisticService.findAllUserStatistics(statisticCreateDto.getUserId()), l);
String response = mockMvc.perform(get(URL + "/all?userId=" + statisticCreateDto.getUserId())
.contentType(CONTENT_TYPE)
.content(objectMapper.writeValueAsString(statisticCreateDto)))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {
});
assertEquals(userStatisticsDto, l);
}
@Test
void findHouseStatisticsByUserTest() throws Exception {
StatisticCreateDto statisticCreateDto = StatisticCreateDto.builder().build();
statisticCreateDto.setMonthNum(3);
List<UserStatisticsDto> l = new ArrayList<>();
assertEquals(statisticService.findAllUserStatisticsByHouse(statisticCreateDto.getUserId(), statisticCreateDto.getHouseId()), l);
String response = mockMvc.perform(get(URL + "/user?userId=" + statisticCreateDto.getUserId()
+ "&houseId=" + statisticCreateDto.getHouseId())
.contentType(CONTENT_TYPE)
.content(objectMapper.writeValueAsString(statisticCreateDto)))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
List<UserStatisticsDto> userStatisticsDto = objectMapper.readValue(response, new TypeReference<List<UserStatisticsDto>>() {
});
assertEquals(userStatisticsDto, l);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment