|
|
|
|
package common.ecommerce.hengjian.adapter;
|
|
|
|
|
|
|
|
|
|
import common.ecommerce.hengjian.HengjianConstants;
|
|
|
|
|
import common.ecommerce.http.JacksonJsonCodec;
|
|
|
|
|
import common.ecommerce.shared.spi.ChannelSecret;
|
|
|
|
|
import common.ecommerce.shared.testkit.RecordingTransport;
|
|
|
|
|
import common.ecommerce.warehouse.enums.WarehouseProvider;
|
|
|
|
|
import common.ecommerce.warehouse.error.WarehouseUnsupportedCapabilityException;
|
|
|
|
|
import common.ecommerce.warehouse.model.OutboundRef;
|
|
|
|
|
import common.ecommerce.warehouse.sdk.WarehouseConnection;
|
|
|
|
|
import common.ecommerce.warehouse.sdk.WarehouseSdk;
|
|
|
|
|
import common.ecommerce.warehouse.spi.WarehouseAccount;
|
|
|
|
|
import common.ecommerce.warehouse.testkit.InMemoryWarehouses;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import java.time.Clock;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 恒健适配器门面契约:注册后能按 provider 解析,未实现的能力显式拒绝。
|
|
|
|
|
*/
|
|
|
|
|
class HengjianAdapterTest {
|
|
|
|
|
|
|
|
|
|
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-12T00:00:00Z"), ZoneOffset.UTC);
|
|
|
|
|
private static final String WH = "HJ-EFCA";
|
|
|
|
|
|
|
|
|
|
private static WarehouseAccount account() {
|
|
|
|
|
return WarehouseAccount.builder()
|
|
|
|
|
.warehouseCode(WH)
|
|
|
|
|
.provider(WarehouseProvider.HENGJIAN.name())
|
|
|
|
|
.providerWarehouseId("EFCA")
|
|
|
|
|
.credentialRef("kms://test/hengjian")
|
|
|
|
|
.timeZone("America/Los_Angeles")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static WarehouseSdk sdk() {
|
|
|
|
|
return WarehouseSdk.builder()
|
|
|
|
|
.warehouseRepository(new InMemoryWarehouses().put(account()))
|
|
|
|
|
.clock(CLOCK)
|
|
|
|
|
.register(new HengjianAdapterFactory())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static WarehouseConnection conn() {
|
|
|
|
|
return WarehouseConnection.of(HengjianConstants.TEST_BASE_URL,
|
|
|
|
|
ChannelSecret.builder().appSecret("token-1").build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void registersAndResolves() {
|
|
|
|
|
WarehouseSdk sdk = sdk();
|
|
|
|
|
|
|
|
|
|
assertTrue(sdk.capabilities(WH).supports(
|
|
|
|
|
common.ecommerce.warehouse.enums.WarehouseCapability.DIRECTORY));
|
|
|
|
|
assertTrue(sdk.capabilities(WH).supports(
|
|
|
|
|
common.ecommerce.warehouse.enums.WarehouseCapability.LOGISTICS_PRODUCT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下单 / 查询 / 包裹已接、取消未接:门面能力检查放行 {@code OUTBOUND},
|
|
|
|
|
* 适配器对未实现的 {@code cancel} 显式抛异常,不返回 null。
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
void unimplementedCancelIsRejected() {
|
|
|
|
|
WarehouseSdk sdk = sdk();
|
|
|
|
|
|
|
|
|
|
assertThrows(common.ecommerce.warehouse.error.WarehouseException.class,
|
|
|
|
|
() -> sdk.warehouses(WH, conn()).outbound().cancel(
|
|
|
|
|
common.ecommerce.warehouse.model.CancelCommand.builder()
|
|
|
|
|
.outboundRequestNo("OB-1").build()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 库存 / 入库 / 退货仍未接入:门面按能力位直接拒绝。 */
|
|
|
|
|
@Test
|
|
|
|
|
void undeclaredCapabilityIsRejected() {
|
|
|
|
|
WarehouseSdk sdk = sdk();
|
|
|
|
|
|
|
|
|
|
assertThrows(WarehouseUnsupportedCapabilityException.class,
|
|
|
|
|
() -> sdk.warehouses(WH, conn()).inventory().query(null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 能力矩阵查询本身可用(不触发真实 API)。 */
|
|
|
|
|
@Test
|
|
|
|
|
void capabilityQueryIsOffline() {
|
|
|
|
|
HengjianAdapter adapter = new HengjianAdapter(RecordingTransport.create(), new JacksonJsonCodec());
|
|
|
|
|
|
|
|
|
|
assertTrue(!adapter.capabilities().contains(
|
|
|
|
|
common.ecommerce.warehouse.enums.WarehouseCapability.INVENTORY_QUERY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void providerEnumIsRegistered() {
|
|
|
|
|
assertEquals("恒健", WarehouseProvider.HENGJIAN.label());
|
|
|
|
|
assertEquals(50, WarehouseProvider.HENGJIAN.code());
|
|
|
|
|
}
|
|
|
|
|
}
|