|
|
|
|
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.WarehouseProvider;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 恒健<b>只读</b>探针:核对已对接接口的真实出入参。
|
|
|
|
|
*
|
|
|
|
|
* <p>默认跳过,用 {@code -Dhengjian.probe=true} 显式开启;凭据走系统属性,
|
|
|
|
|
* <b>真实 token 不入库</b>:</p>
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* mvn -pl warehouse-sdk-hengjian -DfailIfNoTests=false \
|
|
|
|
|
* -Dhengjian.probe=true \
|
|
|
|
|
* -Dhengjian.probe.token=你的组织token \
|
|
|
|
|
* -Dhengjian.probe.warehouseCode=EFCA \
|
|
|
|
|
* -Dtest=HengjianReadOnlyProbeTest test
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* <p><b>只跑查询类接口</b>:建单 / 取消 / 销毁会真实创建单据,没有测试环境
|
|
|
|
|
* 明确许可前一律不碰。</p>
|
|
|
|
|
*
|
|
|
|
|
* <p>输出只打印字段名与取值摘要,不打印 token 与完整报文(可能含 PII)。</p>
|
|
|
|
|
*/
|
|
|
|
|
@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<WarehouseFacility> list = adapter().warehouses(ctx());
|
|
|
|
|
System.out.println(" 返回 " + list.size() + " 个仓");
|
|
|
|
|
for (int i = 0; i < Math.min(list.size(), 10); i++) {
|
|
|
|
|
WarehouseFacility w = list.get(i);
|
|
|
|
|
System.out.println(" [" + i + "] code=" + w.warehouseCode()
|
|
|
|
|
+ " name=" + w.name()
|
|
|
|
|
+ " country=" + w.country()
|
|
|
|
|
+ " state=" + w.state()
|
|
|
|
|
+ " city=" + w.city()
|
|
|
|
|
+ " postal=" + w.postcode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 全量物流渠道:验证无参数 POST 与 data 是数组。 */
|
|
|
|
|
@Test
|
|
|
|
|
void probeAllCarrierServices() {
|
|
|
|
|
assumeToken();
|
|
|
|
|
run("POST /v2/carrierGroup/getCarrierGroup", new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
List<LogisticsProduct> list = adapter().products(ctx(), PROVIDER_WAREHOUSE);
|
|
|
|
|
System.out.println(" 返回 " + list.size() + " 个物流产品");
|
|
|
|
|
for (int i = 0; i < Math.min(list.size(), 10); i++) {
|
|
|
|
|
LogisticsProduct p = list.get(i);
|
|
|
|
|
System.out.println(" [" + i + "] code=" + p.logisticsProductCode()
|
|
|
|
|
+ " name=" + p.logisticsProductName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 按仓过滤的物流渠道:验证 data 是「仓代码 → 数组」的对象。 */
|
|
|
|
|
@Test
|
|
|
|
|
void probeWarehouseCarrierServices() {
|
|
|
|
|
assumeToken();
|
|
|
|
|
run("POST /v2/carrierGroup/getWarehouseCarrierGroupServices", new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
List<LogisticsProduct> list = adapter().productsOfWarehouse(ctx(), PROVIDER_WAREHOUSE);
|
|
|
|
|
System.out.println(" 仓 " + PROVIDER_WAREHOUSE + " 返回 " + list.size() + " 个物流产品");
|
|
|
|
|
for (int i = 0; i < Math.min(list.size(), 10); i++) {
|
|
|
|
|
System.out.println(" [" + i + "] code=" + list.get(i).logisticsProductCode()
|
|
|
|
|
+ " name=" + list.get(i).logisticsProductName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 承运商代码清单(走同一个全量接口,验证去重)。 */
|
|
|
|
|
@Test
|
|
|
|
|
void probeCarrierCodes() {
|
|
|
|
|
assumeToken();
|
|
|
|
|
run("POST /v2/carrierGroup/getCarrierGroup (carriers)", new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
List<String> codes = adapter().carriers(ctx());
|
|
|
|
|
System.out.println(" 去重后 " + codes.size() + " 个 code:" + codes);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 订单详情:只按来源单号查,需要 {@code -Dhengjian.probe.orderNo}。 */
|
|
|
|
|
@Test
|
|
|
|
|
void probeOrderDetail() {
|
|
|
|
|
assumeToken();
|
|
|
|
|
final String orderNo = opt("hengjian.probe.orderNo", "");
|
|
|
|
|
Assumptions.assumeTrue(!orderNo.isEmpty(),
|
|
|
|
|
"未提供 -Dhengjian.probe.orderNo,跳过订单详情探针");
|
|
|
|
|
run("POST /v1/saleOrder/findOne", new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
OutboundOrder order = adapter().get(ctx(), OutboundRef.ofRequestNo(orderNo));
|
|
|
|
|
if (order == null) {
|
|
|
|
|
System.out.println(" [空] 未找到该单");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
System.out.println(" status=" + order.status()
|
|
|
|
|
+ " rawStatus=" + order.rawStatus()
|
|
|
|
|
+ " providerOrderId=" + order.providerOrderId()
|
|
|
|
|
+ " tracking=" + order.trackingNumber()
|
|
|
|
|
+ " paidAt=" + order.paidAt()
|
|
|
|
|
+ " shippedAt=" + order.shippedAt()
|
|
|
|
|
+ " fee=" + order.estimatedShippingFee());
|
|
|
|
|
System.out.println(" 行数=" + order.lines().size()
|
|
|
|
|
+ " 附件数=" + order.attachments().size()
|
|
|
|
|
+ " exception=" + order.exceptionCode());
|
|
|
|
|
for (OutboundLine line : order.lines()) {
|
|
|
|
|
System.out.println(" line sku=" + line.providerSku()
|
|
|
|
|
+ " qty=" + line.quantity()
|
|
|
|
|
+ " total=" + line.totalAmount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 订单列表:按时间窗查,核对分页结构与 {@code orderId} 是否真回。
|
|
|
|
|
*
|
|
|
|
|
* <p>需要 {@code -Dhengjian.probe.begin=yyyy-MM-dd} 与 {@code -Dhengjian.probe.end=yyyy-MM-dd},
|
|
|
|
|
* 跨度不超过 30 天。</p>
|
|
|
|
|
*/
|
|
|
|
|
@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<OutboundOrder> page = adapter().query(ctx(), query);
|
|
|
|
|
System.out.println(" 本页 " + page.size() + " 条, 有下一页=" + page.hasMore()
|
|
|
|
|
+ ", 游标=" + page.nextCursor());
|
|
|
|
|
for (OutboundOrder order : page.items()) {
|
|
|
|
|
System.out.println(" orderNo=" + order.outboundRequestNo()
|
|
|
|
|
+ " orderId=" + order.providerOrderId()
|
|
|
|
|
+ " status=" + order.rawStatus()
|
|
|
|
|
+ " carrier=" + order.carrierCode()
|
|
|
|
|
+ " shippedAt=" + order.shippedAt());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|