Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] 테스트 코드 구현 #12

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4107f8e
refactor: DTO req, res 구분
m-a-king Sep 11, 2024
30cc0c0
feat: 주문, 상품 entity PK AutoIncrement
m-a-king Sep 11, 2024
0b913f5
테스트 보류
m-a-king Sep 11, 2024
debe747
feat: Req DTOs Validation check
m-a-king Sep 11, 2024
469d607
refactor: DTO req, res 구분
m-a-king Sep 11, 2024
578adcf
delete: unUsed import
m-a-king Sep 11, 2024
4c0fec8
실행 시간 측정 AOP 추가
shmin98 Sep 11, 2024
54888e0
로그 관리를 위한 xml 설정 추가, CONSOLE, FILE, ERROR 에 대한 로그 관리 가능, 로그 레벨별 단위 커스…
skfk286 Sep 11, 2024
8212e97
로그 관리 환경에 따라 Profile 설정 추가(local, dev)
skfk286 Sep 11, 2024
1cad64f
Merge branch 'main' into Logger
skfk286 Sep 11, 2024
760e7fd
Merge pull request #5 from prgrms-be-devcourse/Logger
skfk286 Sep 11, 2024
0707374
AOP Rollback
shmin98 Sep 11, 2024
5427ce3
[설정 추가 내용]
shmin98 Sep 11, 2024
c2acb4d
refactor: 생성, 수정 Auditing
m-a-king Sep 11, 2024
7a17e2c
update: DTO class 를 record 로 변경
m-a-king Sep 11, 2024
c453979
TEST 코드 보류
m-a-king Sep 11, 2024
ebd844e
feat: 주문 상태 String -> ENUM
m-a-king Sep 11, 2024
73e0d47
fix: 전역 예외 핸들러 버그 수정
m-a-king Sep 11, 2024
6967426
fix: SuperBuilder
m-a-king Sep 11, 2024
6acfb2e
fix: 반환 타입 직관적이게 수정
m-a-king Sep 11, 2024
fd51bce
feat: 주문상품서비스 구현
m-a-king Sep 11, 2024
1c76f57
Merge remote-tracking branch 'origin/main' into Validation
m-a-king Sep 11, 2024
fdc5a6e
출력 라이브러리 변경
shmin98 Sep 11, 2024
da1eaa5
Merge pull request #8 from prgrms-be-devcourse/AOP
m-a-king Sep 11, 2024
b6a76be
Merge remote-tracking branch 'origin/main' into Validation
m-a-king Sep 11, 2024
583a6b8
refactor: .collect(Collectors.toList()) ---> .toList()
m-a-king Sep 11, 2024
a332435
Merge pull request #9 from prgrms-be-devcourse/Validation
m-a-king Sep 11, 2024
70aff18
refactor: 불필요한 import 삭제
eundeang Sep 11, 2024
51f9f77
test: 정규표현식에 맞는 Email 생성 클래스 추가
eundeang Sep 11, 2024
e45a048
test: @DisplayName 추가
eundeang Sep 11, 2024
2a8ac77
test: email 생성 코드 추가
eundeang Sep 11, 2024
2af8e80
test: Describe : OrderByEmail메서드 테스트 클래스 추가
eundeang Sep 11, 2024
1ba0206
test: Context : 이메일에 해당하는 주문이 있는 경우
eundeang Sep 11, 2024
e679601
test: describe: getAllOrders 추가
eundeang Sep 11, 2024
f6be55a
test: describe: registerOrder 추가
eundeang Sep 11, 2024
23d601a
test: context: ExistOrder
eundeang Sep 11, 2024
4780b9b
test: 기존 테스트 코드 삭제
eundeang Sep 11, 2024
498120b
test: validation test - email check
eundeang Sep 11, 2024
d4a7ac1
test: 이메일에 해당하는 주문이 있는 경우의 beforeafter 세팅
eundeang Sep 12, 2024
8a13997
test: test-result
eundeang Sep 12, 2024
cd2ed0c
test: registerOrder TC 추가
eundeang Sep 12, 2024
dc63481
test: test result modified
eundeang Sep 12, 2024
67f23f0
fix: springboottest로 변경
eundeang Sep 12, 2024
f1bd4eb
refactor: @Transactional 추가후 삭제 메서드 제거
eundeang Sep 12, 2024
74ceacb
test: test 명세
eundeang Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
721 changes: 721 additions & 0 deletions Test Results - OrderServiceImplTest.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.example.gc_coffee.Exception;

