Browse Source
- 新增订单一单多件:POST api.add_order_multiple,multipart/form-data, products 字段是 JSON 字符串;返回 rst.order_no 作为仓侧单号 - 新增转运:POST fba.do_fba,application/json,返回 rst.order_no, 创建后处于待审核 - 转运审核:POST fba.do_approve,无请求体,token 与 order_no 都在 query 仓库域内核的配套扩展(YQN 不受影响,原有测试全绿): - OutboundCommand 增加 splitOrder,仅声明了 SPLIT 的仓解释 - TransferCommand 增加 po / orderType / deliveryMode / deliveryWay / otherWarehouseName / labelRequirements / palletRequired / 各类贴标份数 - TransferCapable 增加默认 approve(不支持的仓显式拒绝), WarehouseOperations.approveTransfer 走幂等守卫,动作键 approve 字段映射的取舍: - logistics_type 用 carrierCode 承载;ckh 用 outboundRequestNo(要求唯一) - is_sign 模型无对应字段,固定发「否」 - order_type:Wayfair → wayfair,其余 → common - 地址超过 32 字符的部分自动拆到 address2 - 字典字段(orderType / deliveryMode / deliveryWay / labelRequirements) 只接受仓方字典原值,SDK 不做归一 - 信仓这版不收申报信息与包裹尺寸,统一模型里的对应字段不发送 - 转运仅支持 TransferType.OUTBOUND(信仓转运 = 仓到平台仓)feature/supplier-lingxing
17 changed files with 1434 additions and 24 deletions
@ -0,0 +1,179 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.http.JsonCodec; |
||||||
|
import common.ecommerce.shared.error.ChannelException; |
||||||
|
import common.ecommerce.shared.error.ValidationException; |
||||||
|
import common.ecommerce.shared.model.Platform; |
||||||
|
import common.ecommerce.warehouse.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.OutboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.OutboundLine; |
||||||
|
import common.ecommerce.warehouse.model.ShipTo; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import common.ecommerce.xincang.dto.XincangDtos; |
||||||
|
|
||||||
|
import java.time.Instant; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓出库下单报文映射({@code POST api.add_order_multiple})。 |
||||||
|
* |
||||||
|
* <p>该接口是 {@code multipart/form-data},{@code products} 字段本身是一段 JSON 字符串。 |
||||||
|
* 平台字段名只出现在本类与 {@link XincangDtos}。</p> |
||||||
|
* |
||||||
|
* <p>文档没有对应字段的就不发:申报信息(HS / 原产国 / 申报价值)、包裹尺寸等 |
||||||
|
* 统一模型里有,但信仓这版接口不收,硬塞只会被忽略或报错。</p> |
||||||
|
*/ |
||||||
|
public final class XincangOrderMapper { |
||||||
|
|
||||||
|
/** 信仓要求发货时间格式 {@code yyyy-MM-dd HH:mm:ss}(北京时间)。 */ |
||||||
|
private static final DateTimeFormatter REQUIRED_DELIVERY_TIME = |
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||||
|
/** 地址 1 上限 32 字符,超出部分走 address2。 */ |
||||||
|
private static final int ADDRESS_MAX = 32; |
||||||
|
/** 订单类型:信仓只接受 common / wayfair。 */ |
||||||
|
static final String ORDER_TYPE_COMMON = "common"; |
||||||
|
static final String ORDER_TYPE_WAYFAIR = "wayfair"; |
||||||
|
/** 签名服务:信仓只收「是 / 否」,模型里没有该字段,默认否。 */ |
||||||
|
private static final String SIGN_NOT_REQUIRED = "否"; |
||||||
|
|
||||||
|
private XincangOrderMapper() { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 统一命令 → 信仓一单多件下单表单。 |
||||||
|
* |
||||||
|
* @param ctx 本次调用上下文(取仓编码) |
||||||
|
* @param cmd 出库命令 |
||||||
|
* @param json 用于序列化 {@code products} |
||||||
|
* @throws ValidationException 缺少仓编码或收件人必填项 |
||||||
|
*/ |
||||||
|
public static Map<String, String> toForm(WarehouseContext ctx, OutboundCommand cmd, JsonCodec json) { |
||||||
|
ShipTo shipTo = cmd.shipTo(); |
||||||
|
requireText(shipTo.name(), "shipTo.name", ctx); |
||||||
|
requireText(shipTo.phone(), "shipTo.phone", ctx); |
||||||
|
requireText(shipTo.countryCode(), "shipTo.countryCode", ctx); |
||||||
|
requireText(shipTo.stateOrProvince(), "shipTo.stateOrProvince", ctx); |
||||||
|
requireText(shipTo.city(), "shipTo.city", ctx); |
||||||
|
requireText(shipTo.postalCode(), "shipTo.postalCode", ctx); |
||||||
|
requireText(shipTo.addressLine1(), "shipTo.addressLine1", ctx); |
||||||
|
|
||||||
|
String warehouseCode = firstNonBlank(cmd.warehouseId(), ctx.providerWarehouseId()); |
||||||
|
requireText(warehouseCode, "warehouseCode", ctx); |
||||||
|
// 信仓 logistics_type 是必填的物流方式字典值,这里用 carrierCode 承载
|
||||||
|
requireText(cmd.carrierCode(), "carrierCode (信仓 logistics_type)", ctx); |
||||||
|
|
||||||
|
Map<String, String> form = new LinkedHashMap<String, String>(); |
||||||
|
form.put("order_type", orderTypeOf(cmd.salesPlatform())); |
||||||
|
form.put("warehouse_code", warehouseCode); |
||||||
|
// ckh = 参考号,信仓要求唯一;用 OMS 出库单号,便于回查
|
||||||
|
form.put("ckh", cmd.outboundRequestNo()); |
||||||
|
|
||||||
|
Address address = splitAddress(shipTo.addressLine1()); |
||||||
|
form.put("country", shipTo.countryCode().trim()); |
||||||
|
form.put("province", shipTo.stateOrProvince().trim()); |
||||||
|
form.put("city", shipTo.city().trim()); |
||||||
|
form.put("address", address.line1); |
||||||
|
putIfPresent(form, "address2", address.line2); |
||||||
|
form.put("postcode", shipTo.postalCode().trim()); |
||||||
|
form.put("receive_user", shipTo.name().trim()); |
||||||
|
form.put("phone", shipTo.phone().trim()); |
||||||
|
putIfPresent(form, "email", shipTo.email()); |
||||||
|
form.put("logistics_type", cmd.carrierCode().trim()); |
||||||
|
form.put("is_sign", SIGN_NOT_REQUIRED); |
||||||
|
form.put("products", productsJson(cmd.lines(), json)); |
||||||
|
|
||||||
|
// 不传 is_split 时信仓默认 1(拆单);只有调用方显式给值才下发
|
||||||
|
if (cmd.splitOrder() != null) { |
||||||
|
form.put("is_split", cmd.splitOrder() ? "1" : "0"); |
||||||
|
} |
||||||
|
Instant latest = cmd.latestShipDate(); |
||||||
|
if (latest != null) { |
||||||
|
form.put("required_delivery_time", REQUIRED_DELIVERY_TIME.format( |
||||||
|
LocalDateTime.ofInstant(latest, XincangConstants.SYSTEM_ZONE))); |
||||||
|
} |
||||||
|
putIfPresent(form, "remark", cmd.remark()); |
||||||
|
return form; |
||||||
|
} |
||||||
|
|
||||||
|
/** 商品明细:{@code [{"product_sku":"...","sku_count":"1"}, ...]}。 */ |
||||||
|
static String productsJson(List<OutboundLine> lines, JsonCodec json) { |
||||||
|
List<XincangDtos.OrderProduct> products = new ArrayList<XincangDtos.OrderProduct>(lines.size()); |
||||||
|
for (OutboundLine line : lines) { |
||||||
|
XincangDtos.OrderProduct product = new XincangDtos.OrderProduct(); |
||||||
|
product.productSku = skuOf(line); |
||||||
|
product.skuCount = String.valueOf(line.quantity()); |
||||||
|
products.add(product); |
||||||
|
} |
||||||
|
return json.toJson(products); |
||||||
|
} |
||||||
|
|
||||||
|
/** 仓侧 SKU 优先;没有映射时用 OMS 主 SKU。 */ |
||||||
|
static String skuOf(OutboundLine line) { |
||||||
|
String providerSku = line.providerSku(); |
||||||
|
if (providerSku != null && !providerSku.trim().isEmpty()) { |
||||||
|
return providerSku.trim(); |
||||||
|
} |
||||||
|
return line.omsSku(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓订单类型只接受 {@code common} / {@code wayfair}。 |
||||||
|
* |
||||||
|
* <p>Wayfair 渠道走 {@code wayfair};其余平台走 {@code common}。 |
||||||
|
* 信仓不区分其它平台,不做臆造映射。</p> |
||||||
|
*/ |
||||||
|
static String orderTypeOf(Platform platform) { |
||||||
|
return platform == Platform.WAYFAIR ? ORDER_TYPE_WAYFAIR : ORDER_TYPE_COMMON; |
||||||
|
} |
||||||
|
|
||||||
|
/** 地址超过 32 字符的部分截到 address2,避免被仓侧截断丢信息。 */ |
||||||
|
static Address splitAddress(String address) { |
||||||
|
String trimmed = address.trim(); |
||||||
|
if (trimmed.length() <= ADDRESS_MAX) { |
||||||
|
return new Address(trimmed, null); |
||||||
|
} |
||||||
|
return new Address(trimmed.substring(0, ADDRESS_MAX), trimmed.substring(ADDRESS_MAX)); |
||||||
|
} |
||||||
|
|
||||||
|
/** 拆好的地址。 */ |
||||||
|
static final class Address { |
||||||
|
final String line1; |
||||||
|
final String line2; |
||||||
|
|
||||||
|
Address(String line1, String line2) { |
||||||
|
this.line1 = line1; |
||||||
|
this.line2 = line2; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void putIfPresent(Map<String, String> form, String key, String value) { |
||||||
|
if (value != null && !value.trim().isEmpty()) { |
||||||
|
form.put(key, value.trim()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String requireText(String value, String field, WarehouseContext ctx) { |
||||||
|
if (value == null || value.trim().isEmpty()) { |
||||||
|
throw new ValidationException(ChannelException.builder() |
||||||
|
.message("xincang outbound requires " + field) |
||||||
|
.operation("warehouse.outbound.create") |
||||||
|
.provider(WarehouseProvider.XINCANG.name()) |
||||||
|
.requestId(ctx.requestId()) |
||||||
|
.retryable(false)); |
||||||
|
} |
||||||
|
return value.trim(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String firstNonBlank(String a, String b) { |
||||||
|
if (a != null && !a.trim().isEmpty()) { |
||||||
|
return a.trim(); |
||||||
|
} |
||||||
|
return b == null ? null : b.trim(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,154 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.shared.error.ChannelException; |
||||||
|
import common.ecommerce.shared.error.ValidationException; |
||||||
|
import common.ecommerce.warehouse.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.TransferCommand; |
||||||
|
import common.ecommerce.warehouse.model.TransferOrder; |
||||||
|
import common.ecommerce.warehouse.model.TransferStatus; |
||||||
|
import common.ecommerce.warehouse.model.TransferType; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.xincang.dto.XincangDtos; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓转运 / 调拨报文映射({@code POST fba.do_fba})。 |
||||||
|
* |
||||||
|
* <p>信仓的「转运」= 从信仓发货到平台仓(FBA / 其它),在统一模型里对应 |
||||||
|
* {@link TransferType#OUTBOUND}:发货仓是信仓自己,目的仓是平台仓。</p> |
||||||
|
* |
||||||
|
* <p>字典字段({@code order_type} / {@code delivery_mode} / {@code delivery_way} / |
||||||
|
* {@code label_requirement})信仓只认它自己字典的原值,调用方需从字典接口取; |
||||||
|
* SDK 不做枚举归一,也不猜测取值。</p> |
||||||
|
*/ |
||||||
|
public final class XincangTransferMapper { |
||||||
|
|
||||||
|
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||||
|
/** 目的仓不在字典里时的固定写法(文档要求)。 */ |
||||||
|
static final String OTHER_WAREHOUSE_NAME = "其他仓库"; |
||||||
|
/** 标签需求多选分隔符。 */ |
||||||
|
private static final String LABEL_SEPARATOR = ","; |
||||||
|
|
||||||
|
private XincangTransferMapper() { |
||||||
|
} |
||||||
|
|
||||||
|
/** 统一命令 → 信仓新增转运请求。 */ |
||||||
|
public static XincangDtos.TransferRequest toRequest(TransferCommand cmd, WarehouseContext ctx, |
||||||
|
String productsJson) { |
||||||
|
if (cmd.type() != TransferType.OUTBOUND) { |
||||||
|
throw validation(ctx, "xincang transfer only supports OUTBOUND (warehouse -> platform), got " |
||||||
|
+ cmd.type()); |
||||||
|
} |
||||||
|
XincangDtos.TransferRequest req = new XincangDtos.TransferRequest(); |
||||||
|
req.fbaNo = cmd.transferRequestNo(); |
||||||
|
req.po = firstNonBlank(cmd.po(), cmd.transferRequestNo()); |
||||||
|
req.fromWarehouseName = require(cmd.fromWarehouseCode(), |
||||||
|
"fromWarehouseCode (信仓 from_warehouse_name)", ctx); |
||||||
|
req.destWarehouseName = require(cmd.toWarehouseCode(), |
||||||
|
"toWarehouseCode (信仓 dest_warehouse_name)", ctx); |
||||||
|
req.otherWarehouse = blankToNull(cmd.otherWarehouseName()); |
||||||
|
req.orderType = blankToNull(cmd.orderType()); |
||||||
|
req.deliveryMode = require(cmd.deliveryMode(), "deliveryMode (信仓转运类型字典值)", ctx); |
||||||
|
req.deliveryWay = require(cmd.deliveryWay(), "deliveryWay (信仓转运方式字典值)", ctx); |
||||||
|
req.preSendTime = formatDate(cmd.estimateOutboundDate()); |
||||||
|
if (req.preSendTime == null) { |
||||||
|
throw validation(ctx, "estimateOutboundDate is required (信仓 pre_send_time)"); |
||||||
|
} |
||||||
|
if (cmd.palletRequired() == null) { |
||||||
|
throw validation(ctx, "palletRequired is required (信仓 is_pallet)"); |
||||||
|
} |
||||||
|
req.isPallet = booleanText(cmd.palletRequired()); |
||||||
|
req.labelRequirement = cmd.labelRequirements().isEmpty() ? null : join(cmd.labelRequirements()); |
||||||
|
req.products = productsJson; |
||||||
|
req.remark = blankToNull(cmd.remark()); |
||||||
|
req.productPrintCopies = copies(cmd.productLabelCopies()); |
||||||
|
req.ctnPrintCopies = copies(cmd.cartonLabelCopies()); |
||||||
|
req.palletPrintCopies = copies(cmd.palletLabelCopies()); |
||||||
|
return req; |
||||||
|
} |
||||||
|
|
||||||
|
/** 转运单创建结果 → 统一模型;信仓只回 {@code order_no},其余字段留空。 */ |
||||||
|
public static TransferOrder toCreated(TransferCommand cmd, String providerTransferNo) { |
||||||
|
return TransferOrder.builder() |
||||||
|
.transferRequestNo(cmd.transferRequestNo()) |
||||||
|
.providerTransferNo(providerTransferNo) |
||||||
|
.fromWarehouseCode(cmd.fromWarehouseCode()) |
||||||
|
.toWarehouseCode(cmd.toWarehouseCode()) |
||||||
|
.type(cmd.type()) |
||||||
|
// 新增成功后处于待审核;审核走 approve
|
||||||
|
.status(TransferStatus.PENDING_REVIEW) |
||||||
|
.rawStatus("0") |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
/** 产品明细:{@code [{"product_no":"SKU","sku_count":"1"}]}。 */ |
||||||
|
public static List<XincangDtos.TransferProduct> products(TransferCommand cmd) { |
||||||
|
List<XincangDtos.TransferProduct> products = |
||||||
|
new ArrayList<XincangDtos.TransferProduct>(cmd.lines().size()); |
||||||
|
for (TransferCommand.TransferLine line : cmd.lines()) { |
||||||
|
XincangDtos.TransferProduct product = new XincangDtos.TransferProduct(); |
||||||
|
product.productNo = line.providerSku(); |
||||||
|
product.skuCount = String.valueOf(line.quantity()); |
||||||
|
products.add(product); |
||||||
|
} |
||||||
|
return products; |
||||||
|
} |
||||||
|
|
||||||
|
/** 打托:true → 是 / false → 否 / null → 不传。 */ |
||||||
|
private static String booleanText(Boolean value) { |
||||||
|
if (value == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return value ? "是" : "否"; |
||||||
|
} |
||||||
|
|
||||||
|
private static String copies(Integer copies) { |
||||||
|
return copies == null ? null : String.valueOf(copies); |
||||||
|
} |
||||||
|
|
||||||
|
private static String formatDate(LocalDate date) { |
||||||
|
return date == null ? null : DATE.format(date); |
||||||
|
} |
||||||
|
|
||||||
|
private static String join(List<String> values) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for (String value : values) { |
||||||
|
if (sb.length() > 0) { |
||||||
|
sb.append(LABEL_SEPARATOR); |
||||||
|
} |
||||||
|
sb.append(value); |
||||||
|
} |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String require(String value, String field, WarehouseContext ctx) { |
||||||
|
if (value == null || value.trim().isEmpty()) { |
||||||
|
throw validation(ctx, field + " is required for xincang transfer"); |
||||||
|
} |
||||||
|
return value.trim(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String firstNonBlank(String a, String fallback) { |
||||||
|
if (a != null && !a.trim().isEmpty()) { |
||||||
|
return a.trim(); |
||||||
|
} |
||||||
|
return fallback; |
||||||
|
} |
||||||
|
|
||||||
|
private static String blankToNull(String v) { |
||||||
|
return v == null || v.trim().isEmpty() ? null : v.trim(); |
||||||
|
} |
||||||
|
|
||||||
|
private static ValidationException validation(WarehouseContext ctx, String message) { |
||||||
|
return new ValidationException(ChannelException.builder() |
||||||
|
.message(message) |
||||||
|
.operation("warehouse.transfer.create") |
||||||
|
.provider(WarehouseProvider.XINCANG.name()) |
||||||
|
.requestId(ctx.requestId()) |
||||||
|
.retryable(false)); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.shared.error.ChannelException; |
||||||
|
import common.ecommerce.shared.error.ValidationException; |
||||||
|
import common.ecommerce.warehouse.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓暂时不支持的出库 / 调拨能力。 |
||||||
|
* |
||||||
|
* <p>本轮只接入「新增订单」与「转运创建 / 审核」,查询、取消、包裹都还没接。 |
||||||
|
* 这里统一抛 {@link ValidationException}({@code retryable=false}),<b>不返回空集合</b>—— |
||||||
|
* 静默返回 {@code null} / 空会让调用方以为「仓说没有这单」。</p> |
||||||
|
*/ |
||||||
|
final class XincangUnsupportedOutbound { |
||||||
|
|
||||||
|
private XincangUnsupportedOutbound() { |
||||||
|
} |
||||||
|
|
||||||
|
static ValidationException queryUnsupported(WarehouseContext ctx) { |
||||||
|
throw unsupported(ctx, "warehouse.outbound.query"); |
||||||
|
} |
||||||
|
|
||||||
|
static ValidationException getUnsupported(WarehouseContext ctx) { |
||||||
|
throw unsupported(ctx, "warehouse.outbound.get"); |
||||||
|
} |
||||||
|
|
||||||
|
static ValidationException checkCancelUnsupported(WarehouseContext ctx) { |
||||||
|
throw unsupported(ctx, "warehouse.outbound.checkCancel"); |
||||||
|
} |
||||||
|
|
||||||
|
static ValidationException cancelUnsupported(WarehouseContext ctx) { |
||||||
|
throw unsupported(ctx, "warehouse.outbound.cancel"); |
||||||
|
} |
||||||
|
|
||||||
|
static ValidationException packagesUnsupported(WarehouseContext ctx) { |
||||||
|
throw unsupported(ctx, "warehouse.outbound.packages"); |
||||||
|
} |
||||||
|
|
||||||
|
private static ValidationException unsupported(WarehouseContext ctx, String operation) { |
||||||
|
return new ValidationException(ChannelException.builder() |
||||||
|
.message("xincang does not implement " + operation + " yet") |
||||||
|
.operation(operation) |
||||||
|
.provider(WarehouseProvider.XINCANG.name()) |
||||||
|
.requestId(ctx.requestId()) |
||||||
|
.retryable(false)); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
package common.ecommerce.xincang.http; |
||||||
|
|
||||||
|
import common.ecommerce.http.HttpRequest; |
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.net.URLEncoder; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.TreeMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* multipart/form-data 请求体构造。 |
||||||
|
* |
||||||
|
* <p>信仓「新增订单一单多件」要求 {@code multipart/form-data},字段值里的 |
||||||
|
* {@code products} 本身就是一段 JSON 字符串。这里用固定 boundary, |
||||||
|
* 保证同一份入参生成的报文每次都一样,便于契约测试断言。</p> |
||||||
|
*/ |
||||||
|
public final class XincangMultipart { |
||||||
|
|
||||||
|
/** 固定 boundary:报文可预测。 */ |
||||||
|
static final String BOUNDARY = "----commonEcommerceXincangBoundary"; |
||||||
|
/** 与 boundary 配套的 Content-Type。 */ |
||||||
|
public static final String CONTENT_TYPE = "multipart/form-data; boundary=" + BOUNDARY; |
||||||
|
|
||||||
|
private XincangMultipart() { |
||||||
|
} |
||||||
|
|
||||||
|
/** 构造一个不带文件、只有文本字段的 multipart 请求。 */ |
||||||
|
public static HttpRequest post(String baseUrl, String path, Map<String, String> form, |
||||||
|
String token, String operation) { |
||||||
|
return HttpRequest.builder() |
||||||
|
.method("POST") |
||||||
|
.url(trimTrailingSlash(baseUrl) + path |
||||||
|
+ "?token=" + urlEncode(token)) |
||||||
|
.contentType(CONTENT_TYPE) |
||||||
|
.body(body(form)) |
||||||
|
.operation(operation) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 字段按 key 升序输出(信仓文档不要求顺序,固定顺序只为可断言)。 |
||||||
|
* |
||||||
|
* <p>值为 null 的字段跳过——可选字段没给就不发,避免把空串误当成业务值。</p> |
||||||
|
*/ |
||||||
|
static String body(Map<String, String> form) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
Map<String, String> sorted = new TreeMap<String, String>(); |
||||||
|
if (form != null) { |
||||||
|
for (Map.Entry<String, String> e : form.entrySet()) { |
||||||
|
if (e.getValue() != null) { |
||||||
|
sorted.put(e.getKey(), e.getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
for (Map.Entry<String, String> e : sorted.entrySet()) { |
||||||
|
sb.append("--").append(BOUNDARY).append("\r\n") |
||||||
|
.append("Content-Disposition: form-data; name=\"").append(e.getKey()).append("\"\r\n") |
||||||
|
.append("\r\n") |
||||||
|
.append(e.getValue()).append("\r\n"); |
||||||
|
} |
||||||
|
sb.append("--").append(BOUNDARY).append("--\r\n"); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String trimTrailingSlash(String url) { |
||||||
|
String trimmed = url.trim(); |
||||||
|
int end = trimmed.length(); |
||||||
|
while (end > 0 && trimmed.charAt(end - 1) == '/') { |
||||||
|
end--; |
||||||
|
} |
||||||
|
return trimmed.substring(0, end); |
||||||
|
} |
||||||
|
|
||||||
|
private static String urlEncode(String v) { |
||||||
|
try { |
||||||
|
return URLEncoder.encode(v == null ? "" : v, "UTF-8"); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
throw new IllegalStateException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,178 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryLockProvider; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryTokenStore; |
||||||
|
import common.ecommerce.shared.testkit.MutableClock; |
||||||
|
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
|
import common.ecommerce.shared.testkit.Responses; |
||||||
|
import common.ecommerce.shared.model.Platform; |
||||||
|
import common.ecommerce.warehouse.WarehouseCapability; |
||||||
|
import common.ecommerce.warehouse.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.LabelMode; |
||||||
|
import common.ecommerce.warehouse.model.OutboundCommand; |
||||||
|
import common.ecommerce.warehouse.model.OutboundLine; |
||||||
|
import common.ecommerce.warehouse.model.OutboundReceipt; |
||||||
|
import common.ecommerce.warehouse.model.ShipTo; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import org.junit.jupiter.api.BeforeEach; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
import java.time.Duration; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓出库下单(一单多件)契约测试。 |
||||||
|
*/ |
||||||
|
class XincangOrderTest { |
||||||
|
|
||||||
|
private static final String BASE = XincangConstants.TEST_BASE_URL; |
||||||
|
private static final String APP_KEY = "ak-1"; |
||||||
|
private static final String TOKEN = "{T-1}"; |
||||||
|
|
||||||
|
private RecordingTransport transport; |
||||||
|
private MutableClock clock; |
||||||
|
private XincangAdapter adapter; |
||||||
|
|
||||||
|
@BeforeEach |
||||||
|
void setUp() { |
||||||
|
transport = RecordingTransport.create(); |
||||||
|
clock = MutableClock.atUtc("2026-11-10T00:00:00Z"); |
||||||
|
transport.route(XincangConstants.PATH_LOGIN, req -> Responses.ok( |
||||||
|
"{\"rst\":{\"id\":\"c-1\",\"token\":\"" + TOKEN + "\",\"token_expire_time\":\"" |
||||||
|
+ java.time.LocalDateTime.ofInstant(clock.instant().plus(Duration.ofHours(2)), |
||||||
|
XincangConstants.SYSTEM_ZONE) |
||||||
|
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) |
||||||
|
+ "\"},\"errno\":0,\"err\":\"\",\"trace_id\":\"t-login\"}")); |
||||||
|
adapter = new XincangAdapter(transport, new common.ecommerce.http.JacksonJsonCodec(), |
||||||
|
new InMemoryTokenStore(), new InMemoryLockProvider(), clock); |
||||||
|
} |
||||||
|
|
||||||
|
private static WarehouseContext ctx() { |
||||||
|
return WarehouseContext.of("XC-CA-3790", WarehouseProvider.XINCANG, "CA-3790", |
||||||
|
WarehouseConnection.of(BASE, ChannelSecret.builder() |
||||||
|
.appKey(APP_KEY).appSecret("sk").build()), |
||||||
|
"req-1", Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
private static OutboundCommand command(Boolean split) { |
||||||
|
OutboundCommand.Builder b = OutboundCommand.builder() |
||||||
|
.outboundRequestNo("OB-20261110-001") |
||||||
|
.orderRef("SO-1") |
||||||
|
.labelMode(LabelMode.WAREHOUSE_LABEL) |
||||||
|
.salesPlatform(Platform.AMAZON_SC) |
||||||
|
.carrierCode("FEDEX-G") |
||||||
|
.warehouseId("CA-3790") |
||||||
|
.shipTo(ShipTo.builder() |
||||||
|
.name("Receiver") |
||||||
|
.phone("5550000") |
||||||
|
.countryCode("US") |
||||||
|
.stateOrProvince("CA") |
||||||
|
.city("Fontana") |
||||||
|
.addressLine1("3790 DE FOREST CIRCLE, UNIT B, EXTRA LONG SUFFIX") |
||||||
|
.postalCode("92337") |
||||||
|
.build()) |
||||||
|
.line(OutboundLine.builder().lineNo("1").omsSku("SKU-A").quantity(2).build()) |
||||||
|
.line(OutboundLine.builder().lineNo("2").omsSku("SKU-B").providerSku("SKU-B-XC") |
||||||
|
.quantity(1).build()); |
||||||
|
if (split != null) { |
||||||
|
b.splitOrder(split); |
||||||
|
} |
||||||
|
return b.build(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void createsMultiLineOrderAsMultipart() { |
||||||
|
transport.route(XincangConstants.PATH_ORDER_ADD_MULTIPLE, req -> Responses.ok( |
||||||
|
"{\"rst\":{\"order_no\":\"DS-B001-26101300025\",\"order_id\":\"125553878740636306\"}," |
||||||
|
+ "\"errno\":0,\"err\":\"\",\"trace_id\":\"t-order\"}")); |
||||||
|
|
||||||
|
OutboundReceipt receipt = adapter.create(ctx(), command(true)); |
||||||
|
|
||||||
|
assertEquals("OB-20261110-001", receipt.outboundRequestNo()); |
||||||
|
assertEquals("DS-B001-26101300025", receipt.providerOrderId()); |
||||||
|
|
||||||
|
common.ecommerce.http.HttpRequest req = transport.lastDataRequest(); |
||||||
|
assertEquals("POST", req.method()); |
||||||
|
assertTrue(req.url().contains("/api.add_order_multiple?token="), req.url()); |
||||||
|
assertTrue(req.contentType().startsWith("multipart/form-data; boundary="), req.contentType()); |
||||||
|
|
||||||
|
String body = req.body(); |
||||||
|
assertTrue(body.contains("name=\"ckh\"\r\n\r\nOB-20261110-001"), body); |
||||||
|
assertTrue(body.contains("name=\"warehouse_code\"\r\n\r\nCA-3790"), body); |
||||||
|
assertTrue(body.contains("name=\"logistics_type\"\r\n\r\nFEDEX-G"), body); |
||||||
|
assertTrue(body.contains("name=\"order_type\"\r\n\r\ncommon"), body); |
||||||
|
assertTrue(body.contains("name=\"is_split\"\r\n\r\n1"), body); |
||||||
|
// 商品明细是一段 JSON 字符串
|
||||||
|
assertTrue(body.contains("\"product_sku\":\"SKU-A\""), body); |
||||||
|
assertTrue(body.contains("\"sku_count\":\"2\""), body); |
||||||
|
// 仓侧 SKU 优先
|
||||||
|
assertTrue(body.contains("\"product_sku\":\"SKU-B-XC\""), body); |
||||||
|
// 地址超过 32 位走 address2(前 32 字符 = "3790 DE FOREST CIRCLE, UNIT B, E")
|
||||||
|
assertTrue(body.contains("name=\"address\"\r\n\r\n3790 DE FOREST CIRCLE, UNIT B, E\r\n"), body); |
||||||
|
assertTrue(body.contains("name=\"address2\"\r\n\r\nXTRA LONG SUFFIX"), body); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void splitFlagIsOmittedWhenCallerDidNotSetIt() { |
||||||
|
transport.route(XincangConstants.PATH_ORDER_ADD_MULTIPLE, req -> Responses.ok( |
||||||
|
"{\"rst\":{\"order_no\":\"DS-1\",\"order_id\":\"1\"},\"errno\":0,\"err\":\"\"}")); |
||||||
|
|
||||||
|
adapter.create(ctx(), command(null)); |
||||||
|
|
||||||
|
assertFalse(transport.lastDataRequest().body().contains("name=\"is_split\""), |
||||||
|
"未显式指定时交给信仓默认(拆单)"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void missingShipToFieldFailsBeforeSending() { |
||||||
|
transport.route(XincangConstants.PATH_ORDER_ADD_MULTIPLE, req -> Responses.ok("{}")); |
||||||
|
OutboundCommand cmd = OutboundCommand.builder() |
||||||
|
.outboundRequestNo("OB-2") |
||||||
|
.salesPlatform(Platform.AMAZON_SC) |
||||||
|
.carrierCode("FEDEX-G") |
||||||
|
.warehouseId("CA-3790") |
||||||
|
.shipTo(ShipTo.builder().name("R").countryCode("US").stateOrProvince("CA") |
||||||
|
.city("Fontana").addressLine1("1 A St").postalCode("92337").build()) |
||||||
|
.line(OutboundLine.builder().lineNo("1").omsSku("SKU-A").quantity(1).build()) |
||||||
|
.build(); |
||||||
|
|
||||||
|
common.ecommerce.shared.error.ValidationException e = |
||||||
|
assertThrows(common.ecommerce.shared.error.ValidationException.class, |
||||||
|
() -> adapter.create(ctx(), cmd)); |
||||||
|
assertTrue(e.getMessage().contains("shipTo.phone"), e.getMessage()); |
||||||
|
// 登录后即失败,不应发出下单请求
|
||||||
|
assertFalse(transport.recorded().stream().anyMatch( |
||||||
|
r -> r.url().contains(XincangConstants.PATH_ORDER_ADD_MULTIPLE))); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void missingProviderOrderNoIsNotSilentSuccess() { |
||||||
|
transport.route(XincangConstants.PATH_ORDER_ADD_MULTIPLE, req -> Responses.ok( |
||||||
|
"{\"rst\":null,\"errno\":0,\"err\":\"\",\"trace_id\":\"t-x\"}")); |
||||||
|
|
||||||
|
common.ecommerce.warehouse.error.WarehouseException e = |
||||||
|
assertThrows(common.ecommerce.warehouse.error.WarehouseException.class, |
||||||
|
() -> adapter.create(ctx(), command(true))); |
||||||
|
assertTrue(e.getMessage().contains("rst.order_no"), e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void queryAndCancelAreExplicitlyUnsupported() { |
||||||
|
assertThrows(common.ecommerce.shared.error.ValidationException.class, |
||||||
|
() -> adapter.get(ctx(), null)); |
||||||
|
assertThrows(common.ecommerce.shared.error.ValidationException.class, |
||||||
|
() -> adapter.query(ctx(), null)); |
||||||
|
assertFalse(adapter.capabilities().contains(WarehouseCapability.INVENTORY_QUERY)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void outboundCapabilityIsDeclared() { |
||||||
|
assertTrue(adapter.capabilities().contains(WarehouseCapability.OUTBOUND)); |
||||||
|
assertTrue(adapter.supports("XC-CA-3790", WarehouseCapability.SPLIT)); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,195 @@ |
|||||||
|
package common.ecommerce.xincang.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.shared.error.ValidationException; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryLockProvider; |
||||||
|
import common.ecommerce.shared.testkit.InMemoryTokenStore; |
||||||
|
import common.ecommerce.shared.testkit.MutableClock; |
||||||
|
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
|
import common.ecommerce.shared.testkit.Responses; |
||||||
|
import common.ecommerce.warehouse.WarehouseCapability; |
||||||
|
import common.ecommerce.warehouse.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.TransferCommand; |
||||||
|
import common.ecommerce.warehouse.model.TransferOrder; |
||||||
|
import common.ecommerce.warehouse.model.TransferStatus; |
||||||
|
import common.ecommerce.warehouse.model.ShipTo; |
||||||
|
import common.ecommerce.warehouse.model.TransferType; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import common.ecommerce.xincang.XincangConstants; |
||||||
|
import org.junit.jupiter.api.BeforeEach; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
import java.time.Duration; |
||||||
|
import java.time.LocalDate; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 信仓转运:新增({@code fba.do_fba})与审核({@code fba.do_approve})契约测试。 |
||||||
|
*/ |
||||||
|
class XincangTransferTest { |
||||||
|
|
||||||
|
private static final String BASE = XincangConstants.TEST_BASE_URL; |
||||||
|
private static final String APP_KEY = "ak-1"; |
||||||
|
|
||||||
|
private RecordingTransport transport; |
||||||
|
private XincangAdapter adapter; |
||||||
|
|
||||||
|
@BeforeEach |
||||||
|
void setUp() { |
||||||
|
transport = RecordingTransport.create(); |
||||||
|
MutableClock clock = MutableClock.atUtc("2026-11-10T00:00:00Z"); |
||||||
|
transport.route(XincangConstants.PATH_LOGIN, req -> Responses.ok( |
||||||
|
"{\"rst\":{\"id\":\"c-1\",\"token\":\"{T-1}\",\"token_expire_time\":\"" |
||||||
|
+ java.time.LocalDateTime.ofInstant(clock.instant().plus(Duration.ofHours(2)), |
||||||
|
XincangConstants.SYSTEM_ZONE) |
||||||
|
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) |
||||||
|
+ "\"},\"errno\":0,\"err\":\"\",\"trace_id\":\"t-login\"}")); |
||||||
|
adapter = new XincangAdapter(transport, new common.ecommerce.http.JacksonJsonCodec(), |
||||||
|
new InMemoryTokenStore(), new InMemoryLockProvider(), clock); |
||||||
|
} |
||||||
|
|
||||||
|
private static WarehouseContext ctx() { |
||||||
|
return WarehouseContext.of("XC-CA-3790", WarehouseProvider.XINCANG, "CA-3790", |
||||||
|
WarehouseConnection.of(BASE, ChannelSecret.builder() |
||||||
|
.appKey(APP_KEY).appSecret("sk").build()), |
||||||
|
"req-1", Clock.systemUTC()); |
||||||
|
} |
||||||
|
|
||||||
|
private static TransferCommand command() { |
||||||
|
return TransferCommand.builder() |
||||||
|
.transferRequestNo("TR-20261110-001") |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode("CA-3790") |
||||||
|
.toWarehouseCode("ONT8") |
||||||
|
.po("PO-58016") |
||||||
|
.orderType("FBA") |
||||||
|
.deliveryMode("FBA") |
||||||
|
.deliveryWay("Amazon(亚马逊卡车自提)") |
||||||
|
.estimateOutboundDate(LocalDate.parse("2026-11-12")) |
||||||
|
.estimateInboundDate(LocalDate.parse("2026-11-20")) |
||||||
|
.shipTo(ShipTo.builder().name("FBA").countryCode("US").stateOrProvince("CA") |
||||||
|
.city("San Bernardino").addressLine1("1 Amazon Way").postalCode("92408").build()) |
||||||
|
.palletRequired(true) |
||||||
|
.labelRequirement("产品贴") |
||||||
|
.labelRequirement("外箱标签") |
||||||
|
.productLabelCopies(4) |
||||||
|
.cartonLabelCopies(2) |
||||||
|
.remark("测试转运") |
||||||
|
.line("LSS29ORANGE", 5) |
||||||
|
.line("LSS29BLUE", 1) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void createsTransferWithJsonBody() { |
||||||
|
transport.route(XincangConstants.PATH_TRANSFER_CREATE, req -> Responses.ok( |
||||||
|
"{\"rst\":{\"order_no\":\"LTL26101500002\"},\"errno\":0,\"err\":\"\",\"trace_id\":\"t-fba\"}")); |
||||||
|
|
||||||
|
TransferOrder order = adapter.create(ctx(), command()); |
||||||
|
|
||||||
|
assertEquals("TR-20261110-001", order.transferRequestNo()); |
||||||
|
assertEquals("LTL26101500002", order.providerTransferNo()); |
||||||
|
assertEquals(TransferStatus.PENDING_REVIEW, order.status()); |
||||||
|
|
||||||
|
common.ecommerce.http.HttpRequest req = transport.lastDataRequest(); |
||||||
|
assertEquals("POST", req.method()); |
||||||
|
assertTrue(req.url().contains("/fba.do_fba?token="), req.url()); |
||||||
|
String body = req.body(); |
||||||
|
assertTrue(body.contains("\"fba_no\":\"TR-20261110-001\""), body); |
||||||
|
assertTrue(body.contains("\"po\":\"PO-58016\""), body); |
||||||
|
assertTrue(body.contains("\"from_warehouse_name\":\"CA-3790\""), body); |
||||||
|
assertTrue(body.contains("\"dest_warehouse_name\":\"ONT8\""), body); |
||||||
|
assertTrue(body.contains("\"delivery_mode\":\"FBA\""), body); |
||||||
|
assertTrue(body.contains("\"delivery_way\":\"Amazon(亚马逊卡车自提)\""), body); |
||||||
|
assertTrue(body.contains("\"pre_send_time\":\"2026-11-12\""), body); |
||||||
|
assertTrue(body.contains("\"is_pallet\":\"是\""), body); |
||||||
|
assertTrue(body.contains("\"label_requirement\":\"产品贴,外箱标签\""), body); |
||||||
|
assertTrue(body.contains("\"product_print_copies\":\"4\""), body); |
||||||
|
assertTrue(body.contains("\"ctn_print_copies\":\"2\""), body); |
||||||
|
// products 是 JSON 字符串
|
||||||
|
assertTrue(body.contains("\\\"product_no\\\":\\\"LSS29ORANGE\\\""), body); |
||||||
|
assertTrue(body.contains("\\\"sku_count\\\":\\\"5\\\""), body); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void approvePostsOrderNoInQueryWithoutBody() { |
||||||
|
transport.route(XincangConstants.PATH_TRANSFER_APPROVE, req -> Responses.ok( |
||||||
|
"{\"rst\":true,\"errno\":0,\"err\":\"\",\"trace_id\":\"t-approve\"}")); |
||||||
|
|
||||||
|
adapter.approve(ctx(), "LTL26101500002"); |
||||||
|
|
||||||
|
common.ecommerce.http.HttpRequest req = transport.lastDataRequest(); |
||||||
|
assertEquals("POST", req.method()); |
||||||
|
assertTrue(req.url().contains("/fba.do_approve?"), req.url()); |
||||||
|
assertTrue(req.url().contains("order_no=LTL26101500002"), req.url()); |
||||||
|
assertTrue(req.url().contains("token=%7BT-1%7D"), req.url()); |
||||||
|
assertNull(req.body(), "转运审核无请求体"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void approveFailurePropagatesBusinessError() { |
||||||
|
transport.route(XincangConstants.PATH_TRANSFER_APPROVE, req -> Responses.ok( |
||||||
|
"{\"rst\":null,\"errno\":-1,\"err\":\"转运单状态不允许审核\",\"trace_id\":\"t-bad\"}")); |
||||||
|
|
||||||
|
common.ecommerce.shared.error.PlatformBusinessException e = |
||||||
|
assertThrows(common.ecommerce.shared.error.PlatformBusinessException.class, |
||||||
|
() -> adapter.approve(ctx(), "LTL1")); |
||||||
|
assertTrue(e.getMessage().contains("不允许审核"), e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void nonOutboundTransferTypeIsRejected() { |
||||||
|
TransferCommand cmd = TransferCommand.builder() |
||||||
|
.transferRequestNo("TR-2") |
||||||
|
.type(TransferType.WAREHOUSE_TO_WAREHOUSE) |
||||||
|
.fromWarehouseCode("A").toWarehouseCode("B") |
||||||
|
.estimateOutboundDate(LocalDate.now()).estimateInboundDate(LocalDate.now()) |
||||||
|
.line("SKU", 1) |
||||||
|
.build(); |
||||||
|
|
||||||
|
ValidationException e = assertThrows(ValidationException.class, |
||||||
|
() -> adapter.create(ctx(), cmd)); |
||||||
|
assertTrue(e.getMessage().contains("OUTBOUND"), e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void missingDictionaryFieldsFailBeforeSending() { |
||||||
|
TransferCommand cmd = TransferCommand.builder() |
||||||
|
.transferRequestNo("TR-3") |
||||||
|
.type(TransferType.OUTBOUND) |
||||||
|
.fromWarehouseCode("CA-3790").toWarehouseCode("ONT8") |
||||||
|
.estimateOutboundDate(LocalDate.now()) |
||||||
|
.estimateInboundDate(LocalDate.now().plusDays(1)) |
||||||
|
.shipTo(ShipTo.builder().name("FBA").countryCode("US").stateOrProvince("CA") |
||||||
|
.city("San Bernardino").addressLine1("1 Amazon Way").postalCode("92408").build()) |
||||||
|
.line("SKU", 1) |
||||||
|
.build(); |
||||||
|
|
||||||
|
ValidationException e = assertThrows(ValidationException.class, |
||||||
|
() -> adapter.create(ctx(), cmd)); |
||||||
|
assertTrue(e.getMessage().contains("deliveryMode"), e.getMessage()); |
||||||
|
assertFalse(transport.recorded().stream() |
||||||
|
.anyMatch(r -> r.url().contains(XincangConstants.PATH_TRANSFER_CREATE))); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void missingTransferNoIsNotSilentSuccess() { |
||||||
|
transport.route(XincangConstants.PATH_TRANSFER_CREATE, req -> Responses.ok( |
||||||
|
"{\"rst\":null,\"errno\":0,\"err\":\"\"}")); |
||||||
|
|
||||||
|
common.ecommerce.warehouse.error.WarehouseException e = |
||||||
|
assertThrows(common.ecommerce.warehouse.error.WarehouseException.class, |
||||||
|
() -> adapter.create(ctx(), command())); |
||||||
|
assertTrue(e.getMessage().contains("rst.order_no"), e.getMessage()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void transferCapabilityDeclared() { |
||||||
|
assertTrue(adapter.capabilities().contains(WarehouseCapability.TRANSFER)); |
||||||
|
assertTrue(adapter.supports("XC-CA-3790", WarehouseCapability.TRANSFER)); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue