Files
java-10561/src/test/java/com/gxwebsoft/config/ServerUrlConfigTest.java
2025-09-06 11:58:18 +08:00

52 lines
1.8 KiB
Java

package com.gxwebsoft.config;
import com.gxwebsoft.common.core.config.ConfigProperties;
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.*;
/**
* 服务器URL配置测试
* 验证server-url配置是否正确从配置文件读取
*/
@SpringBootTest
@ActiveProfiles("dev")
public class ServerUrlConfigTest {
@Autowired
private ConfigProperties configProperties;
@Test
public void testServerUrlConfiguration() {
// 验证配置属性不为空
assertNotNull(configProperties, "ConfigProperties should not be null");
// 验证server-url配置正确读取
String serverUrl = configProperties.getServerUrl();
assertNotNull(serverUrl, "Server URL should not be null");
assertFalse(serverUrl.isEmpty(), "Server URL should not be empty");
// 在开发环境下,应该是本地地址
assertTrue(serverUrl.contains("127.0.0.1") || serverUrl.contains("localhost"),
"In dev environment, server URL should contain localhost or 127.0.0.1");
System.out.println("当前配置的服务器URL: " + serverUrl);
}
@Test
public void testServerUrlFormat() {
String serverUrl = configProperties.getServerUrl();
// 验证URL格式
assertTrue(serverUrl.startsWith("http://") || serverUrl.startsWith("https://"),
"Server URL should start with http:// or https://");
assertTrue(serverUrl.endsWith("/api"),
"Server URL should end with /api");
System.out.println("服务器URL格式验证通过: " + serverUrl);
}
}