|
|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
package common.ecommerce.lingxing.platform.amazon; |
|
|
|
|
|
|
|
|
|
import common.ecommerce.capability.AggregatorCapable.SubChannel; |
|
|
|
|
import common.ecommerce.http.HttpRequest; |
|
|
|
|
import common.ecommerce.http.HttpResponse; |
|
|
|
|
import common.ecommerce.http.HttpTransport; |
|
|
|
|
@ -24,21 +25,22 @@ import org.junit.jupiter.api.Test;
@@ -24,21 +25,22 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
import java.time.Clock; |
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.time.Instant; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse; |
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 领星 · 亚马逊 SC 商品接口真实环境测试。 |
|
|
|
|
* 领星 · 亚马逊 SC 真实环境测试:先查店铺列表拿 sid,再用 sid 拉 Listing。 |
|
|
|
|
* |
|
|
|
|
* <p><b>跑之前把下面三个常量填上,然后 IDE 里右键 Run 或执行:</b></p> |
|
|
|
|
* <p><b>跑之前填 APP_KEY / APP_SECRET 即可</b>;SID 留空时会自动从店铺列表取第一个。</p> |
|
|
|
|
* <pre> |
|
|
|
|
* mvn -pl lingxing -am test -Dtest=AmazonScProductLiveTest |
|
|
|
|
* </pre> |
|
|
|
|
* |
|
|
|
|
* <p>调用前确认出口 IP 已加入领星白名单。本类只用于联调,不要把真实凭证提交到仓库。</p> |
|
|
|
|
* |
|
|
|
|
* <p>亚马逊 Listing 接口令牌桶容量为 1,且按「账户 + path」共享,必须串行调用。</p> |
|
|
|
|
* <p>两个接口的令牌桶容量都是 1,且按「账户 + path」共享,必须串行调用。</p> |
|
|
|
|
*/ |
|
|
|
|
class AmazonScProductLiveTest { |
|
|
|
|
|
|
|
|
|
@ -47,8 +49,11 @@ class AmazonScProductLiveTest {
@@ -47,8 +49,11 @@ class AmazonScProductLiveTest {
|
|
|
|
|
private static final String APP_KEY = "在这里填 AppID"; |
|
|
|
|
/** 领星 ERP 开放接口的 AppSecret。 */ |
|
|
|
|
private static final String APP_SECRET = "在这里填 AppSecret"; |
|
|
|
|
/** 亚马逊店铺的领星 sid(来自店铺列表接口的 sid 字段)。 */ |
|
|
|
|
private static final String SID = "在这里填 sid"; |
|
|
|
|
/** |
|
|
|
|
* 亚马逊店铺的领星 sid。 |
|
|
|
|
* 留空则自动调用店铺列表接口,取第一个正常状态的店铺。 |
|
|
|
|
*/ |
|
|
|
|
private static final String SID = ""; |
|
|
|
|
// ================================================
|
|
|
|
|
|
|
|
|
|
private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL; |
|
|
|
|
@ -57,21 +62,42 @@ class AmazonScProductLiveTest {
@@ -57,21 +62,42 @@ class AmazonScProductLiveTest {
|
|
|
|
|
private final LoggingTransport transport = |
|
|
|
|
new LoggingTransport(new OkHttpTransport("common-ecommerce-smoke")); |
|
|
|
|
|
|
|
|
|
/** 拉一页亚马逊 Listing,打印请求与解析结果,人工核对字段映射。 */ |
|
|
|
|
/** |
|
|
|
|
* 店铺列表:一次性返回企业已授权到领星的全部亚马逊 SC 店铺。 |
|
|
|
|
* |
|
|
|
|
* <p>接口 {@code GET /erp/sc/data/seller/lists},非分页。打印每个店铺的 sid 与名称, |
|
|
|
|
* 同时打印请求与响应原始报文(见 LoggingTransport),便于核对字段名。</p> |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
void listsAmazonShops() { |
|
|
|
|
requireConfigured(); |
|
|
|
|
|
|
|
|
|
List<SubChannel> channels = adapter().listSubChannels(shopListContext()); |
|
|
|
|
System.out.println("[shops] subChannels size=" + channels.size()); |
|
|
|
|
for (SubChannel c : channels) { |
|
|
|
|
System.out.println(" platformCode=" + c.platformCode() |
|
|
|
|
+ " sid=" + c.externalStoreId() |
|
|
|
|
+ " platform=" + c.platform() |
|
|
|
|
+ " name=" + c.name()); |
|
|
|
|
} |
|
|
|
|
assertNotNull(channels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 拿第一个正常店铺的 sid,调 Listing 接口。 */ |
|
|
|
|
@Test |
|
|
|
|
void pullsOnePageOfListings() { |
|
|
|
|
requireConfigured(); |
|
|
|
|
|
|
|
|
|
ChannelContext ctx = ChannelContext.of(amazonAccount(), connection(), |
|
|
|
|
"smoke-" + System.currentTimeMillis(), Clock.systemUTC()); |
|
|
|
|
String sid = resolveSid(); |
|
|
|
|
System.out.println("[listings] 使用 sid=" + sid); |
|
|
|
|
|
|
|
|
|
LingxingAdapter adapter = new LingxingAdapter(transport, json, |
|
|
|
|
new InMemoryTokenStore(), new InMemoryLockProvider(), Clock.systemUTC()); |
|
|
|
|
ChannelContext ctx = ChannelContext.of(amazonAccount(sid), connection(), |
|
|
|
|
"smoke-" + System.currentTimeMillis(), Clock.systemUTC()); |
|
|
|
|
|
|
|
|
|
Instant to = Instant.now(); |
|
|
|
|
Instant from = to.minus(Duration.ofDays(7)); |
|
|
|
|
|
|
|
|
|
Page<ProductListing> page = adapter.pull(ctx, ProductQuery.builder() |
|
|
|
|
Page<ProductListing> page = adapter().pull(ctx, ProductQuery.builder() |
|
|
|
|
.updatedAfter(from) |
|
|
|
|
.updatedBefore(to) |
|
|
|
|
.pageSize(20) |
|
|
|
|
@ -94,20 +120,18 @@ class AmazonScProductLiveTest {
@@ -94,20 +120,18 @@ class AmazonScProductLiveTest {
|
|
|
|
|
void pullsFirstPageWithoutTimeWindow() { |
|
|
|
|
requireConfigured(); |
|
|
|
|
|
|
|
|
|
ChannelContext ctx = ChannelContext.of(amazonAccount(), connection(), |
|
|
|
|
String sid = resolveSid(); |
|
|
|
|
ChannelContext ctx = ChannelContext.of(amazonAccount(sid), connection(), |
|
|
|
|
"smoke-" + System.currentTimeMillis(), Clock.systemUTC()); |
|
|
|
|
|
|
|
|
|
LingxingAdapter adapter = new LingxingAdapter(transport, json, |
|
|
|
|
new InMemoryTokenStore(), new InMemoryLockProvider(), Clock.systemUTC()); |
|
|
|
|
|
|
|
|
|
Page<ProductListing> page = adapter.pull(ctx, ProductQuery.builder().pageSize(10).build()); |
|
|
|
|
Page<ProductListing> page = adapter().pull(ctx, ProductQuery.builder().pageSize(10).build()); |
|
|
|
|
|
|
|
|
|
System.out.println("[listings/no-window] items=" + page.size() |
|
|
|
|
System.out.println("[listings/no-window] sid=" + sid + " items=" + page.size() |
|
|
|
|
+ " nextCursor=" + page.nextCursor()); |
|
|
|
|
for (ProductListing p : page.items()) { |
|
|
|
|
System.out.println(" sku=" + p.platformSku() + " status=" + p.status()); |
|
|
|
|
} |
|
|
|
|
// Listing 接口可能返回空列表(店铺没有商品),这里只验证调用与解析没抛异常
|
|
|
|
|
// 店铺可能没有商品,空列表也算通过
|
|
|
|
|
assertNotNull(page); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -115,10 +139,25 @@ class AmazonScProductLiveTest {
@@ -115,10 +139,25 @@ class AmazonScProductLiveTest {
|
|
|
|
|
|
|
|
|
|
private static void requireConfigured() { |
|
|
|
|
org.junit.jupiter.api.Assumptions.assumeTrue( |
|
|
|
|
!APP_KEY.startsWith("在这里填") |
|
|
|
|
&& !APP_SECRET.startsWith("在这里填") |
|
|
|
|
&& !SID.startsWith("在这里填"), |
|
|
|
|
"请先填写 AmazonScProductLiveTest 顶部的 APP_KEY / APP_SECRET / SID"); |
|
|
|
|
!APP_KEY.startsWith("在这里填") && !APP_SECRET.startsWith("在这里填"), |
|
|
|
|
"请先填写 AmazonScProductLiveTest 顶部的 APP_KEY / APP_SECRET"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 优先用常量里的 SID;留空则从店铺列表取第一个。 */ |
|
|
|
|
private String resolveSid() { |
|
|
|
|
if (SID != null && !SID.trim().isEmpty() && !SID.startsWith("在这里填")) { |
|
|
|
|
return SID.trim(); |
|
|
|
|
} |
|
|
|
|
List<SubChannel> channels = adapter().listSubChannels(shopListContext()); |
|
|
|
|
if (channels.isEmpty()) { |
|
|
|
|
throw new AssertionError("店铺列表为空:该企业没有已授权且状态正常的亚马逊 SC 店铺"); |
|
|
|
|
} |
|
|
|
|
return channels.get(0).externalStoreId(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private LingxingAdapter adapter() { |
|
|
|
|
return new LingxingAdapter(transport, json, |
|
|
|
|
new InMemoryTokenStore(), new InMemoryLockProvider(), Clock.systemUTC()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelConnection connection() { |
|
|
|
|
@ -126,10 +165,27 @@ class AmazonScProductLiveTest {
@@ -126,10 +165,27 @@ class AmazonScProductLiveTest {
|
|
|
|
|
.appKey(APP_KEY).appSecret(APP_SECRET).build()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelAccount amazonAccount() { |
|
|
|
|
/** 店铺列表所用的上下文:店铺维度此时还不存在,用占位 omsStoreId。 */ |
|
|
|
|
private ChannelContext shopListContext() { |
|
|
|
|
return ChannelContext.of(placeholderAccount(), connection(), |
|
|
|
|
"smoke-shops-" + System.currentTimeMillis(), Clock.systemUTC()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelAccount placeholderAccount() { |
|
|
|
|
return ChannelAccount.builder() |
|
|
|
|
.key(AccountKey.of(ChannelProvider.LINGXING, Platform.AMAZON_SC, "oms-amz-discovery")) |
|
|
|
|
.externalStoreId("discovery") |
|
|
|
|
.platformCode(10001) |
|
|
|
|
.credentialRef("smoke") |
|
|
|
|
.marketplaceZone("America/Los_Angeles") |
|
|
|
|
.currency("USD") |
|
|
|
|
.build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ChannelAccount amazonAccount(String sid) { |
|
|
|
|
return ChannelAccount.builder() |
|
|
|
|
.key(AccountKey.of(ChannelProvider.LINGXING, Platform.AMAZON_SC, "oms-amz-smoke")) |
|
|
|
|
.externalStoreId(SID) |
|
|
|
|
.externalStoreId(sid) |
|
|
|
|
.platformCode(10001) |
|
|
|
|
.credentialRef("smoke") |
|
|
|
|
.marketplaceZone("America/Los_Angeles") |
|
|
|
|
|