프로젝트 빌드, 실행 후 아래와 같이 테스트
1. 상품 생성
method : POST
url : http://localhost:8080/products
body :
{
"name": "맥북 미니",
"price": 1300000,
"stock": 5
}
resopnse :

- 응답에 새로 생성된 id 데이터가 들어있는 것을 확인
DB :

- DB table에 상품이 추가된 것을 확인 (1행, 2행 데이터는 이미 있던 데이터)
2. 특정 상품 조회
method : GET
url : http://localhost:8080/products/1
resopnse :

- id = 1 인 데이터 조회 확인
3. 모든 상품 조회
method : GET
url : http://localhost:8080/products
resopnse :

4. 상품 삭제
method : DELETE
url : http://localhost:8080/products/3
DB :

- id=3 데이터가 제거되었음
5. 주문 생성
method : POST
url : http://localhost:8080/orders
body :
{
"productId": 1,
"quantity": 2
}
response :

DB :

- orders 테이블에 데이터 생성 확인

- products 테이블에 id = 1 인 데이터의 stock이 5에서 3으로 변경된 것을 확인
* 재고 부족 테스트를 위해 다시 한 번 주문 생성 요청
method : POST
url : http://localhost:8080/orders
body :
{
"productId": 1,
"quantity": 10
}
response :

- 에러 발생 확인
6. 상품 정보 변경
method : PUT
url : http://localhost:8080/products/1
body :
{
"name": "맥북 프로",
"price": 2500000,
"stock": 3
}
response :

DB :

- 상품 이름이 변경 된 것을 확인
7. 주문 정보 조회
method : GET
url : http://localhost:8080/orders/1
response :

- id = 1인 데이터 정보 조회 확인
- 주문 정보의 상품 이름이 변경된 것을 확인 (개발 요구 사항)
'Spring > - [시리즈] 간단한 CRUD 구현하기' 카테고리의 다른 글
| CRUD 구현 9 - 간단한 페이지네이션(Pagination) 구현 (0) | 2026.05.18 |
|---|---|
| CRUD 구현 7 - Controller 구현 (0) | 2026.05.15 |
| CRUD 구현 6 - Service 구현 (0) | 2026.05.15 |
| CRUD 구현 5 - DTO (Data Transfer Object) 구현 (0) | 2026.05.15 |
| CRUD 구현 4 - Repository 구현 (0) | 2026.05.14 |