package org.xmx0632.deliciousfruit.service; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.PAYMENT_METHOD; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.DeductionPay; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByCashCoupon; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByEcoupon; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByGiftCard; import org.xmx0632.deliciousfruit.api.v1.bo.Result; import org.xmx0632.deliciousfruit.api.v1.bo.SettlementResponse.ProductFreeInfo; import org.xmx0632.deliciousfruit.api.v1.bo.SettlementResponse.PromotionDetails; import org.xmx0632.deliciousfruit.entity.UserAccount; /** * 测试货到付现金(3) COD的各种情况 * * @author mars * */ public class IosPayoffServiceCashOnDeliveryTest extends BaseIosPayoffServiceTestCase { private UserAccount userAccount = null; @Before public void setUp() throws Exception { super.setUp(); } @After public void tearDown() throws Exception { } // 货到付现金(3),低于100元,不免运费 @Test public void testProcessCOD_need_freight() { // mock BigDecimal totalPrice = BigDecimal.valueOf(28); BigDecimal actualAmount = BigDecimal.valueOf(24.5); BigDecimal productPriceOff = null; List<ProductFreeInfo> productProductsFree = null; List<ProductFreeInfo> totalProductsFree = null; BigDecimal totalPriceOff = totalPrice.subtract(actualAmount); mockSettlementResponse(actualAmount, productPriceOff, productProductsFree, totalPriceOff, totalProductsFree, totalPrice, BigDecimal.valueOf(10)); mockDeductionPayService(new ArrayList<PayByCashCoupon>(), new ArrayList<PayByEcoupon>(), new ArrayList<PayByGiftCard>(), BigDecimal.ZERO, BigDecimal.ZERO); // verify logic OrderRequest request = createRequest(cashCoupons, giftCards, payAmountFromAccount, payAmountFromPonit, payPonit, orderList, PAYMENT_METHOD.CASH_ON_DELIVERY.getCode()); OrderResponse response = iosPayoffService.process(request, userAccount); assertNotNull(response); System.out.println("response:" + response); assertEquals(Result.SUCCESS_RESULT, response.getResult()); // 支付方式 assertEquals(PAYMENT_METHOD.CASH_ON_DELIVERY.getCode(), response.getPaymentMethod()); assertEquals(TRANSACTION_ID, response.getTransactionID()); assertEquals(totalPrice, response.getTotalPrice()); assertEquals(BigDecimal.valueOf(24.5), response.getPayAmount()); assertEquals("ORDER10000001", response.getOrderNumber()); assertEquals(BigDecimal.valueOf(10.0), response.getFreight()); assertEquals(BigDecimal.valueOf(10), response.getFreightPay()); // 享受的促销优惠 PromotionDetails promotionDetails = response.getPromotionDetails(); assertNotNull(promotionDetails); assertEquals(BigDecimal.valueOf(3.5), promotionDetails.getPriceOff()); List<ProductFreeInfo> productsFree = promotionDetails.getProductsFree(); assertNotNull(productsFree); assertEquals(0, productsFree.size()); assertNoDeductionPay(response); } private void assertNoDeductionPay(OrderResponse response) { // 没有任何抵扣付款 DeductionPay deductionPay = response.getDeductionPay(); assertNotNull(deductionPay); assertTrue(deductionPay.getPayByCashCouponInfo().isEmpty()); assertTrue(deductionPay.getPayByGiftCardInfo().isEmpty()); // 用积分抵扣付款 BigDecimal payByPoint = deductionPay.getPayByPoint(); assertEquals(BigDecimal.ZERO, payByPoint); // 用账户余额抵扣付款 BigDecimal payFromAccount = deductionPay.getPayFromAccount(); assertEquals(BigDecimal.ZERO, payFromAccount); } // 货到付现金(3),高于100元,免运费 @Test public void testProcessCOD_need_no_freight() { // mock BigDecimal totalPrice = BigDecimal.valueOf(130); BigDecimal actualAmount = BigDecimal.valueOf(110); BigDecimal productPriceOff = null; List<ProductFreeInfo> productProductsFree = null; List<ProductFreeInfo> totalProductsFree = null; BigDecimal totalPriceOff = totalPrice.subtract(actualAmount); mockSettlementResponse(actualAmount, productPriceOff, productProductsFree, totalPriceOff, totalProductsFree, totalPrice, BigDecimal.valueOf(0)); mockDeductionPayService(new ArrayList<PayByCashCoupon>(), new ArrayList<PayByEcoupon>(), new ArrayList<PayByGiftCard>(), BigDecimal.ZERO, BigDecimal.ZERO); // verify logic OrderRequest request = createRequest(cashCoupons, giftCards, payAmountFromAccount, payAmountFromPonit, payPonit, orderList, PAYMENT_METHOD.CASH_ON_DELIVERY.getCode()); OrderResponse response = iosPayoffService.process(request, userAccount); assertNotNull(response); System.out.println("response:" + response); assertEquals(Result.SUCCESS_RESULT, response.getResult()); // 支付方式 assertEquals(PAYMENT_METHOD.CASH_ON_DELIVERY.getCode(), response.getPaymentMethod()); assertEquals(TRANSACTION_ID, response.getTransactionID()); assertEquals(totalPrice, response.getTotalPrice()); assertEquals(actualAmount, response.getPayAmount()); assertEquals("ORDER10000001", response.getOrderNumber()); assertEquals(BigDecimal.valueOf(10.0), response.getFreight()); assertEquals(BigDecimal.valueOf(0), response.getFreightPay()); // 享受的促销优惠 PromotionDetails promotionDetails = response.getPromotionDetails(); assertNotNull(promotionDetails); assertEquals(totalPrice.subtract(actualAmount), promotionDetails.getPriceOff()); List<ProductFreeInfo> productsFree = promotionDetails.getProductsFree(); assertNotNull(productsFree); assertEquals(0, productsFree.size()); assertNoDeductionPay(response); } // TODO 查询抵扣消息时异常 @Test public void testExceptionWhenGetDeductionPay() throws Exception { fail("not implemented"); } // TODO 发送抵扣消息时异常,回滚已发送消息 @Test public void testExceptionWhenSendDeductionPayMessage() throws Exception { fail("not implemented"); } // TODO 发送抵扣消息时异常,回滚已发送消息,发送回滚消息异常 @Test public void testExceptionWhenSendDeductionPayMessageRollback() throws Exception { fail("not implemented"); } // TODO 发送订单消息时异常,回滚已发送的抵扣消息 @Test public void testExceptionWhenOrderShouldRollbackDeductionPay() throws Exception { fail("not implemented"); } // TODO 发送订单消息时,新增收货地址,更新到数据库 @Test public void testNewReceiverWhenOrder() throws Exception { fail("not implemented"); } // TODO 发送订单消息时,如果收货地址有变化,更新到数据库 @Test public void testChangeReceiverWhenOrder() throws Exception { fail("not implemented"); } // TODO 发送订单消息时,如果没有收货地址,拒绝订单操作 @Test public void testRefuseOrderWhenNoReceiver() throws Exception { fail("not implemented"); } }