import jakarta.persistence.EntityNotFoundException;
import org.example.gc_coffee.dto.response.ApiResponseDto;
import org.example.gc_coffee.dto.common.ApiResponseDto;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@ControllerAdvice
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(EntityNotFoundException.class)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/example/gc_coffee/GcCoffeeApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing //등록시각, 수정시각을 위한 전체 auditing 활성화를 위한 에노테이션
@SpringBootApplication
public class GcCoffeeApplication {

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/example/gc_coffee/aspects/ExeTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.gc_coffee.aspects;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface ExeTimer {
}
68 changes: 68 additions & 0 deletions src/main/java/org/example/gc_coffee/aspects/ExecutionTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.example.gc_coffee.aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Slf4j
@Component
@Aspect
public class ExecutionTimer {

/*
* @Arund 사용 -> 메서드 실행 전, 후로 시간을 공유해야 하기 때문
* * org.example.gc_coffee.controller.*.*(..) -> controller 패키지 내의 모든 클래스 및 함수 실행 시 동작
*/
@Around("execution(* org.example.gc_coffee.controller.*.*(..))")
public Object PackageExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {

StopWatch stopWatch = new StopWatch();

stopWatch.start();
Object result = joinPoint.proceed();
stopWatch.stop();

long totalTimeMillis = stopWatch.getTotalTimeMillis();

MethodSignature signature = (MethodSignature) joinPoint.getSignature();
String methodName = signature.getMethod().getName();

log.info("실행 메서드: {}, 실행시간 = {}ms", methodName, totalTimeMillis);

return result;
}



/*
* 조인포인트를 어노테이션으로 설정
* 시간을 테스트할 함수에 @ExeTimer 작성
*/
// @Pointcut("@annotation(org.example.gc_coffee.aspects.ExeTimer)")
// private void timer(){};
//
// // 메서드 실행 전,후로 시간을 공유해야 하기 때문
// @Around("timer()")
// public Object UnitExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
//
// StopWatch stopWatch = new StopWatch();
//
// stopWatch.start();
// Object result = joinPoint.proceed(); // 조인포인트의 메서드 실행
// stopWatch.stop();
//
// long totalTimeMillis = stopWatch.getTotalTimeMillis();
//
// MethodSignature signature = (MethodSignature) joinPoint.getSignature();
// String methodName = signature.getMethod().getName();
//
// log.info("실행 메서드: {}, 실행시간 = {}ms", methodName, totalTimeMillis);
//
// return result;
// }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.example.gc_coffee.controller;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.example.gc_coffee.dto.OrderDto;
import org.example.gc_coffee.dto.response.ApiResponseDto;
import org.example.gc_coffee.dto.request.OrderReqDto;
import org.example.gc_coffee.dto.response.OrderResDto;
import org.example.gc_coffee.dto.common.ApiResponseDto;
import org.example.gc_coffee.service.OrderService;
import org.springframework.web.bind.annotation.*;

Expand All @@ -16,20 +18,20 @@ public class OrderController {
private final OrderService orderService;

@GetMapping("/{email}")
public ApiResponseDto<List<OrderDto>> getOrderByEmail(@PathVariable(value = "email") String email) {
List<OrderDto> orderDtoList = orderService.getOrderByEmail(email);
return new ApiResponseDto<>("Order retrieved successfully", orderDtoList);
public ApiResponseDto<List<OrderResDto>> getOrderByEmail(@PathVariable(value = "email") String email) {
List<OrderResDto> orderResDtoList = orderService.getOrderByEmail(email);
return new ApiResponseDto<>("Order retrieved successfully", orderResDtoList);
}

@GetMapping("/all")
public ApiResponseDto<List<OrderDto>> getAllOrder() {
List<OrderDto> orders = orderService.getAllOrders();
public ApiResponseDto<List<OrderResDto>> getAllOrder() {
List<OrderResDto> orders = orderService.getAllOrders();
return new ApiResponseDto<>("Orders retrieved successfully", orders);
}

@PostMapping
public ApiResponseDto<String> registerOrder(@RequestBody OrderDto orderDto) {
orderService.registerOrder(orderDto);
public ApiResponseDto<String> registerOrder(@RequestBody @Valid OrderReqDto orderReqDto) {
orderService.registerOrder(orderReqDto);
return new ApiResponseDto<>(201, "Order registered successfully \n당일 오후 2시 이후의 주문은 다음날 배송을 시작합니다.", null);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.example.gc_coffee.controller;

import lombok.RequiredArgsConstructor;
import org.example.gc_coffee.dto.ProductDto;
import org.example.gc_coffee.dto.response.ApiResponseDto;
import org.example.gc_coffee.dto.request.ProductReqDto;
import org.example.gc_coffee.dto.response.ProductResDto;
import org.example.gc_coffee.dto.common.ApiResponseDto;
import org.example.gc_coffee.service.ProductService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -18,20 +17,20 @@ public class ProductController {
private final ProductService productService;

@GetMapping("/{name}")
public ApiResponseDto<ProductDto> getProductByName(@PathVariable(value = "name") String name) {
ProductDto product = productService.getProductByNames(name);
public ApiResponseDto<ProductResDto> getProductByName(@PathVariable(value = "name") String name) {
ProductResDto product = productService.getProductByNames(name);
return new ApiResponseDto<>("Product retrieved successfully", product);
}

@GetMapping("/all")
public ApiResponseDto<List<ProductDto>> getAllProducts() {
List<ProductDto> products = productService.getAllProducts();
public ApiResponseDto<List<ProductResDto>> getAllProducts() {
List<ProductResDto> products = productService.getAllProducts();
return new ApiResponseDto<>("All products retrieved successfully", products);
}

@PostMapping
public ApiResponseDto<String> registerProduct(@RequestBody ProductDto productDto) {
productService.registerProduct(productDto);
public ApiResponseDto<String> registerProduct(@RequestBody ProductReqDto productReqDto) {
productService.registerProduct(productReqDto);
return new ApiResponseDto<>(201,"Product registered successfully", null);
}
}
16 changes: 0 additions & 16 deletions src/main/java/org/example/gc_coffee/dto/BaseDto.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/org/example/gc_coffee/dto/OrderDto.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/org/example/gc_coffee/dto/OrderProductDto.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/org/example/gc_coffee/dto/ProductDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.gc_coffee.dto.response;
package org.example.gc_coffee.dto.common;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/example/gc_coffee/dto/common/OrderStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.gc_coffee.dto.common;

public enum OrderStatus {
ORDER_PLACED, // 주문 완료
PENDING_PAYMENT, // 결제 대기
PAYMENT_COMPLETED, // 결제 완료
PREPARING_SHIPMENT, // 상품 준비 중
SHIPPED, // 배송 중
DELIVERED, // 배송 완료
COMPLETED // 주문 완료
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.example.gc_coffee.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.example.gc_coffee.entity.Order;
import org.example.gc_coffee.entity.OrderProduct;
import org.example.gc_coffee.entity.Product;

import java.util.UUID;

public record OrderProductReqDto(
@NotNull(message = "상품 ID를 입력해주세요.")
UUID productId,

@NotBlank(message = "카테고리를 입력해주세요.")
String category,

@NotNull(message = "가격을 입력해주세요.")
Long price,

@NotNull(message = "수량을 입력해주세요.")
Integer quantity
) {
// 정적 팩토리 메서드 of
public static OrderProductReqDto of(UUID productId, String category, Long price, Integer quantity) {
return new OrderProductReqDto(productId, category, price, quantity);
}

// DTO로부터 엔티티 생성하는 메서드 toEntity
public OrderProduct toEntity(Order order, Product product) {
return OrderProduct.builder()
.order(order)
.product(product)
.category(category)
.price(price)
.quantity(quantity)
.build();
}
}
Loading