|
|
@@ -1,10 +1,14 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
/**
|
|
|
@@ -45,4 +49,25 @@ public class TencentTtsServiceAuthorizationTest {
|
|
|
assertTrue(auth.contains("Credential=AKIDtest/2026-10-22/tts/tc3_request"),
|
|
|
"Credential 应含 UTC 日期 2026-10-22,实际: " + auth);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 腾讯云 API 3.0 的错误嵌套在 Response.Error(实测 PkgExhausted 响应),
|
|
|
+ * 顶层 getJSONObject("Error") 永远返回 null,会掩盖真实错误。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void extractError_readsNestedResponseError() {
|
|
|
+ JSONObject resp = JSON.parseObject("{\"Response\":{\"RequestId\":\"r1\","
|
|
|
+ + "\"Error\":{\"Code\":\"UnsupportedOperation.PkgExhausted\","
|
|
|
+ + "\"Message\":\"The resource pack allowance has been exhausted, please check your resource pack.\"}}}");
|
|
|
+ JSONObject error = service.extractError(resp);
|
|
|
+ assertNotNull(error, "应从 Response.Error 提取错误,不得返回 null");
|
|
|
+ assertEquals("UnsupportedOperation.PkgExhausted", error.getString("Code"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 合成成功(无 Error 字段)→ extractError 返回 null,不误报 */
|
|
|
+ @Test
|
|
|
+ public void extractError_nullWhenNoError() {
|
|
|
+ JSONObject resp = JSON.parseObject("{\"Response\":{\"Audio\":\"aGVsbG8=\",\"RequestId\":\"r2\"}}");
|
|
|
+ assertNull(service.extractError(resp));
|
|
|
+ }
|
|
|
}
|