Skip to content

Commit

Permalink
[Order API TDD] 상품 조회 기능 API 테스트로 전환
Browse files Browse the repository at this point in the history
  • Loading branch information
jihunparkme committed Feb 26, 2024
1 parent 268d74c commit 398a9fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
4 changes: 4 additions & 0 deletions product-order-service/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TDD

[실전! 스프링부트 상품-주문 API 개발로 알아보는 TDD](https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-%EC%8B%A4%EC%A0%84-%EC%83%81%ED%92%88%EC%A3%BC%EB%AC%B8-tdd/dashboard) 강의 정리

## POJO 상품 등록 기능 구현하기

**Java TDD**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/products")
Expand All @@ -27,13 +24,15 @@ public ResponseEntity<Void> addProduct(@RequestBody final AddProductRequest requ
return ResponseEntity.status(HttpStatus.CREATED).build();
}

public GetProductResponse getProduct(final long productId) {
@GetMapping("/{productId}")
public ResponseEntity<GetProductResponse> getProduct(@PathVariable final long productId) {
final Product product = productPort.getProduct(productId);

return new GetProductResponse(
GetProductResponse response = new GetProductResponse(
product.getId(),
product.getName(),
product.getPrice(),
product.getDiscountPolicy());
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.productorderservice.product;

import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;

Expand All @@ -16,4 +19,20 @@ class ProductApiTest extends ApiTest {
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());
}

@Test
void 상품조회() {
ProductSteps.requestAddProduct(ProductSteps.getAddProductRequest());
Long productId = 1L;

final ExtractableResponse<Response> response = RestAssured.given().log().all() // 요청 로그 남기기
.when()
.get("/products/{productId}", productId)
.then().log().all()
.extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(response.jsonPath().getString("id")).isEqualTo("1");
assertThat(response.jsonPath().getString("name")).isEqualTo("상품명");
assertThat(response.jsonPath().getString("price")).isEqualTo("1000");
}
}

This file was deleted.

0 comments on commit 398a9fb

Please sign in to comment.