-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6161a4c
commit 31059fc
Showing
8 changed files
with
103 additions
and
23 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
17 changes: 17 additions & 0 deletions
17
...der-service/src/main/java/com/example/productorderservice/product/GetProductResponse.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,17 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
record GetProductResponse( | ||
long id, | ||
String name, | ||
int price, | ||
DiscountPolicy discountPolicy | ||
) { | ||
GetProductResponse { | ||
Assert.notNull(id, "상품 ID는 필수입니다."); | ||
Assert.hasText(name, "상품명은 필수입니다."); | ||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다."); | ||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다."); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
|
||
interface ProductPort { | ||
void save(final Product product); | ||
|
||
Product getProduct(long productId); | ||
} |
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
25 changes: 2 additions & 23 deletions
25
...t-order-service/src/test/java/com/example/productorderservice/product/ProductApiTest.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 |
---|---|---|
@@ -1,40 +1,19 @@ | ||
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; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProductApiTest extends ApiTest { | ||
|
||
@Test | ||
void 상품등록() { | ||
final var request = getAddProductRequest(); | ||
final var request = ProductSteps.getAddProductRequest(); | ||
|
||
final var response = requestAddProduct(request); | ||
final var response = ProductSteps.requestAddProduct(request); | ||
|
||
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value()); | ||
} | ||
|
||
private ExtractableResponse<Response> requestAddProduct(final AddProductRequest request) { | ||
return RestAssured.given().log().all() // 요청 로그 남기기 | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.when() | ||
.post("/products") | ||
.then() | ||
.log().all().extract(); | ||
} | ||
|
||
private AddProductRequest getAddProductRequest() { | ||
final String name = "상품명"; | ||
final int price = 1000; | ||
final DiscountPolicy discountPolicy = DiscountPolicy.NONE; | ||
return new AddProductRequest(name, price, discountPolicy); // 02. Request 클래스 생성 | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...der-service/src/test/java/com/example/productorderservice/product/ProductServiceTest.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,28 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@SpringBootTest | ||
class ProductServiceTest { | ||
|
||
@Autowired | ||
private ProductService productService; | ||
|
||
@Test | ||
void 상품조회() { | ||
// 상품 등록 | ||
productService.addProduct(ProductSteps.getAddProductRequest()); | ||
final long productId = 1L; | ||
|
||
// 상품 조회 | ||
final GetProductResponse response = productService.getProduct(productId); | ||
|
||
// 상품의 응답 검증 | ||
assertThat(response).isNotNull(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...uct-order-service/src/test/java/com/example/productorderservice/product/ProductSteps.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,25 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.springframework.http.MediaType; | ||
|
||
public class ProductSteps { | ||
public static ExtractableResponse<Response> requestAddProduct(final AddProductRequest request) { | ||
return RestAssured.given().log().all() // 요청 로그 남기기 | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.body(request) | ||
.when() | ||
.post("/products") | ||
.then() | ||
.log().all().extract(); | ||
} | ||
|
||
public static AddProductRequest getAddProductRequest() { | ||
final String name = "상품명"; | ||
final int price = 1000; | ||
final DiscountPolicy discountPolicy = DiscountPolicy.NONE; | ||
return new AddProductRequest(name, price, discountPolicy); // 02. Request 클래스 생성 | ||
} | ||
} |