调整 音频合成, 头衔监测
This commit is contained in:
141
src/test/java/com/rj/service/TtsRequestLogShortUrlTest.java
Normal file
141
src/test/java/com/rj/service/TtsRequestLogShortUrlTest.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.rj.entity.TtsRequestLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* TTS请求日志短链接设置测试
|
||||
*
|
||||
* @author rj
|
||||
* @date 2025-01-02
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
public class TtsRequestLogShortUrlTest {
|
||||
|
||||
@Autowired
|
||||
private ITtsRequestLogService ttsRequestLogService;
|
||||
|
||||
/**
|
||||
* 测试根据音频名称设置短链接(默认15分钟)
|
||||
*/
|
||||
@Test
|
||||
public void testSetShortUrlByAudioNameDefault() {
|
||||
try {
|
||||
String audioName = "test_audio_20250102_150000_12345.mp3";
|
||||
|
||||
log.info("开始测试根据音频名称设置短链接(默认15分钟)...");
|
||||
log.info("音频名称: {}", audioName);
|
||||
|
||||
// 先创建一个测试日志记录
|
||||
TtsRequestLog requestLog = createTestRequestLog(audioName);
|
||||
boolean saveResult = ttsRequestLogService.saveTtsRequestLog(requestLog);
|
||||
|
||||
if (saveResult) {
|
||||
log.info("测试日志记录保存成功,ID: {}", requestLog.getId());
|
||||
|
||||
// 测试设置短链接
|
||||
boolean result = ttsRequestLogService.setShortUrlByAudioName(audioName);
|
||||
|
||||
if (result) {
|
||||
log.info("短链接设置成功!");
|
||||
|
||||
// 查询验证
|
||||
TtsRequestLog updatedLog = ttsRequestLogService.getTtsRequestLogById(requestLog.getId());
|
||||
if (updatedLog != null) {
|
||||
log.info("验证结果:");
|
||||
log.info(" 音频名称: {}", updatedLog.getAudioName());
|
||||
log.info(" 短链接: {}", updatedLog.getShortUrl());
|
||||
log.info(" 过期时间: {}", updatedLog.getShortUrlExpireTime());
|
||||
}
|
||||
} else {
|
||||
log.error("短链接设置失败");
|
||||
}
|
||||
} else {
|
||||
log.error("测试日志记录保存失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试过程中发生异常: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试不存在的音频名称
|
||||
*/
|
||||
@Test
|
||||
public void testSetShortUrlByNonExistentAudioName() {
|
||||
try {
|
||||
String audioName = "non_existent_audio.mp3";
|
||||
|
||||
log.info("开始测试不存在的音频名称...");
|
||||
log.info("音频名称: {}", audioName);
|
||||
|
||||
// 测试设置短链接
|
||||
boolean result = ttsRequestLogService.setShortUrlByAudioName(audioName);
|
||||
|
||||
if (result) {
|
||||
log.error("意外成功:不存在的音频名称不应该设置成功");
|
||||
} else {
|
||||
log.info("测试通过:不存在的音频名称正确返回失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试过程中发生异常: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试空音频名称
|
||||
*/
|
||||
@Test
|
||||
public void testSetShortUrlByEmptyAudioName() {
|
||||
try {
|
||||
String audioName = "";
|
||||
|
||||
log.info("开始测试空音频名称...");
|
||||
log.info("音频名称: '{}'", audioName);
|
||||
|
||||
// 测试设置短链接
|
||||
boolean result = ttsRequestLogService.setShortUrlByAudioName(audioName);
|
||||
|
||||
if (result) {
|
||||
log.error("意外成功:空音频名称不应该设置成功");
|
||||
} else {
|
||||
log.info("测试通过:空音频名称正确返回失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("测试过程中发生异常: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建测试用的TTS请求日志
|
||||
*/
|
||||
private TtsRequestLog createTestRequestLog(String audioName) {
|
||||
TtsRequestLog requestLog = new TtsRequestLog();
|
||||
requestLog.setRequestTime(LocalDateTime.now());
|
||||
requestLog.setModel("fnlp/MOSS-TTSD-v0.5");
|
||||
requestLog.setInputText("测试音频文件");
|
||||
requestLog.setInputLength(6);
|
||||
requestLog.setVoice("fnlp/MOSS-TTSD-v0.5:claire");
|
||||
requestLog.setStatus("SUCCESS");
|
||||
requestLog.setAudioName(audioName);
|
||||
requestLog.setMinioUrl("http://localhost:9000/audio/" + audioName);
|
||||
requestLog.setCreatorName("测试用户");
|
||||
requestLog.setCreatorPhone("13800138000");
|
||||
requestLog.setCreateTime(LocalDateTime.now());
|
||||
requestLog.setUpdateTime(LocalDateTime.now());
|
||||
return requestLog;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user