fix(项目管理): 修复项目环境的校验数据源连通失败的缺陷
This commit is contained in:
parent
78047f577a
commit
33fda25e5f
|
@ -524,4 +524,5 @@ relate_source_id_length_range=关联来源ID必须在{min}和{max}之间
|
|||
relate_source_type_not_blank=关联资源类型不能为空
|
||||
|
||||
api_import_schedule=接口定义-定时导入任务
|
||||
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
||||
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
||||
api_test_environment_datasource_connect_failed=数据源连接失败
|
|
@ -555,4 +555,5 @@ relate_source_type_not_blank=The associated resource type cannot be empty
|
|||
|
||||
api_import_schedule=API import schedule
|
||||
|
||||
project.description.length_range=The description must be between {min} and {max} characters
|
||||
project.description.length_range=The description must be between {min} and {max} characters
|
||||
api_test_environment_datasource_connect_failed=Data source connection failed
|
|
@ -552,4 +552,5 @@ relate_source_type_not_blank=关联资源类型不能为空
|
|||
|
||||
api_import_schedule=接口定义-定时导入任务
|
||||
|
||||
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
||||
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
||||
api_test_environment_datasource_connect_failed=数据源连接失败
|
|
@ -482,6 +482,7 @@ node.name.repeat=節點名稱重複
|
|||
project.cannot.match.parent=和父節點的項目無法匹配
|
||||
api_test_environment_not_exist=環境不存在
|
||||
mock_environment_not_delete=Mock 環境不允許刪除
|
||||
api_test_environment_datasource_connect_failed=數據源連接失敗
|
||||
|
||||
# 状态流
|
||||
status=狀態
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
@ -96,7 +97,10 @@ public class EnvironmentService {
|
|||
Properties properties = new Properties();
|
||||
properties.setProperty(USERNAME, databaseConfig.getUsername());
|
||||
properties.setProperty(PASSWORD, databaseConfig.getPassword());
|
||||
driver.connect(databaseConfig.getDbUrl(), properties);
|
||||
Connection connect = driver.connect(databaseConfig.getDbUrl(), properties);
|
||||
if (connect == null) {
|
||||
throw new MSException(Translator.get("api_test_environment_datasource_connect_failed"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -857,8 +857,8 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
//测试mysql dbUrl为空
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setDbUrl(null);
|
||||
dataSource.setPassword("Password123@mysql");
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setUsername(username);
|
||||
//测试mysql DriverId为空
|
||||
dataSource.setDriverId(null);
|
||||
this.requestPost(validate, dataSource, BAD_REQUEST_MATCHER);
|
||||
|
@ -867,6 +867,16 @@ public class EnvironmentControllerTests extends BaseTest {
|
|||
dataSource.setDbUrl("jdbc:mysql://");
|
||||
dataSource.setDriverId(StringUtils.join("system", "&", "com.mysql.cj.jdbc.Driver"));
|
||||
this.requestPost(validate, dataSource, ERROR_REQUEST_MATCHER);
|
||||
dataSource.setDbUrl(dburl);
|
||||
dataSource.setUsername("测试数据源");
|
||||
dataSource.setPassword("测试数据源");
|
||||
dataSource.setDriverId(StringUtils.join("system", "&", "com.mysql.cj.jdbc.Driver"));
|
||||
this.requestPost(validate, dataSource, ERROR_REQUEST_MATCHER);
|
||||
dataSource.setDbUrl("测试数据源");
|
||||
dataSource.setUsername("测试数据源");
|
||||
dataSource.setPassword("测试数据源");
|
||||
dataSource.setDriverId(StringUtils.join("system", "&", "com.mysql.cj.jdbc.Driver"));
|
||||
this.requestPost(validate, dataSource, ERROR_REQUEST_MATCHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue