#33 tdd(order-service): get product - api test
This commit is contained in:
@@ -3,10 +3,7 @@ package com.example.productorderservice.product;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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
|
||||
@RequiredArgsConstructor
|
||||
@@ -20,4 +17,9 @@ public class ProductController {
|
||||
productService.addProduct(request);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
@GetMapping("/{productId}")
|
||||
public ResponseEntity<GetProductResponse> getProduct(@PathVariable final Long productId) {
|
||||
return ResponseEntity.ok(productService.getProduct(productId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class ProductService {
|
||||
productPort.save(product);
|
||||
}
|
||||
|
||||
public GetProductResponse getProduct(long productId) {
|
||||
public GetProductResponse getProduct(Long productId) {
|
||||
final Product product = productPort.getProduct(productId);
|
||||
|
||||
return new GetProductResponse(
|
||||
|
||||
@@ -14,21 +14,25 @@ class ProductApiTest extends ApiTest {
|
||||
|
||||
@Test
|
||||
void 상품등록() {
|
||||
final var request = 상품등록요청_생성();
|
||||
final var request = ProductSteps.상품등록요청_생성();
|
||||
final var response = ProductSteps.상품등록요청(request);
|
||||
|
||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 상품조회() {
|
||||
ProductSteps.상품등록요청(ProductSteps.상품등록요청_생성());
|
||||
final Long productId = 1L;
|
||||
|
||||
ExtractableResponse<Response> response = RestAssured.given().log().all()
|
||||
.when()
|
||||
.get("/products/{productId}", productId)
|
||||
.then().log().all()
|
||||
.extract();
|
||||
|
||||
private static AddProductRequest 상품등록요청_생성() {
|
||||
final String name = "상품명";
|
||||
final int price = 1000;
|
||||
final DiscountPolicy discountPolicy = DiscountPolicy.NONE;
|
||||
|
||||
final AddProductRequest request = new AddProductRequest(name, price, discountPolicy);
|
||||
return request;
|
||||
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(response.jsonPath().getString("name")).isEqualTo("상품명");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user