package edu.whut.test.domain.trade;

import com.alibaba.fastjson2.JSON;
import edu.whut.domain.trade.model.entity.TradePaySettlementEntity;
import edu.whut.domain.trade.model.entity.TradePaySuccessEntity;
import edu.whut.domain.trade.service.ITradeSettlementOrderService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
 * 拼团交易结算服务测试
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class TradeSettlementOrderServiceTest {

    @Resource
    private ITradeSettlementOrderService tradeSettlementOrderService;

    /**
     * 模拟拼团交易结算（小商场用户支付成功后调用）
     * @throws Exception
     */
    @Test
    public void test_settlementMarketPayOrder() throws Exception {
        //模拟支付成功后传入的信息
        TradePaySuccessEntity tradePaySuccessEntity = new TradePaySuccessEntity();
        tradePaySuccessEntity.setSource("s01");
        tradePaySuccessEntity.setChannel("c01");
        tradePaySuccessEntity.setUserId("zy03");
        tradePaySuccessEntity.setOutTradeNo("353044746766");
        tradePaySuccessEntity.setOutTradeTime(new Date());  //交易时间
        TradePaySettlementEntity tradePaySettlementEntity = tradeSettlementOrderService.settlementMarketPayOrder(tradePaySuccessEntity);
        log.info("请求参数:{}", JSON.toJSONString(tradePaySuccessEntity));
        log.info("测试结果:{}", JSON.toJSONString(tradePaySettlementEntity));

        // 暂停，等待MQ消息。处理完后，手动关闭程序
//        new CountDownLatch(1).await();
    }

}
