错误处理

This commit is contained in:
lu7213 committed 2026-11-06 21:32:26 -05:00
1 parent cf68147d08
commit 7202f0783a
3 files changed
+68 -9

No files matched your search

@@ -0,0 +1,41 @@
package com.ruoyi.system.chain;
import org.junit.Test;
import java.lang.reflect.Field;
import static org.junit.Assert.fail;
/** 启动联通失败只降低远程执行能力,配置格式错误仍须阻止启动。 */
public class ChainExecutorClientTest {
@Test
public void unavailableExecutorDoesNotPreventPaymentSystemStartup() throws Exception {
ChainExecutorClient client = client("http://127.0.0.1:1");
client.validate();
}
@Test
public void invalidExecutorUrlStillPreventsStartup() throws Exception {
ChainExecutorClient client = client("http://example.com:9088");
try {
client.validate();
fail("域名地址应在发起请求前被拒绝");
} catch (IllegalArgumentException expected) {
// 只允许内网字面IP,避免DNS重绑定或误连公网。
}
}
private ChainExecutorClient client(String url) throws Exception {
ChainExecutorClient client = new ChainExecutorClient();
set(client, "enabled", true);
set(client, "url", url);
set(client, "token", "test-only-token-012345678901234567890");
return client;
}
private void set(Object target, String name, Object value) throws Exception {
Field field = target.getClass().getDeclaredField(name);
field.setAccessible(true);
field.set(target, value);
}
}