|
| 1 | +package dev.pradeep.SirmaAssignment.Tests; |
| 2 | + |
| 3 | +import dev.pradeep.SirmaAssignment.Dto.Request.CreateProjectDto; |
| 4 | +import dev.pradeep.SirmaAssignment.Dto.Request.UpdateProjectDto; |
| 5 | +import dev.pradeep.SirmaAssignment.Enum.ProjectStatus; |
| 6 | +import dev.pradeep.SirmaAssignment.Model.Project; |
| 7 | +import dev.pradeep.SirmaAssignment.Services.ProjectService; |
| 8 | +import java.time.LocalDate; |
| 9 | +import java.util.List; |
| 10 | +import org.assertj.core.api.Assertions; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | +import org.springframework.beans.factory.annotation.Autowired; |
| 13 | +import org.springframework.boot.test.context.SpringBootTest; |
| 14 | + |
| 15 | +@SpringBootTest |
| 16 | +public class ProjectServiceIntegrationTest { |
| 17 | + |
| 18 | + //instead of mock bean use actual bean |
| 19 | + @Autowired |
| 20 | + private ProjectService projectService; |
| 21 | + |
| 22 | + @Test |
| 23 | + public void TestCrudApis(){ |
| 24 | + createProjectTest(); |
| 25 | + updateProjectTest(); |
| 26 | + getTest(); |
| 27 | + getListProjects(); |
| 28 | + deleteProjectTest(); |
| 29 | + } |
| 30 | + |
| 31 | + public void updateProjectTest() { |
| 32 | + UpdateProjectDto updateProjectDto = UpdateProjectDto.builder() |
| 33 | + .projectId(1L) |
| 34 | + .name("kidney stone detector") |
| 35 | + .projectType("machine learning project") |
| 36 | + .status(ProjectStatus.IN_PROGRESS) |
| 37 | + .startDate(LocalDate.now()) |
| 38 | + .endDate(LocalDate.now().plusMonths(2)) |
| 39 | + .description("This is a machine learning project") |
| 40 | + .projectRequirements(List.of("4gb ram", "50gb ssd", "cpu 5 gen")) |
| 41 | + .technologies(List.of("java", "python", "kotlin")) |
| 42 | + .build(); |
| 43 | + |
| 44 | + projectService.updateProject(updateProjectDto); |
| 45 | + |
| 46 | + // check if the start date is less than end date |
| 47 | + Assertions.assertThat(updateProjectDto.getEndDate()).isAfter(updateProjectDto.getStartDate()); |
| 48 | + } |
| 49 | + |
| 50 | + public void createProjectTest() { |
| 51 | + CreateProjectDto createProjectDto = CreateProjectDto.builder() |
| 52 | + .name("kidney stone detector") |
| 53 | + .projectType("machine learning project") |
| 54 | + .status(ProjectStatus.IN_PROGRESS) |
| 55 | + .startDate(LocalDate.now()) |
| 56 | + .endDate(LocalDate.now().plusMonths(2)) |
| 57 | + .description("This is a machine learning project") |
| 58 | + .projectRequirements(List.of("4gb ram", "50gb ssd", "cpu 5 gen")) |
| 59 | + .technologies(List.of("java", "python", "kotlin")) |
| 60 | + .build(); |
| 61 | + |
| 62 | + projectService.createProject(createProjectDto); |
| 63 | + |
| 64 | + // check if the start date is less than end date |
| 65 | + Assertions.assertThat(createProjectDto.getEndDate()).isAfter(createProjectDto.getStartDate()); |
| 66 | + } |
| 67 | + |
| 68 | + /* |
| 69 | + before adding to the database, it is pretested and validated |
| 70 | + null initially test fails |
| 71 | + */ |
| 72 | + public void getTest() { |
| 73 | + Project project = projectService.findProject(1L); |
| 74 | + Assertions.assertThat(project.getId()).isEqualTo(1L); |
| 75 | + } |
| 76 | + |
| 77 | + /* |
| 78 | + dummy test to check if the database is not empty |
| 79 | + test fails as the list is empty by default as an in-memory database. |
| 80 | + */ |
| 81 | + public void getListProjects() { |
| 82 | + List<Project> projects = projectService.findAllProjects(); |
| 83 | + Assertions.assertThat(projects.size()).isGreaterThan(0); |
| 84 | + } |
| 85 | + |
| 86 | + /* |
| 87 | + check if the project is deleted |
| 88 | + if null then successfully deleted |
| 89 | + */ |
| 90 | + public void deleteProjectTest() { |
| 91 | + projectService.deleteProject(1L); |
| 92 | + } |
| 93 | + |
| 94 | +} |
0 commit comments