Browse Source

test(lingxing): 冒烟测试改为直接填常量,不再读环境变量

占位常量未填时用 Assumptions 跳过,不会拿占位串去打真实接口。

Co-Authored-By: Claude <noreply@anthropic.com>
feature/supplier-lingxing
chenchuchuan 3 weeks ago
parent
commit
71389aae5d
  1. 44
      lingxing/src/test/java/common/ecommerce/lingxing/LingxingLiveSmokeTest.java

44
lingxing/src/test/java/common/ecommerce/lingxing/LingxingLiveSmokeTest.java

@ -19,7 +19,6 @@ import common.ecommerce.spi.ChannelSecret; @@ -19,7 +19,6 @@ import common.ecommerce.spi.ChannelSecret;
import common.ecommerce.testkit.InMemoryLockProvider;
import common.ecommerce.testkit.InMemoryTokenStore;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import java.time.Clock;
import java.time.Duration;
@ -31,38 +30,41 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,38 +30,41 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* 领星真实环境冒烟测试。未配置凭证时整类跳过。
* 领星真实环境冒烟测试。
*
* <p><b>跑之前把下面三个常量填上,然后 IDE 里右键 Run 或执行:</b></p>
* <pre>
* export LINGXING_APP_KEY=xxx
* export LINGXING_APP_SECRET=xxx
* export LINGXING_STORE_ID=1108413237731
* export LINGXING_PLATFORM_CODE=10008 # 可选,默认 Walmart
* export LINGXING_BASE_URL=https://openapi.lingxing.com # 可选
* mvn -pl lingxing -am test -Dtest=LingxingLiveSmokeTest
* </pre>
*
* <p>调用前确认出口 IP 已加入领星白名单,否则会直接 401/403。</p>
*
* <p>本类只用于联调,不要把真实凭证提交到仓库。</p>
*/
@EnabledIfEnvironmentVariable(named = "LINGXING_APP_KEY", matches = ".+")
class LingxingLiveSmokeTest {
private static final String APP_KEY = System.getenv("LINGXING_APP_KEY");
private static final String APP_SECRET = System.getenv("LINGXING_APP_SECRET");
private static final String STORE_ID = System.getenv().getOrDefault("LINGXING_STORE_ID", "");
private static final int PLATFORM_CODE = Integer.parseInt(
System.getenv().getOrDefault("LINGXING_PLATFORM_CODE", "10008"));
private static final String BASE_URL = System.getenv().getOrDefault(
"LINGXING_BASE_URL", LingxingConstants.PRODUCTION_BASE_URL);
// ==================== 填写这里 ====================
/** 领星 ERP 开放接口的 AppID。 */
private static final String APP_KEY = "在这里填 AppID";
/** 领星 ERP 开放接口的 AppSecret。 */
private static final String APP_SECRET = "在这里填 AppSecret";
/** 领星后台的 store_id。 */
private static final String STORE_ID = "在这里填 store_id";
// ================================================
/** 10008 = Walmart;TikTok 10011、eBay 10003、Amazon 10001,按需改。 */
private static final int PLATFORM_CODE = 10008;
private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL;
private final JacksonJsonCodec json = new JacksonJsonCodec();
private final LoggingTransport transport = new LoggingTransport(new OkHttpTransport("common-ecommerce-smoke"));
private final InMemoryTokenStore tokenStore = new InMemoryTokenStore();
private final InMemoryLockProvider locks = new InMemoryLockProvider();
/** 第 1 步:只验证认证。失败说明 appId/appSecret 字段名或环境不对,与订单接口无关。 */
/** 第 1 步:只验证认证。失败说明 AppID/AppSecret 不对,或 IP 不在白名单。 */
@Test
void tokenCanBeFetched() {
requireConfigured();
AccessToken token = new LingxingTokenClient(transport, json, Clock.systemUTC())
.fetch(BASE_URL, APP_KEY, APP_SECRET);
System.out.println("[token] " + token.fingerprint() + " expiresAt=" + token.expiresAt());
@ -72,6 +74,7 @@ class LingxingLiveSmokeTest { @@ -72,6 +74,7 @@ class LingxingLiveSmokeTest {
/** 第 2 步:拉一页订单,打印请求与解析结果,人工核对字段映射。 */
@Test
void pullsOnePageOfOrders() {
requireConfigured();
LingxingAdapter adapter = adapter();
ChannelContext ctx = ChannelContext.of(account(), connection(),
"smoke-" + System.currentTimeMillis(), Clock.systemUTC());
@ -100,6 +103,15 @@ class LingxingLiveSmokeTest { @@ -100,6 +103,15 @@ class LingxingLiveSmokeTest {
// ---------------------------------------------------------------- helpers
/** 常量没填时跳过,避免占位字符串去打真实接口;填上后自动执行。 */
private static void requireConfigured() {
org.junit.jupiter.api.Assumptions.assumeTrue(
!APP_KEY.startsWith("在这里填")
&& !APP_SECRET.startsWith("在这里填")
&& !STORE_ID.startsWith("在这里填"),
"请先填写 LingxingLiveSmokeTest 顶部的 APP_KEY / APP_SECRET / STORE_ID");
}
private LingxingAdapter adapter() {
return new LingxingAdapter(transport, json, tokenStore, locks, Clock.systemUTC());
}

Loading…
Cancel
Save