-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from T2-Papillon/dashboard_service_test/choi
[ADD] DashBoard logic Junit Test
- Loading branch information
Showing
17 changed files
with
313 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
public class Contributor{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
papplan/src/main/java/com/boogle/papplan/entity/Employees.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
spring: | ||
sql: | ||
init: | ||
platform: mariadb | ||
encoding: UTF-8 | ||
mode: always | ||
schema-locations: classpath:db/schema-script/create.sql | ||
data-locations: classpath:/db/data-script/data-department.sql | ||
datasource: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:test;MODE=MariaDB | ||
username: sa | ||
password: | ||
# data: classpath:/db/data-script/ | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: none | ||
generate-ddl: false | ||
show-sql: false | ||
h2: | ||
console: # H2 DB를 웹에서 관리할 수 있는 기능 | ||
enabled: true # H2 Console 사용 여부 | ||
path: /h2-console # H2 Console 접속 주소 | ||
|
||
# Hibernate SQL ?? ?? ?? | ||
logging: | ||
level: | ||
org: | ||
hibernate: | ||
SQL: debug | ||
|
||
devtools: | ||
LiveReload: | ||
enable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ spring: | |
spring: | ||
config: | ||
activate: | ||
on-profile: local, dev, prd | ||
on-profile: local, dev, prd, test |
139 changes: 139 additions & 0 deletions
139
papplan/src/test/java/com/boogle/papplan/service/dashboard/DashBoardServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package com.boogle.papplan.service.dashboard; | ||
|
||
import com.boogle.papplan.dto.project.ProjectDTO; | ||
import com.boogle.papplan.entity.*; | ||
import com.boogle.papplan.repository.*; | ||
import com.boogle.papplan.service.project.ProjectService; | ||
import com.boogle.papplan.service.task.TaskService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.util.Assert; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
import java.time.LocalDate; | ||
import java.util.*; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
public class DashBoardServiceTest { | ||
|
||
@Autowired | ||
private ProjectService projectService; | ||
|
||
@Autowired | ||
private TaskService taskService; | ||
@Autowired | ||
private EmployeeRepository employeeRepository; | ||
@Autowired | ||
private ProjectRepository projectRepository; | ||
@Autowired | ||
private ContributorRepository contributorRepository; | ||
@Autowired | ||
private TaskRepository taskRepository; | ||
|
||
|
||
Employees employees; | ||
Project project; | ||
Contributor contributor; | ||
|
||
List<Task> tasks = new ArrayList<>(); | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@BeforeEach | ||
void beforeEmployee() throws SQLException { | ||
|
||
// given | ||
Calendar calendar = Calendar.getInstance(); | ||
int month = calendar.get(Calendar.MONTH); | ||
|
||
Department department = new Department(); department.setDept_no("PL"); | ||
Position position = new Position(); position.setPosition_id("TEAM_LEADER"); | ||
ProjectPriority projectPriority = new ProjectPriority(); projectPriority.setProjectPriorityId("LV1"); | ||
ProjectStatus projectStatus = new ProjectStatus(); projectStatus.setProjectStatusId("DOING"); | ||
TaskPriority taskPriority = new TaskPriority(); taskPriority.setTaskPriorityId("LV1"); | ||
TaskStatus doing = new TaskStatus(); doing.setTaskStatusId("DOING"); | ||
TaskStatus done = new TaskStatus(); done.setTaskStatusId("DONE"); | ||
|
||
// 회원 추가 | ||
employees = new Employees(1, "test@boogle.com", "1234", "홍길동", department, position); | ||
|
||
// 프로젝트 추가 | ||
project = new Project(1, "테스트 프로젝트", employees, | ||
new GregorianCalendar(2024, month, 1).getTime(), | ||
new GregorianCalendar(2024, month, 25).getTime(), | ||
0, new Date(), "", | ||
projectPriority, projectStatus, new ArrayList<Task>(), new ArrayList<Contributor>()); | ||
contributor = new Contributor(1L,project, employees); | ||
|
||
// 하위업무 추가 | ||
Task task1 = new Task(1, project, "테스크1", employees, | ||
new GregorianCalendar(2024, month, 1).getTime(), | ||
new GregorianCalendar(2024,month, 13).getTime(), | ||
new GregorianCalendar(2024,month,10).getTime(), | ||
100, new GregorianCalendar(2024,month,1).getTime(), | ||
false, "", null, "", done, taskPriority); | ||
Task task2 = new Task(2, project, "테스크2", employees, | ||
new GregorianCalendar(2024, month, 1).getTime(), | ||
new GregorianCalendar(2024,month, 12).getTime(), | ||
new GregorianCalendar(2024,month,10).getTime(), | ||
100, new GregorianCalendar(2024,month,1).getTime(), | ||
false, "", null, "", done, taskPriority); | ||
Task task3 = new Task(3, project, "테스크3", employees, | ||
new GregorianCalendar(2024, month, 1).getTime(), | ||
new GregorianCalendar(2024,month, 12).getTime(), | ||
null, | ||
50, new GregorianCalendar(2024,month,1).getTime(), | ||
false, "", null, "", doing, taskPriority); | ||
tasks.add(task1); tasks.add(task2); tasks.add(task3); | ||
} | ||
|
||
/** | ||
* T006-1 | ||
* 대시보드 집계, 필터링 로직 테스트 | ||
* 테스트를 진행하는 달을 기준으로 값을 비교 | ||
*/ | ||
@Test | ||
@Transactional | ||
@DisplayName("TEST1 - 대시보드 데이터 집계 및 필터링") | ||
public void 대시보드_집계_필터링() { | ||
|
||
// given | ||
int empno = 1; | ||
HashMap<String, Object> serviceResult = new HashMap<>(); | ||
LocalDate today = LocalDate.now(); | ||
int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); | ||
|
||
employeeRepository.save(employees); | ||
projectRepository.save(project); | ||
contributorRepository.save(contributor); | ||
taskRepository.saveAll(tasks); | ||
|
||
// when | ||
Optional<HashMap<String,Object>> projectData = projectService.findProjectsByEmpNoDashBoard(empno); | ||
Optional<HashMap<String,Object>> taskData = taskService.getTasksByEmpNoDashBoard(empno); | ||
projectData.ifPresent(serviceResult::putAll); | ||
taskData.ifPresent(serviceResult::putAll); | ||
|
||
// then | ||
assertThat(serviceResult).isNotNull(); | ||
assertThat((List)serviceResult.get("tasks")).hasSize(1); // DOING 상태인 프로젝트 개수 확인 | ||
assertThat((List)serviceResult.get("projects")).hasSize(1); // DOING 상태인 하위업무 개수 확인 | ||
if(day == 12 || day == 13) | ||
assertThat(serviceResult.get("task_today")).isEqualTo(1); | ||
if((day - 12) == 1 || (day - 13) == 1) | ||
assertThat(serviceResult.get("task_yesterday")).isEqualTo(1); | ||
assertThat(serviceResult.get("task_week")).isIn(0,1,2); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
CREATE TABLE department ( | ||
dept_no VARCHAR(20) NOT NULL, | ||
dept_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (dept_no) | ||
); | ||
|
||
CREATE TABLE job_title ( | ||
position_id VARCHAR(20) NOT NULL, | ||
position_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (position_id) | ||
); | ||
|
||
CREATE TABLE employees ( | ||
eno INTEGER AUTO_INCREMENT PRIMARY KEY, | ||
email VARCHAR(50) NOT NULL UNIQUE, | ||
password VARCHAR(65) NOT NULL, | ||
name VARCHAR(20) NOT NULL, | ||
dept_no VARCHAR(20) NOT NULL, | ||
position_id VARCHAR(20) NOT NULL, | ||
CONSTRAINT fk_dept_no FOREIGN KEY (dept_no) REFERENCES department(dept_no), | ||
CONSTRAINT fk_position_id FOREIGN KEY (position_id) REFERENCES job_title(position_id) | ||
); | ||
|
||
CREATE TABLE project_priority ( | ||
project_priority_id VARCHAR(20) NOT NULL, | ||
project_priority_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (project_priority_id) | ||
); | ||
|
||
CREATE TABLE project_status ( | ||
project_status_id VARCHAR(20) NOT NULL, | ||
project_status_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (project_status_id) | ||
); | ||
|
||
CREATE TABLE project ( | ||
proj_no INTEGER AUTO_INCREMENT PRIMARY KEY, | ||
proj_title VARCHAR(50) NOT NULL, | ||
proj_pm INTEGER NOT NULL, | ||
proj_start_date DATE NOT NULL, | ||
proj_end_date DATE NOT NULL, | ||
proj_percent INTEGER, | ||
proj_create_date DATE NOT NULL, | ||
proj_desc VARCHAR(300) NOT NULL, | ||
projp_no VARCHAR(20) NOT NULL, | ||
projs_no VARCHAR(20) NOT NULL, | ||
FOREIGN KEY (proj_pm) REFERENCES employees (eno), | ||
FOREIGN KEY (projp_no) REFERENCES project_priority (project_priority_id), | ||
FOREIGN KEY (projs_no) REFERENCES project_status (project_status_id) | ||
); | ||
|
||
CREATE TABLE contributor ( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
proj_no INTEGER NOT NULL, | ||
eno INTEGER NOT NULL, | ||
PRIMARY KEY (id), | ||
CONSTRAINT FK_proj_no FOREIGN KEY (proj_no) REFERENCES project (proj_no), | ||
CONSTRAINT FK_eno FOREIGN KEY (eno) REFERENCES employees (eno) | ||
); | ||
|
||
CREATE TABLE task_priority ( | ||
task_priority_id VARCHAR(20) NOT NULL, | ||
task_priority_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (task_priority_id) | ||
); | ||
|
||
CREATE TABLE task_status ( | ||
task_status_id VARCHAR(20) NOT NULL, | ||
task_status_name VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (task_status_id) | ||
); | ||
|
||
CREATE TABLE task ( | ||
task_no INTEGER NOT NULL AUTO_INCREMENT, | ||
proj_no INTEGER NOT NULL, | ||
task_title VARCHAR(50) NOT NULL, | ||
assignee_eno INTEGER NOT NULL, | ||
task_start_date DATE NOT NULL, | ||
task_end_date DATE NOT NULL, | ||
task_finish_date DATE, | ||
task_percent INTEGER NOT NULL, | ||
task_create_date DATE NOT NULL, | ||
task_test BOOLEAN NOT NULL, | ||
task_test_url VARCHAR(255), | ||
task_update_date DATE, | ||
task_desc VARCHAR(300) NOT NULL, | ||
task_status_id VARCHAR(20) NOT NULL, | ||
task_priority_id VARCHAR(20) NOT NULL, | ||
PRIMARY KEY (task_no), | ||
CONSTRAINT FK_proj_no_task FOREIGN KEY (proj_no) REFERENCES project (proj_no), | ||
CONSTRAINT FK_assignee_eno FOREIGN KEY (assignee_eno) REFERENCES employees (eno), | ||
CONSTRAINT FK_task_status_id_task FOREIGN KEY (task_status_id) REFERENCES task_status (task_status_id), | ||
CONSTRAINT FK_task_priority_id_task FOREIGN KEY (task_priority_id) REFERENCES task_priority (task_priority_id) | ||
); |
Binary file modified
BIN
+219 Bytes
(110%)
papplan/target/classes/com/boogle/papplan/entity/Contributor.class
Binary file not shown.
Binary file modified
BIN
+56 Bytes
(100%)
papplan/target/classes/com/boogle/papplan/entity/Department.class
Binary file not shown.
Binary file modified
BIN
+338 Bytes
(110%)
papplan/target/classes/com/boogle/papplan/entity/Employees.class
Binary file not shown.
Binary file modified
BIN
+56 Bytes
(100%)
papplan/target/classes/com/boogle/papplan/entity/Position.class
Binary file not shown.
Binary file modified
BIN
+978 Bytes
(110%)
papplan/target/classes/com/boogle/papplan/entity/Project.class
Binary file not shown.