#33 tdd(order-service): payment - spring
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Long, Payment> persistence = new HashMap<>();
|
||||
private Long sequence = 0L;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user