-
Notifications
You must be signed in to change notification settings - Fork 4
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 #191 from Kernel360/develop
로그 기록, 테스트 코드
- Loading branch information
Showing
50 changed files
with
1,944 additions
and
79 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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/speech/up/common/aspect/LoggingAspect.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,18 @@ | ||
package com.speech.up.common.aspect; | ||
|
||
import org.aspectj.lang.annotation.AfterThrowing; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Aspect | ||
@Component | ||
public class LoggingAspect { | ||
private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class); | ||
|
||
@AfterThrowing(pointcut = "execution(* com.speech.up.user.service.*.*(..))", throwing = "exception") | ||
public void logAfterThrowing(Exception exception) { | ||
logger.error("Exception in method: {}", exception.getMessage(), exception); | ||
} | ||
} |
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,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<!-- DEBUG 레벨 로깅 --> | ||
<appender name="DEBUG_FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>/root/logs/debug.log</file> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeBasedRollingPolicy"> | ||
<maxFileSize>10MB</maxFileSize> <!-- 파일 최대 크기 설정 --> | ||
<fileNamePattern>logs/debug.%i.log</fileNamePattern> <!-- 롤링된 파일 이름 패턴 --> | ||
</rollingPolicy> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
<level>DEBUG</level> | ||
<onMatch>ACCEPT</onMatch> | ||
<onMismatch>DENY</onMismatch> | ||
</filter> | ||
</appender> | ||
|
||
<!-- INFO 레벨 로깅 --> | ||
<appender name="INFO_FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>/root/logs/info.log</file> <!-- 날짜 없이 단일 파일 --> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeBasedRollingPolicy"> | ||
<maxFileSize>10MB</maxFileSize> <!-- 파일 최대 크기 설정 --> | ||
<fileNamePattern>logs/info.%i.log</fileNamePattern> <!-- 롤링된 파일 이름 패턴 --> | ||
</rollingPolicy> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
<level>INFO</level> | ||
<onMatch>ACCEPT</onMatch> | ||
<onMismatch>DENY</onMismatch> | ||
</filter> | ||
</appender> | ||
|
||
<!-- ERROR 레벨 로깅 --> | ||
<appender name="ERROR_FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>/root/logs/error.log</file> <!-- 날짜 없이 단일 파일 --> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeBasedRollingPolicy"> | ||
<maxFileSize>10MB</maxFileSize> <!-- 파일 최대 크기 설정 --> | ||
<fileNamePattern>logs/error.%i.log</fileNamePattern> <!-- 롤링된 파일 이름 패턴 --> | ||
</rollingPolicy> | ||
<encoder> | ||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
<level>ERROR</level> | ||
<onMatch>ACCEPT</onMatch> | ||
<onMismatch>DENY</onMismatch> | ||
</filter> | ||
</appender> | ||
|
||
<!-- 로깅 레벨 설정 --> | ||
<root level="INFO"> | ||
<appender-ref ref="DEBUG_FILE" /> | ||
<appender-ref ref="INFO_FILE" /> | ||
<appender-ref ref="ERROR_FILE" /> | ||
</root> | ||
</configuration> |
100 changes: 100 additions & 0 deletions
100
src/test/java/com/speech/up/admin/controller/AdminControllerTest.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,100 @@ | ||
package com.speech.up.admin.controller; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import com.speech.up.user.repository.UserRepository; | ||
import com.speech.up.user.service.UserService; | ||
import com.speech.up.user.service.dto.UserGetInfoDto; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
public class AdminControllerTest { | ||
|
||
@Mock | ||
UserService userService; | ||
|
||
@Mock | ||
UserRepository userRepository; | ||
|
||
@InjectMocks | ||
AdminController adminController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@DisplayName("사용자 정보 가져오기") | ||
@Test | ||
void getUserTest(){ | ||
//given | ||
//when | ||
List<UserGetInfoDto.Response> actualResponse = adminController.getUser(); | ||
|
||
//then | ||
assertNotNull(actualResponse); | ||
} | ||
|
||
@DisplayName("현재 관리자의 사용자 정보") | ||
@Test | ||
void checkAdminTest(){ | ||
//given | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
|
||
//when | ||
ResponseEntity<UserGetInfoDto.Response> actualResponse = adminController.checkAdmin(request); | ||
|
||
//then | ||
assertNotNull(actualResponse); | ||
} | ||
|
||
@DisplayName("지정된 사용자 ID를 가진 사용자를 삭제") | ||
@Test | ||
void dropUserTest(){ | ||
//given | ||
Long userId = 1L; | ||
|
||
//when | ||
adminController.dropUser(userId); | ||
|
||
//then | ||
verify(userRepository, times(1)).deleteById(userId); | ||
} | ||
|
||
@DisplayName("지정된 사용자 ID를 가진 사용자를 비활성화") | ||
@Test | ||
void unUsedUserTest(){ | ||
//given | ||
Long userId = 1L; | ||
|
||
//when | ||
adminController.unUsedUser(userId); | ||
|
||
//then | ||
verify(userService, times(1)).unUsedUser(userId); | ||
} | ||
|
||
@DisplayName("지정된 사용자 ID를 가진 사용자를 복원") | ||
@Test | ||
void restoreUserTest(){ | ||
//given | ||
Long userId = 1L; | ||
|
||
//when | ||
adminController.restoreUser(userId); | ||
|
||
//then | ||
verify(userService, times(1)).restoreUser(userId); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/speech/up/admin/controller/AdminPageControllerTest.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,28 @@ | ||
package com.speech.up.admin.controller; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
public class AdminPageControllerTest { | ||
|
||
@InjectMocks | ||
AdminPageController adminPageController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@DisplayName("admin 페이지 이동") | ||
@Test | ||
void adminPage() { | ||
String actualResponse = adminPageController.adminPage(); | ||
|
||
assertNotNull(actualResponse); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/speech/up/admin/controller/OpenDataControllerTest.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,35 @@ | ||
package com.speech.up.admin.controller; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import com.speech.up.admin.service.StatisticsService; | ||
|
||
public class OpenDataControllerTest { | ||
|
||
@Mock | ||
StatisticsService statisticsService; | ||
|
||
@InjectMocks | ||
OpenDataController openDataController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@DisplayName("통계 테이블의 가장 최근 데이터를 반환") | ||
@Test | ||
void getStatisticsTest() { | ||
|
||
openDataController.getStatistics(); | ||
|
||
verify(statisticsService, times(1)).getStatistics(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/com/speech/up/api/etri/controller/ETRIApiControllerTest.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,40 @@ | ||
package com.speech.up.api.etri.controller; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import com.speech.up.api.etri.service.VoiceToTextService; | ||
|
||
public class ETRIApiControllerTest { | ||
@Mock | ||
VoiceToTextService voiceToTextService; | ||
|
||
@InjectMocks | ||
ETRIApiController etriApiController; | ||
|
||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@DisplayName("api 호출하기") | ||
@Test | ||
void createTaskTest(){ | ||
//given | ||
String script = "script"; | ||
String recordId = "1"; | ||
|
||
//when | ||
etriApiController.createTask(script, recordId); | ||
|
||
//then | ||
verify(voiceToTextService, times(1)).callRecognitionApi(script, Long.valueOf(recordId)); | ||
} | ||
} |
Oops, something went wrong.