Back to Repositories

Testing Kd100 Express Delivery Integration in RuoYi Vue Pro

This integration test suite validates the Kd100ExpressClient implementation for tracking express deliveries in the RuoYi Vue Pro system. It demonstrates proper client configuration and API interaction for querying shipment tracking information.

Test Coverage Overview

The test suite covers the core functionality of the Kd100ExpressClient for express delivery tracking.

Key areas tested include:
  • Client initialization with configuration parameters
  • Express tracking query execution
  • Response handling and deserialization
  • Integration with the KD100 API service

Implementation Analysis

The testing approach utilizes JUnit 5 for integration testing, with a focus on real-world API interaction. The implementation demonstrates proper Spring RestTemplate usage and configuration management for external service integration.

Notable patterns include:
  • BeforeEach setup for client initialization
  • Disabled test annotation for controlled execution
  • Structured DTO usage for request/response handling

Technical Details

Testing infrastructure includes:
  • JUnit 5 testing framework
  • Spring Boot RestTemplate for HTTP interactions
  • Lombok for logging support
  • Custom DTO classes for data transfer
  • JsonUtils for response formatting

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test isolation and setup
  • Clear test method naming
  • Controlled integration test execution
  • Structured configuration management
  • Appropriate use of logging and output formatting

yunaiv/ruoyi-vue-pro

yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientIntegrationTest.java

            
package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * {@link Kd100ExpressClient} 的集成测试
 *
 * @author jason
 */
@Slf4j
public class Kd100ExpressClientIntegrationTest {

    private Kd100ExpressClient client;

    @BeforeEach
    public void init() {
        RestTemplate restTemplate = new RestTemplateBuilder().build();
        TradeExpressProperties.Kd100Config config = new TradeExpressProperties.Kd100Config()
                .setKey("pLXUGAwK5305")
                .setCustomer("E77DF18BE109F454A5CD319E44BF5177");
        client = new Kd100ExpressClient(restTemplate, config);
    }

    @Test
    @Disabled("集成测试,暂时忽略")
    public void testGetExpressTrackList() {
        ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO();
        reqDTO.setExpressCode("STO");
        reqDTO.setLogisticsNo("773220402764314");
        List<ExpressTrackRespDTO> tracks = client.getExpressTrackList(reqDTO);
        System.out.println(JsonUtils.toJsonPrettyString(tracks));
    }

}