package com.rj.service;

import com.rj.dto.VideoSynthesisRequestDto;
import com.rj.entity.VideoSynthesisLog;
import com.rj.service.IVideoSynthesisService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.*;

/**
 * 视频合成视频名称功能测试类
 * 
 * @author rj
 * @date 2025-01-30
 */
@SpringBootTest
@ActiveProfiles("test")
public class VideoSynthesisVideoNameTest {

    @Autowired
    private IVideoSynthesisService videoSynthesisService;

    /**
     * 测试设置自定义视频名称
     */
    @Test
    public void testCustomVideoName() {
        VideoSynthesisRequestDto request = new VideoSynthesisRequestDto();
        request.setVideoName("我的测试视频");
        request.setImageUrl("http://test.com/image.jpg");
        request.setAudioUrl("http://test.com/audio.mp3");
        request.setModel("liveportrait");
        
        VideoSynthesisLog result = videoSynthesisService.synthesizeVideoAndSave(request);
        
        assertNotNull(result);
        assertEquals("我的测试视频", result.getVideoName());
        System.out.println("自定义视频名称测试通过: " + result.getVideoName());
    }

    /**
     * 测试空视频名称时使用默认名称
     */
    @Test
    public void testEmptyVideoName() {
        VideoSynthesisRequestDto request = new VideoSynthesisRequestDto();
        request.setVideoName(""); // 空字符串
        request.setImageUrl("http://test.com/image.jpg");
        request.setAudioUrl("http://test.com/audio.mp3");
        request.setModel("liveportrait");
        
        VideoSynthesisLog result = videoSynthesisService.synthesizeVideoAndSave(request);
        
        assertNotNull(result);
        assertNotNull(result.getVideoName());
        assertTrue(result.getVideoName().startsWith("视频合成_"));
        System.out.println("默认视频名称测试通过: " + result.getVideoName());
    }

    /**
     * 测试null视频名称时使用默认名称
     */
    @Test
    public void testNullVideoName() {
        VideoSynthesisRequestDto request = new VideoSynthesisRequestDto();
        request.setVideoName(null); // null值
        request.setImageUrl("http://test.com/image.jpg");
        request.setAudioUrl("http://test.com/audio.mp3");
        request.setModel("liveportrait");
        
        VideoSynthesisLog result = videoSynthesisService.synthesizeVideoAndSave(request);
        
        assertNotNull(result);
        assertNotNull(result.getVideoName());
        assertTrue(result.getVideoName().startsWith("视频合成_"));
        System.out.println("null视频名称测试通过: " + result.getVideoName());
    }

    /**
     * 测试视频名称长度
     */
    @Test
    public void testVideoNameLength() {
        VideoSynthesisRequestDto request = new VideoSynthesisRequestDto();
        request.setVideoName("这是一个很长的视频名称，用来测试视频名称字段的长度限制和存储功能");
        request.setImageUrl("http://test.com/image.jpg");
        request.setAudioUrl("http://test.com/audio.mp3");
        request.setModel("liveportrait");
        
        VideoSynthesisLog result = videoSynthesisService.synthesizeVideoAndSave(request);
        
        assertNotNull(result);
        assertEquals("这是一个很长的视频名称，用来测试视频名称字段的长度限制和存储功能", result.getVideoName());
        System.out.println("长视频名称测试通过: " + result.getVideoName());
    }
}

























































