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.
105 lines
5.0 KiB
105 lines
5.0 KiB
|
6 days ago
|
package common.ecommerce.edayun.probe;
|
||
|
|
|
||
|
|
import common.ecommerce.edayun.EdayunConstants;
|
||
|
|
import common.ecommerce.edayun.adapter.EdayunAdapter;
|
||
|
6 days ago
|
import common.ecommerce.edayun.adapter.EdayunCaseMarkMapper;
|
||
|
|
import common.ecommerce.edayun.dto.EdayunCaseMarkDtos;
|
||
|
6 days ago
|
import common.ecommerce.http.JacksonJsonCodec;
|
||
|
|
import common.ecommerce.http.OkHttpTransport;
|
||
|
|
import common.ecommerce.shared.error.ChannelException;
|
||
|
|
import common.ecommerce.shared.spi.ChannelSecret;
|
||
|
6 days ago
|
import common.ecommerce.warehouse.enums.CaseMarkPaperSize;
|
||
|
6 days ago
|
import common.ecommerce.warehouse.enums.WarehouseProvider;
|
||
|
6 days ago
|
import common.ecommerce.warehouse.model.CaseMarkPrintCommand;
|
||
|
6 days ago
|
import common.ecommerce.warehouse.model.WarehouseLabel;
|
||
|
|
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.UUID;
|
||
|
|
|
||
|
|
/**
|
||
|
6 days ago
|
* 箱唛打印联调探针:<b>只读</b>(生成 PDF,不改仓侧业务数据)。
|
||
|
6 days ago
|
*
|
||
|
|
* <pre>
|
||
|
|
* # 只看报文(不联网)
|
||
|
|
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \
|
||
|
|
* -Dedayun.probe.barcode=true -Dtest=EdayunBarcodeProbeTest test
|
||
|
|
*
|
||
|
|
* # 真跑
|
||
|
|
* ... -Dedayun.probe.barcode=true -Dedayun.probe.call=true \
|
||
|
|
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \
|
||
|
|
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \
|
||
|
|
* [-Dedayun.probe.sku=ybtest]
|
||
|
|
* </pre>
|
||
|
|
*/
|
||
|
|
@EnabledIfSystemProperty(named = "edayun.probe.barcode", matches = "true")
|
||
|
6 days ago
|
class EdayunCaseMarkProbeTest {
|
||
|
6 days ago
|
|
||
|
|
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL);
|
||
|
|
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", "");
|
||
|
|
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", "");
|
||
|
|
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", "");
|
||
|
|
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", "");
|
||
|
|
private static final String SKU = opt("edayun.probe.sku", "ybtest");
|
||
|
|
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call");
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void probePrintBarcode() {
|
||
|
6 days ago
|
CaseMarkPrintCommand cmd = CaseMarkPrintCommand.builder()
|
||
|
|
.paperSize(CaseMarkPaperSize.SIZE_60_40)
|
||
|
6 days ago
|
.remark("PROBE")
|
||
|
|
.printSkuName(true)
|
||
|
|
.item(SKU, 1)
|
||
|
|
.build();
|
||
|
|
|
||
|
6 days ago
|
EdayunCaseMarkDtos.PrintCaseMarkRequest req = EdayunCaseMarkMapper.toRequest(cmd);
|
||
|
6 days ago
|
String bodyJson = new JacksonJsonCodec().toJson(req);
|
||
|
|
|
||
|
|
System.out.println("\n================ edayun / POST "
|
||
|
6 days ago
|
+ EdayunConstants.PATH_CASE_MARK_PRINT + " ================");
|
||
|
6 days ago
|
System.out.println("[probe] baseUrl=" + BASE_URL + " sku=" + SKU);
|
||
|
|
System.out.println("[request] " + bodyJson);
|
||
|
|
|
||
|
|
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用");
|
||
|
|
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty()
|
||
|
|
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(),
|
||
|
|
"真跑需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret");
|
||
|
|
|
||
|
|
try {
|
||
|
|
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, null,
|
||
|
|
WarehouseConnection.of(BASE_URL,
|
||
|
|
ChannelSecret.builder()
|
||
|
|
.appKey(APP_KEY).appSecret(APP_SECRET)
|
||
|
|
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET)
|
||
|
|
.build()),
|
||
|
|
"probe-" + UUID.randomUUID(), Clock.systemUTC());
|
||
|
|
EdayunAdapter adapter = new EdayunAdapter(
|
||
|
|
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000),
|
||
|
|
new JacksonJsonCodec());
|
||
|
|
|
||
|
6 days ago
|
WarehouseLabel label = adapter.printCaseMarks(ctx, cmd);
|
||
|
6 days ago
|
System.out.println("[OK] labelId=" + label.labelId() + " format=" + label.format()
|
||
|
|
+ " url=" + label.url());
|
||
|
|
} catch (RuntimeException e) {
|
||
|
|
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
|
||
|
|
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": "
|
||
|
|
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…"));
|
||
|
|
if (e instanceof ChannelException) {
|
||
|
|
ChannelException ce = (ChannelException) e;
|
||
|
|
System.out.println(" platformCode=" + ce.platformCode()
|
||
|
|
+ " retryable=" + ce.retryable());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private static String opt(String name, String fallback) {
|
||
|
|
String value = System.getProperty(name, "");
|
||
|
|
String trimmed = value == null ? "" : value.trim();
|
||
|
|
return trimmed.isEmpty() ? fallback : trimmed;
|
||
|
|
}
|
||
|
|
}
|