generated from pricelees/issue-pr-template
refactor: RoomescapeException 코틀린 전환
This commit is contained in:
parent
2404eaefca
commit
fd4ca6da56
@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Value
|
|||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -38,12 +38,12 @@ class JwtHandler(
|
|||||||
.toLong()
|
.toLong()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
when (e) {
|
when (e) {
|
||||||
is ExpiredJwtException -> throw RoomEscapeException(ErrorType.EXPIRED_TOKEN, HttpStatus.UNAUTHORIZED)
|
is ExpiredJwtException -> throw RoomescapeException(ErrorType.EXPIRED_TOKEN, HttpStatus.UNAUTHORIZED)
|
||||||
is UnsupportedJwtException -> throw RoomEscapeException(ErrorType.UNSUPPORTED_TOKEN, HttpStatus.UNAUTHORIZED)
|
is UnsupportedJwtException -> throw RoomescapeException(ErrorType.UNSUPPORTED_TOKEN, HttpStatus.UNAUTHORIZED)
|
||||||
is MalformedJwtException -> throw RoomEscapeException(ErrorType.MALFORMED_TOKEN, HttpStatus.UNAUTHORIZED)
|
is MalformedJwtException -> throw RoomescapeException(ErrorType.MALFORMED_TOKEN, HttpStatus.UNAUTHORIZED)
|
||||||
is SignatureException -> throw RoomEscapeException(ErrorType.INVALID_SIGNATURE_TOKEN, HttpStatus.UNAUTHORIZED)
|
is SignatureException -> throw RoomescapeException(ErrorType.INVALID_SIGNATURE_TOKEN, HttpStatus.UNAUTHORIZED)
|
||||||
is IllegalArgumentException -> throw RoomEscapeException(ErrorType.INVALID_TOKEN, HttpStatus.UNAUTHORIZED)
|
is IllegalArgumentException -> throw RoomescapeException(ErrorType.INVALID_TOKEN, HttpStatus.UNAUTHORIZED)
|
||||||
else -> throw RoomEscapeException(ErrorType.UNEXPECTED_ERROR, HttpStatus.INTERNAL_SERVER_ERROR)
|
else -> throw RoomescapeException(ErrorType.UNEXPECTED_ERROR, HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import roomescape.member.business.MemberService
|
|||||||
import roomescape.member.infrastructure.persistence.Member
|
import roomescape.member.infrastructure.persistence.Member
|
||||||
import roomescape.auth.infrastructure.jwt.JwtHandler
|
import roomescape.auth.infrastructure.jwt.JwtHandler
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
|
||||||
private fun Any.isIrrelevantWith(annotationType: Class<out Annotation>): Boolean {
|
private fun Any.isIrrelevantWith(annotationType: Class<out Annotation>): Boolean {
|
||||||
if (this !is HandlerMethod) {
|
if (this !is HandlerMethod) {
|
||||||
@ -40,9 +40,9 @@ class LoginInterceptor(
|
|||||||
val memberId: Long = jwtHandler.getMemberIdFromToken(token)
|
val memberId: Long = jwtHandler.getMemberIdFromToken(token)
|
||||||
|
|
||||||
return memberService.existsById(memberId)
|
return memberService.existsById(memberId)
|
||||||
} catch (e: RoomEscapeException) {
|
} catch (e: RoomescapeException) {
|
||||||
response.sendRedirect("/login")
|
response.sendRedirect("/login")
|
||||||
throw RoomEscapeException(ErrorType.LOGIN_REQUIRED, HttpStatus.FORBIDDEN)
|
throw RoomescapeException(ErrorType.LOGIN_REQUIRED, HttpStatus.FORBIDDEN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ class AdminInterceptor(
|
|||||||
val token: String? = request.accessTokenCookie().value
|
val token: String? = request.accessTokenCookie().value
|
||||||
val memberId: Long = jwtHandler.getMemberIdFromToken(token)
|
val memberId: Long = jwtHandler.getMemberIdFromToken(token)
|
||||||
member = memberService.findById(memberId)
|
member = memberService.findById(memberId)
|
||||||
} catch (e: RoomEscapeException) {
|
} catch (e: RoomescapeException) {
|
||||||
response.sendRedirect("/login")
|
response.sendRedirect("/login")
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ class AdminInterceptor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
response.sendRedirect("/login")
|
response.sendRedirect("/login")
|
||||||
throw RoomEscapeException(
|
throw RoomescapeException(
|
||||||
ErrorType.PERMISSION_DOES_NOT_EXIST,
|
ErrorType.PERMISSION_DOES_NOT_EXIST,
|
||||||
String.format("[memberId: %d, Role: %s]", this.id, this.role),
|
String.format("[memberId: %d, Role: %s]", this.id, this.role),
|
||||||
HttpStatus.FORBIDDEN
|
HttpStatus.FORBIDDEN
|
||||||
|
|||||||
@ -60,7 +60,7 @@ enum class ErrorType(
|
|||||||
fun from(@JsonProperty("errorType") errorType: String): ErrorType {
|
fun from(@JsonProperty("errorType") errorType: String): ErrorType {
|
||||||
return entries.toTypedArray()
|
return entries.toTypedArray()
|
||||||
.firstOrNull { it.name == errorType }
|
.firstOrNull { it.name == errorType }
|
||||||
?: throw RoomEscapeException(
|
?: throw RoomescapeException(
|
||||||
INVALID_REQUEST_DATA,
|
INVALID_REQUEST_DATA,
|
||||||
"[ErrorType: ${errorType}]",
|
"[ErrorType: ${errorType}]",
|
||||||
HttpStatus.BAD_REQUEST
|
HttpStatus.BAD_REQUEST
|
||||||
|
|||||||
@ -22,9 +22,9 @@ public class ExceptionControllerAdvice {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@ExceptionHandler(value = {RoomEscapeException.class})
|
@ExceptionHandler(value = {RoomescapeException.class})
|
||||||
public ErrorResponse handleRoomEscapeException(RoomEscapeException e, HttpServletResponse response) {
|
public ErrorResponse handleRoomEscapeException(RoomescapeException e, HttpServletResponse response) {
|
||||||
logger.error("{}{}", e.getMessage(), e.getInvalidValue().orElse(""), e);
|
logger.error("{}{}", e.getMessage(), e.getInvalidValue(), e);
|
||||||
response.setStatus(e.getHttpStatus().value());
|
response.setStatus(e.getHttpStatus().value());
|
||||||
return ErrorResponse.of(e.getErrorType(), e.getMessage());
|
return ErrorResponse.of(e.getErrorType(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,41 +1,11 @@
|
|||||||
package roomescape.common.exception;
|
package roomescape.common.exception
|
||||||
|
|
||||||
import java.util.Optional;
|
import org.springframework.http.HttpStatusCode
|
||||||
|
|
||||||
import org.springframework.http.HttpStatusCode;
|
class RoomescapeException(
|
||||||
|
val errorType: ErrorType,
|
||||||
public class RoomEscapeException extends RuntimeException {
|
val invalidValue: String? = "",
|
||||||
|
val httpStatus: HttpStatusCode,
|
||||||
private final ErrorType errorType;
|
) : RuntimeException(errorType.description) {
|
||||||
private final String message;
|
constructor(errorType: ErrorType, httpStatus: HttpStatusCode) : this(errorType, null, httpStatus)
|
||||||
private final String invalidValue;
|
|
||||||
private final HttpStatusCode httpStatus;
|
|
||||||
|
|
||||||
public RoomEscapeException(ErrorType errorType, HttpStatusCode httpStatus) {
|
|
||||||
this(errorType, null, httpStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoomEscapeException(ErrorType errorType, String invalidValue, HttpStatusCode httpStatus) {
|
|
||||||
this.errorType = errorType;
|
|
||||||
this.message = errorType.description;
|
|
||||||
this.invalidValue = invalidValue;
|
|
||||||
this.httpStatus = httpStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ErrorType getErrorType() {
|
|
||||||
return errorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpStatusCode getHttpStatus() {
|
|
||||||
return httpStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getInvalidValue() {
|
|
||||||
return Optional.ofNullable(invalidValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import roomescape.member.infrastructure.persistence.MemberRepository
|
|||||||
import roomescape.member.web.MembersResponse
|
import roomescape.member.web.MembersResponse
|
||||||
import roomescape.member.web.toResponse
|
import roomescape.member.web.toResponse
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
@ -23,7 +23,7 @@ class MemberService(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun findById(memberId: Long): Member = memberRepository.findByIdOrNull(memberId)
|
fun findById(memberId: Long): Member = memberRepository.findByIdOrNull(memberId)
|
||||||
?: throw RoomEscapeException(
|
?: throw RoomescapeException(
|
||||||
ErrorType.MEMBER_NOT_FOUND,
|
ErrorType.MEMBER_NOT_FOUND,
|
||||||
String.format("[memberId: %d]", memberId),
|
String.format("[memberId: %d]", memberId),
|
||||||
HttpStatus.BAD_REQUEST
|
HttpStatus.BAD_REQUEST
|
||||||
@ -31,7 +31,7 @@ class MemberService(
|
|||||||
|
|
||||||
fun findMemberByEmailAndPassword(email: String, password: String): Member =
|
fun findMemberByEmailAndPassword(email: String, password: String): Member =
|
||||||
memberRepository.findByEmailAndPassword(email, password)
|
memberRepository.findByEmailAndPassword(email, password)
|
||||||
?: throw RoomEscapeException(
|
?: throw RoomescapeException(
|
||||||
ErrorType.MEMBER_NOT_FOUND,
|
ErrorType.MEMBER_NOT_FOUND,
|
||||||
String.format("[email: %s, password: %s]", email, password),
|
String.format("[email: %s, password: %s]", email, password),
|
||||||
HttpStatus.BAD_REQUEST
|
HttpStatus.BAD_REQUEST
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import roomescape.payment.dto.response.PaymentCancelResponse;
|
|||||||
import roomescape.payment.dto.response.PaymentResponse;
|
import roomescape.payment.dto.response.PaymentResponse;
|
||||||
import roomescape.payment.dto.response.TossPaymentErrorResponse;
|
import roomescape.payment.dto.response.TossPaymentErrorResponse;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class TossPaymentClient {
|
public class TossPaymentClient {
|
||||||
@ -76,7 +76,7 @@ public class TossPaymentClient {
|
|||||||
ErrorType errorType = getErrorTypeByStatusCode(statusCode);
|
ErrorType errorType = getErrorTypeByStatusCode(statusCode);
|
||||||
TossPaymentErrorResponse errorResponse = getErrorResponse(res);
|
TossPaymentErrorResponse errorResponse = getErrorResponse(res);
|
||||||
|
|
||||||
throw new RoomEscapeException(errorType,
|
throw new RoomescapeException(errorType,
|
||||||
String.format("[ErrorCode = %s, ErrorMessage = %s]", errorResponse.code(), errorResponse.message()),
|
String.format("[ErrorCode = %s, ErrorMessage = %s]", errorResponse.code(), errorResponse.message()),
|
||||||
statusCode);
|
statusCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class CanceledPayment {
|
public class CanceledPayment {
|
||||||
@ -39,7 +39,7 @@ public class CanceledPayment {
|
|||||||
|
|
||||||
private void validateDate(OffsetDateTime approvedAt, OffsetDateTime canceledAt) {
|
private void validateDate(OffsetDateTime approvedAt, OffsetDateTime canceledAt) {
|
||||||
if (canceledAt.isBefore(approvedAt)) {
|
if (canceledAt.isBefore(approvedAt)) {
|
||||||
throw new RoomEscapeException(ErrorType.CANCELED_BEFORE_PAYMENT,
|
throw new RoomescapeException(ErrorType.CANCELED_BEFORE_PAYMENT,
|
||||||
String.format("[approvedAt: %s, canceledAt: %s]", approvedAt, canceledAt),
|
String.format("[approvedAt: %s, canceledAt: %s]", approvedAt, canceledAt),
|
||||||
HttpStatus.CONFLICT);
|
HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import jakarta.persistence.JoinColumn;
|
|||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Payment {
|
public class Payment {
|
||||||
@ -63,21 +63,21 @@ public class Payment {
|
|||||||
|
|
||||||
private void validateIsNullOrBlank(String input, String fieldName) {
|
private void validateIsNullOrBlank(String input, String fieldName) {
|
||||||
if (input == null || input.isBlank()) {
|
if (input == null || input.isBlank()) {
|
||||||
throw new RoomEscapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[value : %s]", fieldName),
|
throw new RoomescapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[value : %s]", fieldName),
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateIsInvalidAmount(Long totalAmount) {
|
private void validateIsInvalidAmount(Long totalAmount) {
|
||||||
if (totalAmount == null || totalAmount < 0) {
|
if (totalAmount == null || totalAmount < 0) {
|
||||||
throw new RoomEscapeException(ErrorType.INVALID_REQUEST_DATA,
|
throw new RoomescapeException(ErrorType.INVALID_REQUEST_DATA,
|
||||||
String.format("[totalAmount : %d]", totalAmount), HttpStatus.BAD_REQUEST);
|
String.format("[totalAmount : %d]", totalAmount), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void validateIsNull(T value, String fieldName) {
|
private <T> void validateIsNull(T value, String fieldName) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new RoomEscapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[value : %s]", fieldName),
|
throw new RoomescapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[value : %s]", fieldName),
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import roomescape.payment.dto.response.PaymentResponse;
|
|||||||
import roomescape.payment.dto.response.ReservationPaymentResponse;
|
import roomescape.payment.dto.response.ReservationPaymentResponse;
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -50,7 +50,7 @@ public class PaymentService {
|
|||||||
|
|
||||||
public PaymentCancelRequest cancelPaymentByAdmin(Long reservationId) {
|
public PaymentCancelRequest cancelPaymentByAdmin(Long reservationId) {
|
||||||
String paymentKey = findPaymentByReservationId(reservationId)
|
String paymentKey = findPaymentByReservationId(reservationId)
|
||||||
.orElseThrow(() -> new RoomEscapeException(ErrorType.PAYMENT_NOT_POUND,
|
.orElseThrow(() -> new RoomescapeException(ErrorType.PAYMENT_NOT_POUND,
|
||||||
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
|
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
|
||||||
.getPaymentKey();
|
.getPaymentKey();
|
||||||
// 취소 시간은 현재 시간으로 일단 생성한 뒤, 결제 취소 완료 후 해당 시간으로 변경합니다.
|
// 취소 시간은 현재 시간으로 일단 생성한 뒤, 결제 취소 완료 후 해당 시간으로 변경합니다.
|
||||||
@ -74,8 +74,8 @@ public class PaymentService {
|
|||||||
canceledPayment.setCanceledAt(canceledAt);
|
canceledPayment.setCanceledAt(canceledAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RoomEscapeException throwPaymentNotFoundByPaymentKey(String paymentKey) {
|
private RoomescapeException throwPaymentNotFoundByPaymentKey(String paymentKey) {
|
||||||
return new RoomEscapeException(
|
return new RoomescapeException(
|
||||||
ErrorType.PAYMENT_NOT_POUND, String.format("[paymentKey: %s]", paymentKey),
|
ErrorType.PAYMENT_NOT_POUND, String.format("[paymentKey: %s]", paymentKey),
|
||||||
HttpStatus.NOT_FOUND);
|
HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ import roomescape.auth.web.support.LoginRequired;
|
|||||||
import roomescape.auth.web.support.MemberId;
|
import roomescape.auth.web.support.MemberId;
|
||||||
import roomescape.common.dto.response.ErrorResponse;
|
import roomescape.common.dto.response.ErrorResponse;
|
||||||
import roomescape.common.dto.response.RoomEscapeApiResponse;
|
import roomescape.common.dto.response.RoomEscapeApiResponse;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@Tag(name = "3. 예약 API", description = "예약 및 대기 정보를 추가 / 조회 / 삭제할 때 사용합니다.")
|
@Tag(name = "3. 예약 API", description = "예약 및 대기 정보를 추가 / 조회 / 삭제할 때 사용합니다.")
|
||||||
@ -151,7 +151,7 @@ public class ReservationController {
|
|||||||
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
||||||
reservationRequest, paymentResponse, memberId);
|
reservationRequest, paymentResponse, memberId);
|
||||||
return getCreatedReservationResponse(reservationResponse, response);
|
return getCreatedReservationResponse(reservationResponse, response);
|
||||||
} catch (RoomEscapeException e) {
|
} catch (RoomescapeException e) {
|
||||||
PaymentCancelRequest cancelRequest = new PaymentCancelRequest(paymentRequest.paymentKey(),
|
PaymentCancelRequest cancelRequest = new PaymentCancelRequest(paymentRequest.paymentKey(),
|
||||||
paymentRequest.amount(), e.getMessage());
|
paymentRequest.amount(), e.getMessage());
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import jakarta.persistence.JoinColumn;
|
|||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import roomescape.member.infrastructure.persistence.Member;
|
import roomescape.member.infrastructure.persistence.Member;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -77,7 +77,7 @@ public class Reservation {
|
|||||||
private void validateIsNull(LocalDate date, ReservationTime reservationTime, Theme theme, Member member,
|
private void validateIsNull(LocalDate date, ReservationTime reservationTime, Theme theme, Member member,
|
||||||
ReservationStatus reservationStatus) {
|
ReservationStatus reservationStatus) {
|
||||||
if (date == null || reservationTime == null || theme == null || member == null || reservationStatus == null) {
|
if (date == null || reservationTime == null || theme == null || member == null || reservationStatus == null) {
|
||||||
throw new RoomEscapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[values: %s]", this),
|
throw new RoomescapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[values: %s]", this),
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class ReservationTime {
|
public class ReservationTime {
|
||||||
@ -36,7 +36,7 @@ public class ReservationTime {
|
|||||||
|
|
||||||
private void validateNull() {
|
private void validateNull() {
|
||||||
if (startAt == null) {
|
if (startAt == null) {
|
||||||
throw new RoomEscapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[values: %s]", this),
|
throw new RoomescapeException(ErrorType.REQUEST_DATA_BLANK, String.format("[values: %s]", this),
|
||||||
HttpStatus.BAD_REQUEST);
|
HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Schema(name = "예약 시간 저장 요청", description = "예약 시간 저장 요청시 사용됩니다.")
|
@Schema(name = "예약 시간 저장 요청", description = "예약 시간 저장 요청시 사용됩니다.")
|
||||||
public record ReservationTimeRequest(
|
public record ReservationTimeRequest(
|
||||||
@ -20,7 +20,7 @@ public record ReservationTimeRequest(
|
|||||||
|
|
||||||
public ReservationTimeRequest {
|
public ReservationTimeRequest {
|
||||||
if (StringUtils.isBlank(startAt.toString())) {
|
if (StringUtils.isBlank(startAt.toString())) {
|
||||||
throw new RoomEscapeException(ErrorType.REQUEST_DATA_BLANK,
|
throw new RoomescapeException(ErrorType.REQUEST_DATA_BLANK,
|
||||||
String.format("[values: %s]", this), HttpStatus.BAD_REQUEST);
|
String.format("[values: %s]", this), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import roomescape.reservation.dto.response.MyReservationsResponse;
|
|||||||
import roomescape.reservation.dto.response.ReservationResponse;
|
import roomescape.reservation.dto.response.ReservationResponse;
|
||||||
import roomescape.reservation.dto.response.ReservationsResponse;
|
import roomescape.reservation.dto.response.ReservationsResponse;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.service.ThemeService;
|
import roomescape.theme.service.ThemeService;
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public class ReservationService {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (reservationRepository.exists(spec)) {
|
if (reservationRepository.exists(spec)) {
|
||||||
throw new RoomEscapeException(ErrorType.HAS_RESERVATION_OR_WAITING, HttpStatus.BAD_REQUEST);
|
throw new RoomescapeException(ErrorType.HAS_RESERVATION_OR_WAITING, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ public class ReservationService {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (reservationRepository.exists(spec)) {
|
if (reservationRepository.exists(spec)) {
|
||||||
throw new RoomEscapeException(ErrorType.RESERVATION_DUPLICATED, HttpStatus.CONFLICT);
|
throw new RoomescapeException(ErrorType.RESERVATION_DUPLICATED, HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public class ReservationService {
|
|||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
LocalDateTime request = LocalDateTime.of(requestDate, requestReservationTime.getStartAt());
|
LocalDateTime request = LocalDateTime.of(requestDate, requestReservationTime.getStartAt());
|
||||||
if (request.isBefore(now)) {
|
if (request.isBefore(now)) {
|
||||||
throw new RoomEscapeException(ErrorType.RESERVATION_PERIOD_IN_PAST,
|
throw new RoomescapeException(ErrorType.RESERVATION_PERIOD_IN_PAST,
|
||||||
String.format("[now: %s %s | request: %s %s]",
|
String.format("[now: %s %s | request: %s %s]",
|
||||||
now.toLocalDate(), now.toLocalTime(), requestDate, requestReservationTime.getStartAt()),
|
now.toLocalDate(), now.toLocalTime(), requestDate, requestReservationTime.getStartAt()),
|
||||||
HttpStatus.BAD_REQUEST
|
HttpStatus.BAD_REQUEST
|
||||||
@ -178,7 +178,7 @@ public class ReservationService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (startFrom.isAfter(endAt)) {
|
if (startFrom.isAfter(endAt)) {
|
||||||
throw new RoomEscapeException(ErrorType.INVALID_DATE_RANGE,
|
throw new RoomescapeException(ErrorType.INVALID_DATE_RANGE,
|
||||||
String.format("[startFrom: %s, endAt: %s", startFrom, endAt), HttpStatus.BAD_REQUEST);
|
String.format("[startFrom: %s, endAt: %s", startFrom, endAt), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ public class ReservationService {
|
|||||||
public void approveWaiting(Long reservationId, Long memberId) {
|
public void approveWaiting(Long reservationId, Long memberId) {
|
||||||
validateIsMemberAdmin(memberId);
|
validateIsMemberAdmin(memberId);
|
||||||
if (reservationRepository.isExistConfirmedReservation(reservationId)) {
|
if (reservationRepository.isExistConfirmedReservation(reservationId)) {
|
||||||
throw new RoomEscapeException(ErrorType.RESERVATION_DUPLICATED, HttpStatus.CONFLICT);
|
throw new RoomescapeException(ErrorType.RESERVATION_DUPLICATED, HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
reservationRepository.updateStatusByReservationId(reservationId, ReservationStatus.CONFIRMED_PAYMENT_REQUIRED);
|
reservationRepository.updateStatusByReservationId(reservationId, ReservationStatus.CONFIRMED_PAYMENT_REQUIRED);
|
||||||
}
|
}
|
||||||
@ -217,11 +217,11 @@ public class ReservationService {
|
|||||||
if (member.isAdmin()) {
|
if (member.isAdmin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new RoomEscapeException(ErrorType.PERMISSION_DOES_NOT_EXIST, HttpStatus.FORBIDDEN);
|
throw new RoomescapeException(ErrorType.PERMISSION_DOES_NOT_EXIST, HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RoomEscapeException throwReservationNotFound(Long reservationId) {
|
private RoomescapeException throwReservationNotFound(Long reservationId) {
|
||||||
return new RoomEscapeException(ErrorType.RESERVATION_NOT_FOUND,
|
return new RoomescapeException(ErrorType.RESERVATION_NOT_FOUND,
|
||||||
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND);
|
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import roomescape.reservation.dto.response.ReservationTimeInfosResponse;
|
|||||||
import roomescape.reservation.dto.response.ReservationTimeResponse;
|
import roomescape.reservation.dto.response.ReservationTimeResponse;
|
||||||
import roomescape.reservation.dto.response.ReservationTimesResponse;
|
import roomescape.reservation.dto.response.ReservationTimesResponse;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -37,7 +37,7 @@ public class ReservationTimeService {
|
|||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public ReservationTime findTimeById(Long id) {
|
public ReservationTime findTimeById(Long id) {
|
||||||
return reservationTimeRepository.findById(id)
|
return reservationTimeRepository.findById(id)
|
||||||
.orElseThrow(() -> new RoomEscapeException(ErrorType.RESERVATION_TIME_NOT_FOUND,
|
.orElseThrow(() -> new RoomescapeException(ErrorType.RESERVATION_TIME_NOT_FOUND,
|
||||||
String.format("[reservationTimeId: %d]", id), HttpStatus.BAD_REQUEST));
|
String.format("[reservationTimeId: %d]", id), HttpStatus.BAD_REQUEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class ReservationTimeService {
|
|||||||
reservationTimeRequest.startAt());
|
reservationTimeRequest.startAt());
|
||||||
|
|
||||||
if (!duplicateReservationTimes.isEmpty()) {
|
if (!duplicateReservationTimes.isEmpty()) {
|
||||||
throw new RoomEscapeException(ErrorType.TIME_DUPLICATED,
|
throw new RoomescapeException(ErrorType.TIME_DUPLICATED,
|
||||||
String.format("[startAt: %s]", reservationTimeRequest.startAt()), HttpStatus.CONFLICT);
|
String.format("[startAt: %s]", reservationTimeRequest.startAt()), HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public class ReservationTimeService {
|
|||||||
List<Reservation> usingTimeReservations = reservationRepository.findByReservationTime(reservationTime);
|
List<Reservation> usingTimeReservations = reservationRepository.findByReservationTime(reservationTime);
|
||||||
|
|
||||||
if (!usingTimeReservations.isEmpty()) {
|
if (!usingTimeReservations.isEmpty()) {
|
||||||
throw new RoomEscapeException(ErrorType.TIME_IS_USED_CONFLICT, String.format("[timeId: %d]", id),
|
throw new RoomescapeException(ErrorType.TIME_IS_USED_CONFLICT, String.format("[timeId: %d]", id),
|
||||||
HttpStatus.CONFLICT);
|
HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import roomescape.reservation.domain.repository.ReservationRepository;
|
import roomescape.reservation.domain.repository.ReservationRepository;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.domain.repository.ThemeRepository;
|
import roomescape.theme.domain.repository.ThemeRepository;
|
||||||
import roomescape.theme.dto.ThemeRequest;
|
import roomescape.theme.dto.ThemeRequest;
|
||||||
@ -31,7 +31,7 @@ public class ThemeService {
|
|||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Theme findThemeById(Long id) {
|
public Theme findThemeById(Long id) {
|
||||||
return themeRepository.findById(id)
|
return themeRepository.findById(id)
|
||||||
.orElseThrow(() -> new RoomEscapeException(ErrorType.THEME_NOT_FOUND,
|
.orElseThrow(() -> new RoomescapeException(ErrorType.THEME_NOT_FOUND,
|
||||||
String.format("[themeId: %d]", id), HttpStatus.BAD_REQUEST));
|
String.format("[themeId: %d]", id), HttpStatus.BAD_REQUEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,14 +69,14 @@ public class ThemeService {
|
|||||||
|
|
||||||
private void validateIsSameThemeNameExist(String name) {
|
private void validateIsSameThemeNameExist(String name) {
|
||||||
if (themeRepository.existsByName(name)) {
|
if (themeRepository.existsByName(name)) {
|
||||||
throw new RoomEscapeException(ErrorType.THEME_DUPLICATED,
|
throw new RoomescapeException(ErrorType.THEME_DUPLICATED,
|
||||||
String.format("[name: %s]", name), HttpStatus.CONFLICT);
|
String.format("[name: %s]", name), HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeThemeById(Long id) {
|
public void removeThemeById(Long id) {
|
||||||
if (themeRepository.isReservedTheme(id)) {
|
if (themeRepository.isReservedTheme(id)) {
|
||||||
throw new RoomEscapeException(ErrorType.THEME_IS_USED_CONFLICT,
|
throw new RoomescapeException(ErrorType.THEME_IS_USED_CONFLICT,
|
||||||
String.format("[themeId: %d]", id), HttpStatus.CONFLICT);
|
String.format("[themeId: %d]", id), HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
themeRepository.deleteById(id);
|
themeRepository.deleteById(id);
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import roomescape.member.infrastructure.persistence.MemberRepository
|
|||||||
import roomescape.auth.infrastructure.jwt.JwtHandler
|
import roomescape.auth.infrastructure.jwt.JwtHandler
|
||||||
import roomescape.auth.service.AuthService
|
import roomescape.auth.service.AuthService
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
|
||||||
|
|
||||||
class AuthServiceTest : BehaviorSpec({
|
class AuthServiceTest : BehaviorSpec({
|
||||||
@ -46,7 +46,7 @@ class AuthServiceTest : BehaviorSpec({
|
|||||||
memberRepository.findByEmailAndPassword(request.email, request.password)
|
memberRepository.findByEmailAndPassword(request.email, request.password)
|
||||||
} returns null
|
} returns null
|
||||||
|
|
||||||
val exception = shouldThrow<RoomEscapeException> {
|
val exception = shouldThrow<RoomescapeException> {
|
||||||
authService.login(request)
|
authService.login(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class AuthServiceTest : BehaviorSpec({
|
|||||||
Then("회원이 없다면 예외를 던진다.") {
|
Then("회원이 없다면 예외를 던진다.") {
|
||||||
every { memberRepository.findByIdOrNull(userId) } returns null
|
every { memberRepository.findByIdOrNull(userId) } returns null
|
||||||
|
|
||||||
val exception = shouldThrow<RoomEscapeException> {
|
val exception = shouldThrow<RoomescapeException> {
|
||||||
authService.checkLogin(userId)
|
authService.checkLogin(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,9 @@ import io.jsonwebtoken.SignatureAlgorithm
|
|||||||
import io.kotest.assertions.throwables.shouldThrow
|
import io.kotest.assertions.throwables.shouldThrow
|
||||||
import io.kotest.core.spec.style.FunSpec
|
import io.kotest.core.spec.style.FunSpec
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import roomescape.auth.infrastructure.jwt.JwtHandler
|
|
||||||
import roomescape.util.JwtFixture
|
import roomescape.util.JwtFixture
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@ -34,13 +33,13 @@ class JwtHandlerTest : FunSpec({
|
|||||||
Thread.sleep(expirationTime) // 만료 시간 이후로 대기
|
Thread.sleep(expirationTime) // 만료 시간 이후로 대기
|
||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
shouldThrow<RoomEscapeException> {
|
shouldThrow<RoomescapeException> {
|
||||||
shortExpirationTimeJwtHandler.getMemberIdFromToken(token)
|
shortExpirationTimeJwtHandler.getMemberIdFromToken(token)
|
||||||
}.errorType shouldBe ErrorType.EXPIRED_TOKEN
|
}.errorType shouldBe ErrorType.EXPIRED_TOKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
test("토큰이 빈 값이면 예외를 던진다.") {
|
test("토큰이 빈 값이면 예외를 던진다.") {
|
||||||
shouldThrow<RoomEscapeException> {
|
shouldThrow<RoomescapeException> {
|
||||||
jwtHandler.getMemberIdFromToken("")
|
jwtHandler.getMemberIdFromToken("")
|
||||||
}.errorType shouldBe ErrorType.INVALID_TOKEN
|
}.errorType shouldBe ErrorType.INVALID_TOKEN
|
||||||
}
|
}
|
||||||
@ -54,7 +53,7 @@ class JwtHandlerTest : FunSpec({
|
|||||||
.signWith(SignatureAlgorithm.HS256, JwtFixture.SECRET_KEY.substring(1).toByteArray())
|
.signWith(SignatureAlgorithm.HS256, JwtFixture.SECRET_KEY.substring(1).toByteArray())
|
||||||
.compact()
|
.compact()
|
||||||
|
|
||||||
shouldThrow<RoomEscapeException> {
|
shouldThrow<RoomescapeException> {
|
||||||
jwtHandler.getMemberIdFromToken(invalidSignatureToken)
|
jwtHandler.getMemberIdFromToken(invalidSignatureToken)
|
||||||
}.errorType shouldBe ErrorType.INVALID_SIGNATURE_TOKEN
|
}.errorType shouldBe ErrorType.INVALID_SIGNATURE_TOKEN
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,8 +5,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
|||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
|
||||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
|
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -21,7 +19,7 @@ import roomescape.payment.dto.request.PaymentRequest;
|
|||||||
import roomescape.payment.dto.response.PaymentCancelResponse;
|
import roomescape.payment.dto.response.PaymentCancelResponse;
|
||||||
import roomescape.payment.dto.response.PaymentResponse;
|
import roomescape.payment.dto.response.PaymentResponse;
|
||||||
import roomescape.common.exception.ErrorType;
|
import roomescape.common.exception.ErrorType;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
@RestClientTest(TossPaymentClient.class)
|
@RestClientTest(TossPaymentClient.class)
|
||||||
class TossPaymentClientTest {
|
class TossPaymentClientTest {
|
||||||
@ -88,10 +86,10 @@ class TossPaymentClientTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> tossPaymentClient.confirmPayment(SampleTossPaymentConst.paymentRequest))
|
assertThatThrownBy(() -> tossPaymentClient.confirmPayment(SampleTossPaymentConst.paymentRequest))
|
||||||
.isInstanceOf(RoomEscapeException.class)
|
.isInstanceOf(RoomescapeException.class)
|
||||||
.hasFieldOrPropertyWithValue("errorType", ErrorType.PAYMENT_ERROR)
|
.hasFieldOrPropertyWithValue("errorType", ErrorType.PAYMENT_ERROR)
|
||||||
.hasFieldOrPropertyWithValue("invalidValue",
|
.hasFieldOrPropertyWithValue("invalidValue",
|
||||||
Optional.of("[ErrorCode = ERROR_CODE, ErrorMessage = Error message]"))
|
"[ErrorCode = ERROR_CODE, ErrorMessage = Error message]")
|
||||||
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.BAD_REQUEST);
|
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,10 +107,10 @@ class TossPaymentClientTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> tossPaymentClient.cancelPayment(SampleTossPaymentConst.cancelRequest))
|
assertThatThrownBy(() -> tossPaymentClient.cancelPayment(SampleTossPaymentConst.cancelRequest))
|
||||||
.isInstanceOf(RoomEscapeException.class)
|
.isInstanceOf(RoomescapeException.class)
|
||||||
.hasFieldOrPropertyWithValue("errorType", ErrorType.PAYMENT_SERVER_ERROR)
|
.hasFieldOrPropertyWithValue("errorType", ErrorType.PAYMENT_SERVER_ERROR)
|
||||||
.hasFieldOrPropertyWithValue("invalidValue",
|
.hasFieldOrPropertyWithValue("invalidValue",
|
||||||
Optional.of("[ErrorCode = ERROR_CODE, ErrorMessage = Error message]"))
|
"[ErrorCode = ERROR_CODE, ErrorMessage = Error message]")
|
||||||
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.INTERNAL_SERVER_ERROR);
|
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import java.time.OffsetDateTime;
|
|||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
class CanceledPaymentTest {
|
class CanceledPaymentTest {
|
||||||
|
|
||||||
@ -17,6 +17,6 @@ class CanceledPaymentTest {
|
|||||||
OffsetDateTime approvedAt = OffsetDateTime.now();
|
OffsetDateTime approvedAt = OffsetDateTime.now();
|
||||||
OffsetDateTime canceledAt = approvedAt.minusMinutes(1L);
|
OffsetDateTime canceledAt = approvedAt.minusMinutes(1L);
|
||||||
assertThatThrownBy(() -> new CanceledPayment("payment-key", "reason", 10000L, approvedAt, canceledAt))
|
assertThatThrownBy(() -> new CanceledPayment("payment-key", "reason", 10000L, approvedAt, canceledAt))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ import roomescape.member.infrastructure.persistence.Role;
|
|||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.reservation.domain.ReservationStatus;
|
import roomescape.reservation.domain.ReservationStatus;
|
||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
|
|
||||||
class PaymentTest {
|
class PaymentTest {
|
||||||
@ -40,7 +40,7 @@ class PaymentTest {
|
|||||||
@NullAndEmptySource
|
@NullAndEmptySource
|
||||||
void invalidPaymentKey(String paymentKey) {
|
void invalidPaymentKey(String paymentKey) {
|
||||||
assertThatThrownBy(() -> new Payment("order-id", paymentKey, 10000L, reservation, OffsetDateTime.now()))
|
assertThatThrownBy(() -> new Payment("order-id", paymentKey, 10000L, reservation, OffsetDateTime.now()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ -48,7 +48,7 @@ class PaymentTest {
|
|||||||
@NullAndEmptySource
|
@NullAndEmptySource
|
||||||
void invalidOrderId(String orderId) {
|
void invalidOrderId(String orderId) {
|
||||||
assertThatThrownBy(() -> new Payment(orderId, "payment-key", 10000L, reservation, OffsetDateTime.now()))
|
assertThatThrownBy(() -> new Payment(orderId, "payment-key", 10000L, reservation, OffsetDateTime.now()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ -57,7 +57,7 @@ class PaymentTest {
|
|||||||
void invalidOrderId(Long totalAmount) {
|
void invalidOrderId(Long totalAmount) {
|
||||||
assertThatThrownBy(
|
assertThatThrownBy(
|
||||||
() -> new Payment("orderId", "payment-key", totalAmount, reservation, OffsetDateTime.now()))
|
() -> new Payment("orderId", "payment-key", totalAmount, reservation, OffsetDateTime.now()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ -65,7 +65,7 @@ class PaymentTest {
|
|||||||
@NullSource
|
@NullSource
|
||||||
void invalidReservation(Reservation reservation) {
|
void invalidReservation(Reservation reservation) {
|
||||||
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, OffsetDateTime.now()))
|
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, OffsetDateTime.now()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ -73,6 +73,6 @@ class PaymentTest {
|
|||||||
@NullSource
|
@NullSource
|
||||||
void invalidApprovedAt(OffsetDateTime approvedAt) {
|
void invalidApprovedAt(OffsetDateTime approvedAt) {
|
||||||
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, approvedAt))
|
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, approvedAt))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import roomescape.reservation.domain.ReservationStatus;
|
|||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
import roomescape.reservation.domain.repository.ReservationRepository;
|
import roomescape.reservation.domain.repository.ReservationRepository;
|
||||||
import roomescape.reservation.domain.repository.ReservationTimeRepository;
|
import roomescape.reservation.domain.repository.ReservationTimeRepository;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.domain.repository.ThemeRepository;
|
import roomescape.theme.domain.repository.ThemeRepository;
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class PaymentServiceTest {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
assertThatThrownBy(() -> paymentService.cancelPaymentByAdmin(nonExistentReservationId))
|
assertThatThrownBy(() -> paymentService.cancelPaymentByAdmin(nonExistentReservationId))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -136,6 +136,6 @@ class PaymentServiceTest {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
assertThatThrownBy(() -> paymentService.updateCanceledTime("non-existent-payment-key", canceledAt))
|
assertThatThrownBy(() -> paymentService.updateCanceledTime("non-existent-payment-key", canceledAt))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
|||||||
|
|
||||||
import roomescape.member.infrastructure.persistence.Member;
|
import roomescape.member.infrastructure.persistence.Member;
|
||||||
import roomescape.member.infrastructure.persistence.Role;
|
import roomescape.member.infrastructure.persistence.Role;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
|
|
||||||
public class ReservationTest {
|
public class ReservationTest {
|
||||||
@ -26,7 +26,7 @@ public class ReservationTest {
|
|||||||
// when & then
|
// when & then
|
||||||
Assertions.assertThatThrownBy(
|
Assertions.assertThatThrownBy(
|
||||||
() -> new Reservation(date, reservationTime, theme, member, ReservationStatus.CONFIRMED))
|
() -> new Reservation(date, reservationTime, theme, member, ReservationStatus.CONFIRMED))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Stream<Arguments> validateConstructorParameterBlankSource() {
|
static Stream<Arguments> validateConstructorParameterBlankSource() {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import org.assertj.core.api.Assertions;
|
|||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
|
|
||||||
class ReservationTimeTest {
|
class ReservationTimeTest {
|
||||||
|
|
||||||
@ -14,6 +14,6 @@ class ReservationTimeTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
Assertions.assertThatThrownBy(() -> new ReservationTime(null))
|
Assertions.assertThatThrownBy(() -> new ReservationTime(null))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import roomescape.reservation.domain.repository.ReservationTimeRepository;
|
|||||||
import roomescape.reservation.dto.request.ReservationRequest;
|
import roomescape.reservation.dto.request.ReservationRequest;
|
||||||
import roomescape.reservation.dto.request.WaitingRequest;
|
import roomescape.reservation.dto.request.WaitingRequest;
|
||||||
import roomescape.reservation.dto.response.ReservationResponse;
|
import roomescape.reservation.dto.response.ReservationResponse;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.domain.repository.ThemeRepository;
|
import roomescape.theme.domain.repository.ThemeRepository;
|
||||||
import roomescape.theme.service.ThemeService;
|
import roomescape.theme.service.ThemeService;
|
||||||
@ -66,7 +66,7 @@ class ReservationServiceTest {
|
|||||||
assertThatThrownBy(() -> reservationService.addReservation(
|
assertThatThrownBy(() -> reservationService.addReservation(
|
||||||
new ReservationRequest(date, reservationTime.getId(), theme.getId(), "paymentKey", "orderId",
|
new ReservationRequest(date, reservationTime.getId(), theme.getId(), "paymentKey", "orderId",
|
||||||
1000L, "paymentType"), member1.getId()))
|
1000L, "paymentType"), member1.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -86,7 +86,7 @@ class ReservationServiceTest {
|
|||||||
// then
|
// then
|
||||||
assertThatThrownBy(() -> reservationService.addWaiting(
|
assertThatThrownBy(() -> reservationService.addWaiting(
|
||||||
new WaitingRequest(date, reservationTime.getId(), theme.getId()), member.getId()))
|
new WaitingRequest(date, reservationTime.getId(), theme.getId()), member.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -110,7 +110,7 @@ class ReservationServiceTest {
|
|||||||
// then
|
// then
|
||||||
assertThatThrownBy(() -> reservationService.addWaiting(
|
assertThatThrownBy(() -> reservationService.addWaiting(
|
||||||
new WaitingRequest(date, reservationTime.getId(), theme.getId()), member1.getId()))
|
new WaitingRequest(date, reservationTime.getId(), theme.getId()), member1.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -126,7 +126,7 @@ class ReservationServiceTest {
|
|||||||
assertThatThrownBy(() -> reservationService.addReservation(
|
assertThatThrownBy(() -> reservationService.addReservation(
|
||||||
new ReservationRequest(beforeDate, reservationTime.getId(), theme.getId(), "paymentKey", "orderId",
|
new ReservationRequest(beforeDate, reservationTime.getId(), theme.getId(), "paymentKey", "orderId",
|
||||||
1000L, "paymentType"), member.getId()))
|
1000L, "paymentType"), member.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -142,7 +142,7 @@ class ReservationServiceTest {
|
|||||||
assertThatThrownBy(() -> reservationService.addReservation(
|
assertThatThrownBy(() -> reservationService.addReservation(
|
||||||
new ReservationRequest(beforeTime.toLocalDate(), reservationTime.getId(), theme.getId(), "paymentKey",
|
new ReservationRequest(beforeTime.toLocalDate(), reservationTime.getId(), theme.getId(), "paymentKey",
|
||||||
"orderId", 1000L, "paymentType"), member.getId()))
|
"orderId", 1000L, "paymentType"), member.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -159,7 +159,7 @@ class ReservationServiceTest {
|
|||||||
new ReservationRequest(beforeTime.toLocalDate(), reservationTime.getId(), theme.getId(), "paymentKey",
|
new ReservationRequest(beforeTime.toLocalDate(), reservationTime.getId(), theme.getId(), "paymentKey",
|
||||||
"orderId", 1000L, "paymentType"),
|
"orderId", 1000L, "paymentType"),
|
||||||
NotExistMemberId))
|
NotExistMemberId))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -171,7 +171,7 @@ class ReservationServiceTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> reservationService.findFilteredReservations(null, null, dateFrom, dateTo))
|
assertThatThrownBy(() -> reservationService.findFilteredReservations(null, null, dateFrom, dateTo))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -194,7 +194,7 @@ class ReservationServiceTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> reservationService.approveWaiting(waiting.id(), admin.getId()))
|
assertThatThrownBy(() -> reservationService.approveWaiting(waiting.id(), admin.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import roomescape.reservation.domain.ReservationTime;
|
|||||||
import roomescape.reservation.domain.repository.ReservationRepository;
|
import roomescape.reservation.domain.repository.ReservationRepository;
|
||||||
import roomescape.reservation.domain.repository.ReservationTimeRepository;
|
import roomescape.reservation.domain.repository.ReservationTimeRepository;
|
||||||
import roomescape.reservation.dto.request.ReservationTimeRequest;
|
import roomescape.reservation.dto.request.ReservationTimeRequest;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.domain.repository.ThemeRepository;
|
import roomescape.theme.domain.repository.ThemeRepository;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class ReservationTimeServiceTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> reservationTimeService.addTime(new ReservationTimeRequest(LocalTime.of(12, 30))))
|
assertThatThrownBy(() -> reservationTimeService.addTime(new ReservationTimeRequest(LocalTime.of(12, 30))))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -64,7 +64,7 @@ class ReservationTimeServiceTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> reservationTimeService.findTimeById(invalidTimeId))
|
assertThatThrownBy(() -> reservationTimeService.findTimeById(invalidTimeId))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -83,6 +83,6 @@ class ReservationTimeServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThatThrownBy(() -> reservationTimeService.removeTimeById(reservationTime.getId()))
|
assertThatThrownBy(() -> reservationTimeService.removeTimeById(reservationTime.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import roomescape.reservation.dto.request.ReservationTimeRequest;
|
|||||||
import roomescape.reservation.dto.response.ReservationTimeResponse;
|
import roomescape.reservation.dto.response.ReservationTimeResponse;
|
||||||
import roomescape.reservation.service.ReservationService;
|
import roomescape.reservation.service.ReservationService;
|
||||||
import roomescape.reservation.service.ReservationTimeService;
|
import roomescape.reservation.service.ReservationTimeService;
|
||||||
import roomescape.common.exception.RoomEscapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.theme.domain.Theme;
|
import roomescape.theme.domain.Theme;
|
||||||
import roomescape.theme.domain.repository.ThemeRepository;
|
import roomescape.theme.domain.repository.ThemeRepository;
|
||||||
import roomescape.theme.dto.ThemeRequest;
|
import roomescape.theme.dto.ThemeRequest;
|
||||||
@ -73,7 +73,7 @@ class ThemeServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThatThrownBy(() -> themeService.findThemeById(notExistId))
|
assertThatThrownBy(() -> themeService.findThemeById(notExistId))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -128,7 +128,7 @@ class ThemeServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThatThrownBy(() -> themeService.addTheme(invalidRequest))
|
assertThatThrownBy(() -> themeService.addTheme(invalidRequest))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -159,6 +159,6 @@ class ThemeServiceTest {
|
|||||||
|
|
||||||
// when & then
|
// when & then
|
||||||
assertThatThrownBy(() -> themeService.removeThemeById(theme.getId()))
|
assertThatThrownBy(() -> themeService.removeThemeById(theme.getId()))
|
||||||
.isInstanceOf(RoomEscapeException.class);
|
.isInstanceOf(RoomescapeException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import roomescape.member.infrastructure.persistence.Member
|
|||||||
import roomescape.member.infrastructure.persistence.MemberRepository
|
import roomescape.member.infrastructure.persistence.MemberRepository
|
||||||
import roomescape.auth.infrastructure.jwt.JwtHandler
|
import roomescape.auth.infrastructure.jwt.JwtHandler
|
||||||
import roomescape.common.exception.ErrorType
|
import roomescape.common.exception.ErrorType
|
||||||
import roomescape.common.exception.RoomEscapeException
|
import roomescape.common.exception.RoomescapeException
|
||||||
|
|
||||||
const val NOT_LOGGED_IN_USERID: Long = 0;
|
const val NOT_LOGGED_IN_USERID: Long = 0;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class RoomescapeApiTest(
|
|||||||
jwtHandler.getMemberIdFromToken(any())
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
} returns NOT_LOGGED_IN_USERID
|
} returns NOT_LOGGED_IN_USERID
|
||||||
|
|
||||||
every { memberRepository.existsById(NOT_LOGGED_IN_USERID) } throws RoomEscapeException(
|
every { memberRepository.existsById(NOT_LOGGED_IN_USERID) } throws RoomescapeException(
|
||||||
ErrorType.LOGIN_REQUIRED,
|
ErrorType.LOGIN_REQUIRED,
|
||||||
HttpStatus.FORBIDDEN
|
HttpStatus.FORBIDDEN
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user