package common.ecommerce.hengjian.probe; import common.ecommerce.hengjian.HengjianConstants; import common.ecommerce.hengjian.adapter.HengjianAdapter; import common.ecommerce.http.JacksonJsonCodec; import common.ecommerce.http.OkHttpTransport; import common.ecommerce.shared.spi.ChannelSecret; import common.ecommerce.shared.support.Page; import common.ecommerce.warehouse.enums.WarehouseFeeType; import common.ecommerce.warehouse.enums.WarehouseProvider; import common.ecommerce.warehouse.model.FeeQuery; import common.ecommerce.warehouse.model.LogisticsProduct; import common.ecommerce.warehouse.model.OutboundLine; import common.ecommerce.warehouse.model.OutboundOrder; import common.ecommerce.warehouse.model.OutboundQuery; import common.ecommerce.warehouse.model.OutboundRef; import common.ecommerce.warehouse.model.WarehouseFacility; import common.ecommerce.warehouse.sdk.WarehouseConnection; import common.ecommerce.warehouse.sdk.WarehouseContext; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import java.time.Clock; import java.util.List; /** * 恒健只读探针:核对已对接接口的真实出入参。 * *
默认跳过,用 {@code -Dhengjian.probe=true} 显式开启;凭据走系统属性, * 真实 token 不入库:
* ** mvn -pl warehouse-sdk-hengjian -DfailIfNoTests=false \ * -Dhengjian.probe=true \ * -Dhengjian.probe.token=你的组织token \ * -Dhengjian.probe.warehouseCode=EFCA \ * -Dtest=HengjianReadOnlyProbeTest test ** *
只跑查询类接口:建单 / 取消 / 销毁会真实创建单据,没有测试环境 * 明确许可前一律不碰。
* *输出只打印字段名与取值摘要,不打印 token 与完整报文(可能含 PII)。
*/ @EnabledIfSystemProperty(named = "hengjian.probe", matches = "true") class HengjianReadOnlyProbeTest { private static final String TOKEN = System.getProperty("hengjian.probe.token", ""); private static final String BASE_URL = opt("hengjian.probe.baseUrl", HengjianConstants.TEST_BASE_URL); private static final String WAREHOUSE_CODE = opt("hengjian.probe.warehouseCode", "HJ-PROBE"); private static final String PROVIDER_WAREHOUSE = opt("hengjian.probe.providerWarehouseId", "EFCA"); private static String opt(String key, String fallback) { String v = System.getProperty(key); return v == null || v.trim().isEmpty() ? fallback : v.trim(); } private static void assumeToken() { Assumptions.assumeTrue(!TOKEN.trim().isEmpty(), "未提供 -Dhengjian.probe.token,跳过恒健探针"); } private static WarehouseContext ctx() { return WarehouseContext.of(WAREHOUSE_CODE, WarehouseProvider.HENGJIAN, PROVIDER_WAREHOUSE, WarehouseConnection.of(BASE_URL, ChannelSecret.builder().appSecret(TOKEN.trim()).build()), "probe-" + System.currentTimeMillis(), Clock.systemUTC()); } private static HengjianAdapter adapter() { return new HengjianAdapter(new OkHttpTransport("common-ecommerce-hengjian-probe"), new JacksonJsonCodec()); } /** 一次跑完,异常只打印不中断——探针要把所有问题一次暴露出来。 */ private static void run(String what, Runnable action) { System.out.println("---- " + what); try { action.run(); } catch (RuntimeException e) { System.out.println(" [FAIL] " + e.getClass().getSimpleName() + ": " + e.getMessage()); } } /** 仓库目录:不依赖任何单号,最容易验通,也顺带验证鉴权与信封。 */ @Test void probeWarehouseDirectory() { assumeToken(); run("POST /v2/warehouse/getWarehouse", new Runnable() { @Override public void run() { List需要 {@code -Dhengjian.probe.begin=yyyy-MM-dd} 与 {@code -Dhengjian.probe.end=yyyy-MM-dd}, * 跨度不超过 30 天。
*/ @Test void probeOrderList() { assumeToken(); final String begin = opt("hengjian.probe.begin", ""); final String end = opt("hengjian.probe.end", ""); Assumptions.assumeTrue(!begin.isEmpty() && !end.isEmpty(), "未提供 -Dhengjian.probe.begin / end,跳过订单列表探针"); run("GET /v1/saleOrder/findByPage", new Runnable() { @Override public void run() { OutboundQuery query = OutboundQuery.builder() .after(java.time.LocalDate.parse(begin) .atStartOfDay(java.time.ZoneOffset.UTC).toInstant()) .before(java.time.LocalDate.parse(end) .atTime(23, 59, 59).toInstant(java.time.ZoneOffset.UTC)) .pageSize(10) .build(); Page用 {@code -Dhengjian.probe.feeType=STORAGE|LAST_MILE|OPERATION} 指定查哪一类; * 必须同时给 {@code -Dhengjian.probe.begin} / {@code end}(yyyy-MM-dd), * 因为恒健要求至少一条过滤条件。
*/ @Test void probeFeeDetails() { assumeToken(); final String feeType = opt("hengjian.probe.feeType", ""); Assumptions.assumeTrue(!feeType.isEmpty(), "未提供 -Dhengjian.probe.feeType,跳过计费明细探针"); final String begin = opt("hengjian.probe.begin", ""); final String end = opt("hengjian.probe.end", ""); Assumptions.assumeTrue(!begin.isEmpty() && !end.isEmpty(), "未提供 -Dhengjian.probe.begin / end,跳过计费明细探针"); final WarehouseFeeType type; try { type = WarehouseFeeType.valueOf(feeType.trim().toUpperCase()); } catch (IllegalArgumentException e) { System.out.println("[skip] 未知的 feeType=" + feeType); return; } run("POST /v1/chargingSettlement/* (" + type + ")", new Runnable() { @Override public void run() { FeeQuery query = FeeQuery.builder() .costType(type) .settledAfter(java.time.LocalDate.parse(begin) .atStartOfDay(java.time.ZoneOffset.UTC).toInstant()) .settledBefore(java.time.LocalDate.parse(end) .atTime(23, 59, 59).toInstant(java.time.ZoneOffset.UTC)) .pageSize(10) .build(); List