diff --git a/product-order-service/src/main/java/com/example/productorderservice/order/OrderService.java b/product-order-service/src/main/java/com/example/productorderservice/order/OrderService.java index 49ff59d8..e72e81e4 100644 --- a/product-order-service/src/main/java/com/example/productorderservice/order/OrderService.java +++ b/product-order-service/src/main/java/com/example/productorderservice/order/OrderService.java @@ -2,15 +2,17 @@ package com.example.productorderservice.order; import com.example.productorderservice.product.Product; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service -class OrderService { +public class OrderService { private final OrderPort orderPort; OrderService(OrderPort orderPort) { this.orderPort = orderPort; } + @Transactional public void createOrder(CreateOrderRequest request) { Product product = orderPort.getProductById(request.productId()); diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/ConsolePaymentGateway.java b/product-order-service/src/test/java/com/example/productorderservice/payment/ConsolePaymentGateway.java index af1622f2..f71aca78 100644 --- a/product-order-service/src/test/java/com/example/productorderservice/payment/ConsolePaymentGateway.java +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/ConsolePaymentGateway.java @@ -1,5 +1,8 @@ package com.example.productorderservice.payment; +import org.springframework.stereotype.Component; + +@Component public class ConsolePaymentGateway implements PaymentGateway { @Override public void execute(int totalPrice, String cardNumber) { diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentAdapter.java b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentAdapter.java index 77601eab..32b5a5d7 100644 --- a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentAdapter.java +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentAdapter.java @@ -3,7 +3,9 @@ package com.example.productorderservice.payment; import com.example.productorderservice.order.Order; import com.example.productorderservice.product.DiscountPolicy; import com.example.productorderservice.product.Product; +import org.springframework.stereotype.Component; +@Component class PaymentAdapter implements PaymentPort { private final PaymentGateway paymentGateway; private final PaymentRepository paymentRepository; diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentRepository.java b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentRepository.java index ae64d6be..707e42e1 100644 --- a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentRepository.java +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentRepository.java @@ -1,8 +1,11 @@ package com.example.productorderservice.payment; +import org.springframework.stereotype.Repository; + import java.util.HashMap; import java.util.Map; +@Repository class PaymentRepository { private final Map persistence = new HashMap<>(); private Long sequence = 0L; diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentService.java b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentService.java index f09a037b..6a438ef7 100644 --- a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentService.java +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentService.java @@ -1,8 +1,10 @@ package com.example.productorderservice.payment; import com.example.productorderservice.order.Order; +import org.springframework.stereotype.Service; -class PaymentService { +@Service +public class PaymentService { private final PaymentPort paymentPort; PaymentService(PaymentPort paymentPort) { diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServicePojoTest.java b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServicePojoTest.java new file mode 100644 index 00000000..d656e85e --- /dev/null +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServicePojoTest.java @@ -0,0 +1,27 @@ +package com.example.productorderservice.payment; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class PaymentServicePojoTest { + + private PaymentService paymentService; + private PaymentPort paymentPort; + + @BeforeEach + void setUp() { + final PaymentGateway paymentGateway = new ConsolePaymentGateway(); + final PaymentRepository paymentRepository= new PaymentRepository(); + paymentPort = new PaymentAdapter(paymentGateway, paymentRepository); + paymentService = new PaymentService(paymentPort); + } + + @Test + void 상품주문() { + + final PaymentRequest request = PaymentSteps.주문결제요청_생성(); + + paymentService.payment(request); + } + +} diff --git a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServiceTest.java b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServiceTest.java index 5cdb9fcb..6f31ffd9 100644 --- a/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServiceTest.java +++ b/product-order-service/src/test/java/com/example/productorderservice/payment/PaymentServiceTest.java @@ -1,24 +1,31 @@ package com.example.productorderservice.payment; +import com.example.productorderservice.order.OrderService; +import com.example.productorderservice.order.OrderSteps; +import com.example.productorderservice.product.ProductService; +import com.example.productorderservice.product.ProductSteps; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +@SpringBootTest class PaymentServiceTest { - private PaymentService paymentService; - private PaymentPort paymentPort; - @BeforeEach - void setUp() { - final PaymentGateway paymentGateway = new ConsolePaymentGateway(); - final PaymentRepository paymentRepository= new PaymentRepository(); - paymentPort = new PaymentAdapter(paymentGateway, paymentRepository); - paymentService = new PaymentService(paymentPort); - } + @Autowired + private ProductService productService; + + @Autowired + private OrderService orderService; + + @Autowired + private PaymentService paymentService; @Test void 상품주문() { - + productService.addProduct(ProductSteps.상품등록요청_생성()); + orderService.createOrder(OrderSteps.상품주문요청_생성()); final PaymentRequest request = PaymentSteps.주문결제요청_생성(); paymentService.payment(request);