You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
6.5 KiB
156 lines
6.5 KiB
|
2 weeks ago
|
package common.ecommerce.yqn.adapter;
|
||
|
|
|
||
|
|
import common.ecommerce.http.JacksonJsonCodec;
|
||
|
|
import common.ecommerce.shared.spi.ChannelSecret;
|
||
|
|
import common.ecommerce.shared.testkit.RecordingTransport;
|
||
|
|
import common.ecommerce.shared.testkit.Responses;
|
||
|
|
import common.ecommerce.warehouse.enums.LabelDownloadMode;
|
||
|
|
import common.ecommerce.warehouse.enums.LabelSizeType;
|
||
|
|
import common.ecommerce.warehouse.enums.LabelsPerPage;
|
||
|
|
import common.ecommerce.warehouse.enums.WarehouseCapability;
|
||
|
|
import common.ecommerce.warehouse.enums.WarehouseProvider;
|
||
|
|
import common.ecommerce.warehouse.model.BoxLabelCommand;
|
||
|
|
import common.ecommerce.warehouse.model.LabelPrintTask;
|
||
|
|
import common.ecommerce.warehouse.sdk.WarehouseConnection;
|
||
|
|
import common.ecommerce.warehouse.sdk.WarehouseContext;
|
||
|
|
import common.ecommerce.yqn.YqnConstants;
|
||
|
|
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.assertNull;
|
||
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 打印入库计划单箱标(API 99)契约测试。
|
||
|
|
*/
|
||
|
|
class YqnBoxLabelTest {
|
||
|
|
|
||
|
|
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-10T00:00:00Z"), ZoneOffset.UTC);
|
||
|
|
|
||
|
|
private static WarehouseContext ctx() {
|
||
|
|
return WarehouseContext.of("YQN-RF_NY_US", WarehouseProvider.YQN, "RF_NY_US",
|
||
|
|
WarehouseConnection.of(YqnConstants.PR_BASE_URL,
|
||
|
|
ChannelSecret.builder().appSecret("key-1").build()),
|
||
|
|
"req-label", CLOCK);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static BoxLabelCommand command() {
|
||
|
|
return BoxLabelCommand.builder()
|
||
|
|
.providerInboundNo("IP20261110001")
|
||
|
|
.inboundRequestNo("OMS-IN-001")
|
||
|
|
.downloadMode(LabelDownloadMode.PDF)
|
||
|
|
.sizeType(LabelSizeType.SIZE_100_100)
|
||
|
|
.labelsPerPage(LabelsPerPage.ONE)
|
||
|
|
.twoCopies(true)
|
||
|
|
.showOrgUniqueCode(true)
|
||
|
|
.build();
|
||
|
|
}
|
||
|
|
|
||
|
|
private static String okBody() {
|
||
|
|
return "{\"statusCode\":200,\"status\":0,\"code\":200,\"message\":\"ok\","
|
||
|
|
+ "\"data\":{\"taskNo\":\"TASK-1\",\"orderNo\":\"IP20261110001\","
|
||
|
|
+ "\"sourceNo\":\"OMS-IN-001\"}}";
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void sendsDocumentedShape() {
|
||
|
|
RecordingTransport transport = RecordingTransport.create()
|
||
|
|
.route(YqnConstants.PATH_INBOUND_BOX_LABEL, req -> Responses.ok(okBody()));
|
||
|
|
YqnAdapter adapter = new YqnAdapter(transport, new JacksonJsonCodec());
|
||
|
|
|
||
|
|
LabelPrintTask task = adapter.printBoxLabel(ctx(), command());
|
||
|
|
|
||
|
|
String body = transport.lastDataRequest().body();
|
||
|
|
assertTrue(body.contains("\"orderNo\":\"IP20261110001\""), body);
|
||
|
|
assertTrue(body.contains("\"sourceNo\":\"OMS-IN-001\""), body);
|
||
|
|
assertTrue(body.contains("\"downloadMode\":2"), body);
|
||
|
|
assertTrue(body.contains("\"labelSizeType\":1"), body);
|
||
|
|
assertTrue(body.contains("\"numPerPage\":1"), body);
|
||
|
|
assertTrue(body.contains("\"twoCopies\":true"), body);
|
||
|
|
assertTrue(body.contains("\"showOrgUniqueCode\":true"), body);
|
||
|
|
|
||
|
|
assertEquals("TASK-1", task.taskNo());
|
||
|
|
assertEquals("IP20261110001", task.providerInboundNo());
|
||
|
|
assertEquals("OMS-IN-001", task.inboundRequestNo());
|
||
|
|
assertEquals(WarehouseProvider.YQN, task.sourceProvider());
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 异步接口只回任务编号,不返回文件。 */
|
||
|
|
@Test
|
||
|
|
void taskCarriesNoLabelFile() {
|
||
|
|
RecordingTransport transport = RecordingTransport.create()
|
||
|
|
.route(YqnConstants.PATH_INBOUND_BOX_LABEL, req -> Responses.ok(okBody()));
|
||
|
|
|
||
|
|
LabelPrintTask task = new YqnAdapter(transport, new JacksonJsonCodec())
|
||
|
|
.printBoxLabel(ctx(), command());
|
||
|
|
|
||
|
|
assertNull(task.label());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void sixPerPageUsesUsLetterSize() {
|
||
|
|
BoxLabelCommand sixPerPage = BoxLabelCommand.builder()
|
||
|
|
.providerInboundNo("IP1")
|
||
|
|
.inboundRequestNo("OMS-1")
|
||
|
|
.sizeType(LabelSizeType.SIZE_104_98)
|
||
|
|
.labelsPerPage(LabelsPerPage.SIX)
|
||
|
|
.build();
|
||
|
|
RecordingTransport transport = RecordingTransport.create()
|
||
|
|
.route(YqnConstants.PATH_INBOUND_BOX_LABEL, req -> Responses.ok(okBody()));
|
||
|
|
new YqnAdapter(transport, new JacksonJsonCodec()).printBoxLabel(ctx(), sixPerPage);
|
||
|
|
|
||
|
|
String body = transport.lastDataRequest().body();
|
||
|
|
assertTrue(body.contains("\"labelSizeType\":3"), body);
|
||
|
|
assertTrue(body.contains("\"numPerPage\":6"), body);
|
||
|
|
// 默认值:PDF + 不两份 + 不展示客户码
|
||
|
|
assertTrue(body.contains("\"downloadMode\":2"), body);
|
||
|
|
assertTrue(body.contains("\"twoCopies\":false"), body);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 尺寸与每页数量不匹配,构造期就失败,不等仓方拒绝。 */
|
||
|
|
@Test
|
||
|
|
void incompatibleSizeAndPerPageRejected() {
|
||
|
|
assertThrows(IllegalArgumentException.class, () -> BoxLabelCommand.builder()
|
||
|
|
.providerInboundNo("IP1").inboundRequestNo("OMS-1")
|
||
|
|
.sizeType(LabelSizeType.SIZE_104_98)
|
||
|
|
.labelsPerPage(LabelsPerPage.ONE)
|
||
|
|
.build());
|
||
|
|
|
||
|
|
assertThrows(IllegalArgumentException.class, () -> BoxLabelCommand.builder()
|
||
|
|
.providerInboundNo("IP1").inboundRequestNo("OMS-1")
|
||
|
|
.sizeType(LabelSizeType.SIZE_100_100)
|
||
|
|
.labelsPerPage(LabelsPerPage.SIX)
|
||
|
|
.build());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void archiveModeMapsToOne() {
|
||
|
|
assertEquals(Integer.valueOf(1),
|
||
|
|
YqnBoxLabelMapper.downloadModeCode(LabelDownloadMode.ARCHIVE));
|
||
|
|
assertEquals(Integer.valueOf(2),
|
||
|
|
YqnBoxLabelMapper.downloadModeCode(LabelDownloadMode.PDF));
|
||
|
|
assertEquals(Integer.valueOf(2),
|
||
|
|
YqnBoxLabelMapper.sizeTypeCode(LabelSizeType.SIZE_100_150));
|
||
|
|
assertNull(YqnBoxLabelMapper.sizeTypeCode(null));
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void declaresBoxLabelCapability() {
|
||
|
|
YqnAdapter adapter = new YqnAdapter(RecordingTransport.create(), new JacksonJsonCodec());
|
||
|
|
assertTrue(adapter.capabilities().contains(WarehouseCapability.BOX_LABEL));
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void blankNumbersRejected() {
|
||
|
|
assertThrows(IllegalArgumentException.class, () -> BoxLabelCommand.builder()
|
||
|
|
.inboundRequestNo("OMS-1").build());
|
||
|
|
assertThrows(IllegalArgumentException.class, () -> BoxLabelCommand.builder()
|
||
|
|
.providerInboundNo("IP1").build());
|
||
|
|
}
|
||
|
|
}
|