-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add common module * chore: add common module to workflow * feat: add common exception classes * feat: alter DomainException to non abstract class * test: add DomainException unit test * test: add ErrorResponse unit test * chore: fix workflow annotations
- Loading branch information
Showing
11 changed files
with
136 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
|
||
} | ||
|
||
tasks.named('bootJar') { | ||
enabled = false | ||
} | ||
|
||
tasks.named('jar') { | ||
enabled = true | ||
} |
10 changes: 10 additions & 0 deletions
10
common/src/main/java/com/oing/domain/exception/DomainException.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,10 @@ | ||
package com.oing.domain.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class DomainException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/main/java/com/oing/domain/exception/ErrorCode.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,22 @@ | ||
package com.oing.domain.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode { | ||
/** | ||
* Common Errors | ||
*/ | ||
UNKNOWN_SERVER_ERROR("CM0001", "Unknown Server Error"), | ||
INVALID_INPUT_VALUE("CM0002", "Invalid Input Value"), | ||
/** | ||
* Auth Related Errors | ||
*/ | ||
AUTHENTICATION_FAILED("AU0001", "Authentication failed"), | ||
AUTHORIZATION_FAILED("AU0002", "No Permission"); | ||
|
||
private final String code; | ||
private final String message; | ||
} |
21 changes: 21 additions & 0 deletions
21
common/src/main/java/com/oing/dto/response/ErrorResponse.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,21 @@ | ||
package com.oing.dto.response; | ||
|
||
import com.oing.domain.exception.ErrorCode; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Schema(description = "에러 응답") | ||
public record ErrorResponse( | ||
@Schema(description = "에러 코드", example = "AU0001") | ||
String code, | ||
|
||
@Schema(description = "에러 메시지", example = "Authentication failed") | ||
String message | ||
) { | ||
public static ErrorResponse of(String code, String message) { | ||
return new ErrorResponse(code, message); | ||
} | ||
|
||
public static ErrorResponse of(ErrorCode errorCode) { | ||
return new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/test/java/com/oing/domain/exception/DomainExceptionTest.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,22 @@ | ||
package com.oing.domain.exception; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class DomainExceptionTest { | ||
@DisplayName("DomainException 생성자 테스트") | ||
@Test | ||
void testConstructor() { | ||
//given | ||
ErrorCode errorCode = ErrorCode.AUTHENTICATION_FAILED; | ||
|
||
//when | ||
DomainException exception = new DomainException(errorCode); | ||
|
||
//then | ||
assertEquals(exception.getErrorCode(), errorCode); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
common/src/test/java/com/oing/dto/response/ErrorResponseTest.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,38 @@ | ||
package com.oing.dto.response; | ||
|
||
import com.oing.domain.exception.ErrorCode; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ErrorResponseTest { | ||
@DisplayName("ErrorResponse.of(String, String) 메서드 테스트") | ||
@Test | ||
void testOfMethod() { | ||
//given | ||
String errorCode = "AU0001"; | ||
String errorMessage = "Authentication failed"; | ||
|
||
//when | ||
ErrorResponse errorResponse = ErrorResponse.of(errorCode, errorMessage); | ||
|
||
//then | ||
assertEquals(errorResponse.code(), errorCode); | ||
assertEquals(errorResponse.message(), errorMessage); | ||
} | ||
|
||
@DisplayName("ErrorResponse.of(ErrorCode) 메서드 테스트") | ||
@Test | ||
void testOfMethod2() { | ||
//given | ||
ErrorCode errorCode = ErrorCode.AUTHENTICATION_FAILED; | ||
|
||
//when | ||
ErrorResponse errorResponse = ErrorResponse.of(errorCode); | ||
|
||
//then | ||
assertEquals(errorResponse.code(), errorCode.getCode()); | ||
assertEquals(errorResponse.message(), errorCode.getMessage()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ repositories { | |
} | ||
|
||
dependencies { | ||
|
||
implementation project(':common') | ||
} | ||
|
||
tasks.named('bootJar') { | ||
|
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ rootProject.name = 'server' | |
|
||
include 'config' | ||
include 'member' | ||
include 'common' | ||
|