|
|
|
@ -21,15 +21,14 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.DATASOURCE_LIST; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.DataSourceServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
|
import org.apache.dolphinscheduler.common.constants.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.constants.DataSourceConstants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.DataSource; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; |
|
|
|
@ -39,10 +38,8 @@ import org.apache.dolphinscheduler.plugin.datasource.api.utils.CommonUtils;
|
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.hive.param.HiveDataSourceParamDTO; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.mysql.param.MySQLDataSourceParamDTO; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.oracle.param.OracleDataSourceParamDTO; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.datasource.postgresql.param.PostgreSQLDataSourceParamDTO; |
|
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
|
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; |
|
|
|
|
import org.apache.dolphinscheduler.spi.enums.DbConnectType; |
|
|
|
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
|
|
|
@ -51,9 +48,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -61,11 +56,9 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.mockito.InjectMocks; |
|
|
|
|
import org.mockito.Mock; |
|
|
|
|
import org.mockito.MockedStatic; |
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
import org.powermock.api.mockito.PowerMockito; |
|
|
|
|
import org.powermock.core.classloader.annotations.PowerMockIgnore; |
|
|
|
@ -81,6 +74,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
@PowerMockIgnore({"sun.security.*", "javax.net.*"}) |
|
|
|
|
@PrepareForTest({DataSourceUtils.class, CommonUtils.class, DataSourceClientProvider.class, PasswordUtils.class}) |
|
|
|
|
public class DataSourceServiceTest { |
|
|
|
|
|
|
|
|
|
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); |
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceServiceTest.class); |
|
|
|
|
private static final Logger dataSourceServiceLogger = LoggerFactory.getLogger(DataSourceServiceImpl.class); |
|
|
|
@ -124,22 +118,26 @@ public class DataSourceServiceTest {
|
|
|
|
|
DbType dataSourceType = postgreSqlDatasourceParam.getType(); |
|
|
|
|
// data source exits
|
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); |
|
|
|
|
Result connectionResult = new Result(Status.DATASOURCE_CONNECT_FAILED.getCode(), Status.DATASOURCE_CONNECT_FAILED.getMsg()); |
|
|
|
|
Result connectionResult = |
|
|
|
|
new Result(Status.DATASOURCE_CONNECT_FAILED.getCode(), Status.DATASOURCE_CONNECT_FAILED.getMsg()); |
|
|
|
|
// PowerMockito.when(dataSourceService.checkConnection(dataSourceType, parameter)).thenReturn(connectionResult);
|
|
|
|
|
PowerMockito.doReturn(connectionResult).when(dataSourceService).checkConnection(dataSourceType, connectionParam); |
|
|
|
|
PowerMockito.doReturn(connectionResult).when(dataSourceService).checkConnection(dataSourceType, |
|
|
|
|
connectionParam); |
|
|
|
|
Result connectFailedResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(), connectFailedResult.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
// data source exits
|
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); |
|
|
|
|
connectionResult = new Result(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg()); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)) |
|
|
|
|
.thenReturn(connectionResult); |
|
|
|
|
Result notValidError = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getCode(), notValidError.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)) |
|
|
|
|
.thenReturn(connectionResult); |
|
|
|
|
Result success = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); |
|
|
|
|
} |
|
|
|
@ -162,13 +160,15 @@ public class DataSourceServiceTest {
|
|
|
|
|
|
|
|
|
|
// data source not exits
|
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null); |
|
|
|
|
Result resourceNotExits = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Result resourceNotExits = |
|
|
|
|
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getCode(), resourceNotExits.getCode().intValue()); |
|
|
|
|
// user no operation perm
|
|
|
|
|
DataSource dataSource = new DataSource(); |
|
|
|
|
dataSource.setUserId(0); |
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); |
|
|
|
|
Result userNoOperationPerm = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Result userNoOperationPerm = |
|
|
|
|
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM.getCode(), userNoOperationPerm.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
// data source name exits
|
|
|
|
@ -177,7 +177,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
dataSourceList.add(dataSource); |
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); |
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(dataSourceList); |
|
|
|
|
Result dataSourceNameExist = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Result dataSourceNameExist = |
|
|
|
|
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.DATASOURCE_EXIST.getCode(), dataSourceNameExist.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
// data source connect failed
|
|
|
|
@ -186,15 +187,18 @@ public class DataSourceServiceTest {
|
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); |
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(null); |
|
|
|
|
Result connectionResult = new Result(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg()); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)) |
|
|
|
|
.thenReturn(connectionResult); |
|
|
|
|
Result connectFailed = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(), connectFailed.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); |
|
|
|
|
PowerMockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName)).thenReturn(null); |
|
|
|
|
connectionResult = new Result(Status.DATASOURCE_CONNECT_FAILED.getCode(), Status.DATASOURCE_CONNECT_FAILED.getMsg()); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)).thenReturn(connectionResult); |
|
|
|
|
connectionResult = |
|
|
|
|
new Result(Status.DATASOURCE_CONNECT_FAILED.getCode(), Status.DATASOURCE_CONNECT_FAILED.getMsg()); |
|
|
|
|
PowerMockito.when(dataSourceService.checkConnection(dataSourceType, connectionParam)) |
|
|
|
|
.thenReturn(connectionResult); |
|
|
|
|
Result success = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); |
|
|
|
|
|
|
|
|
@ -209,9 +213,12 @@ public class DataSourceServiceTest {
|
|
|
|
|
String searchVal = ""; |
|
|
|
|
int pageNo = 1; |
|
|
|
|
int pageSize = 10; |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), DATASOURCE_LIST, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, loginUser.getId(), baseServiceLogger)).thenReturn(ids); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), DATASOURCE_LIST, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, |
|
|
|
|
loginUser.getId(), baseServiceLogger)).thenReturn(ids); |
|
|
|
|
|
|
|
|
|
Result result = dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
|
@ -230,8 +237,10 @@ public class DataSourceServiceTest {
|
|
|
|
|
User loginUser = getAdminUser(); |
|
|
|
|
int dataSourceId = 1; |
|
|
|
|
Result result = new Result(); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, new Object[]{dataSourceId}, -1, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, |
|
|
|
|
new Object[]{dataSourceId}, -1, baseServiceLogger)).thenReturn(true); |
|
|
|
|
// resource not exist
|
|
|
|
|
dataSourceService.putMsg(result, Status.RESOURCE_NOT_EXIST); |
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null); |
|
|
|
@ -250,8 +259,10 @@ public class DataSourceServiceTest {
|
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
loginUser.setId(1); |
|
|
|
|
dataSource.setId(22); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), DATASOURCE_DELETE, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE,new Object[]{dataSource.getId()} , 0, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), DATASOURCE_DELETE, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, |
|
|
|
|
new Object[]{dataSource.getId()}, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
|
PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); |
|
|
|
|
Assert.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode()); |
|
|
|
|
|
|
|
|
@ -263,8 +274,10 @@ public class DataSourceServiceTest {
|
|
|
|
|
loginUser.setId(1); |
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
int userId = 3; |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, |
|
|
|
|
baseServiceLogger)).thenReturn(true); |
|
|
|
|
// test admin user
|
|
|
|
|
Mockito.when(dataSourceMapper.queryAuthedDatasource(userId)).thenReturn(getSingleDataSourceList()); |
|
|
|
|
Mockito.when(dataSourceMapper.queryDatasourceExceptUserId(userId)).thenReturn(getDataSourceList()); |
|
|
|
@ -276,7 +289,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
// test non-admin user
|
|
|
|
|
loginUser.setId(2); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(dataSourceMapper.selectByMap(Collections.singletonMap("user_id", loginUser.getId()))).thenReturn(getDataSourceList()); |
|
|
|
|
Mockito.when(dataSourceMapper.selectByMap(Collections.singletonMap("user_id", loginUser.getId()))) |
|
|
|
|
.thenReturn(getDataSourceList()); |
|
|
|
|
result = dataSourceService.unauthDatasource(loginUser, userId); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
dataSources = (List<DataSource>) result.get(Constants.DATA_LIST); |
|
|
|
@ -311,9 +325,12 @@ public class DataSourceServiceTest {
|
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Set<Integer> dataSourceIds = new HashSet<>(); |
|
|
|
|
dataSourceIds.add(1); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, loginUser.getId(), dataSourceServiceLogger)).thenReturn(dataSourceIds); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, null, |
|
|
|
|
loginUser.getId(), null, baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, |
|
|
|
|
baseServiceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, |
|
|
|
|
loginUser.getId(), dataSourceServiceLogger)).thenReturn(dataSourceIds); |
|
|
|
|
|
|
|
|
|
DataSource dataSource = new DataSource(); |
|
|
|
|
dataSource.setType(DbType.MYSQL); |
|
|
|
@ -361,7 +378,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
dataSource.setName("test"); |
|
|
|
|
dataSource.setNote("Note"); |
|
|
|
|
dataSource.setType(DbType.ORACLE); |
|
|
|
|
dataSource.setConnectionParams("{\"connectType\":\"ORACLE_SID\",\"address\":\"jdbc:oracle:thin:@192.168.xx.xx:49161\",\"database\":\"XE\"," |
|
|
|
|
dataSource.setConnectionParams( |
|
|
|
|
"{\"connectType\":\"ORACLE_SID\",\"address\":\"jdbc:oracle:thin:@192.168.xx.xx:49161\",\"database\":\"XE\"," |
|
|
|
|
+ "\"jdbcUrl\":\"jdbc:oracle:thin:@192.168.xx.xx:49161/XE\",\"user\":\"system\",\"password\":\"oracle\"}"); |
|
|
|
|
|
|
|
|
|
return dataSource; |
|
|
|
@ -373,7 +391,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
dataSource.setName("test"); |
|
|
|
|
dataSource.setNote("Note"); |
|
|
|
|
dataSource.setType(DbType.ORACLE); |
|
|
|
|
dataSource.setConnectionParams("{\"connectType\":\"ORACLE_SID\",\"address\":\"jdbc:oracle:thin:@192.168.xx.xx:49161\",\"database\":\"XE\"," |
|
|
|
|
dataSource.setConnectionParams( |
|
|
|
|
"{\"connectType\":\"ORACLE_SID\",\"address\":\"jdbc:oracle:thin:@192.168.xx.xx:49161\",\"database\":\"XE\"," |
|
|
|
|
+ "\"jdbcUrl\":\"jdbc:oracle:thin:@192.168.xx.xx:49161/XE\",\"user\":\"system\",\"password\":\"oracle\"}"); |
|
|
|
|
|
|
|
|
|
return dataSource; |
|
|
|
@ -390,7 +409,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
oracleDatasourceParamDTO.setConnectType(DbConnectType.ORACLE_SERVICE_NAME); |
|
|
|
|
|
|
|
|
|
ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(oracleDatasourceParamDTO); |
|
|
|
|
String expected = "{\"user\":\"test\",\"password\":\"test\",\"address\":\"jdbc:oracle:thin:@//192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:oracle:thin:@//192.168.9.1:1521/im\"," |
|
|
|
|
String expected = |
|
|
|
|
"{\"user\":\"test\",\"password\":\"test\",\"address\":\"jdbc:oracle:thin:@//192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:oracle:thin:@//192.168.9.1:1521/im\"," |
|
|
|
|
+ "\"driverClassName\":\"oracle.jdbc.OracleDriver\",\"validationQuery\":\"select 1 from dual\",\"connectType\":\"ORACLE_SERVICE_NAME\"}"; |
|
|
|
|
Assert.assertEquals(expected, JSONUtils.toJsonString(connectionParam)); |
|
|
|
|
|
|
|
|
@ -410,7 +430,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
hiveDataSourceParamDTO.setLoginUserKeytabUsername("test2/hdfs-mycluster@ESZ.COM"); |
|
|
|
|
connectionParam = DataSourceUtils.buildConnectionParams(hiveDataSourceParamDTO); |
|
|
|
|
|
|
|
|
|
expected = "{\"user\":\"test\",\"password\":\"test\",\"address\":\"jdbc:hive2://192.168.9.1:10000\",\"database\":\"im\"," |
|
|
|
|
expected = |
|
|
|
|
"{\"user\":\"test\",\"password\":\"test\",\"address\":\"jdbc:hive2://192.168.9.1:10000\",\"database\":\"im\"," |
|
|
|
|
+ "\"jdbcUrl\":\"jdbc:hive2://192.168.9.1:10000/im\",\"driverClassName\":\"org.apache.hive.jdbc.HiveDriver\",\"validationQuery\":\"select 1\"," |
|
|
|
|
+ "\"principal\":\"hive/hdfs-mycluster@ESZ.COM\",\"javaSecurityKrb5Conf\":\"/opt/krb5.conf\",\"loginUserKeytabUsername\":\"test2/hdfs-mycluster@ESZ.COM\"," |
|
|
|
|
+ "\"loginUserKeytabPath\":\"/opt/hdfs.headless.keytab\"}"; |
|
|
|
@ -437,7 +458,8 @@ public class DataSourceServiceTest {
|
|
|
|
|
// ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(mysqlDatasourceParamDTO);
|
|
|
|
|
// String expected =
|
|
|
|
|
// "{\"user\":\"test\",\"password\":\"bnVsbE1USXpORFUy\",\"address\":\"jdbc:mysql://192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:mysql://192.168.9.1:1521/"
|
|
|
|
|
// + "im\",\"driverClassName\":\"com.mysql.cj.jdbc.Driver\",\"validationQuery\":\"select 1\",\"props\":{\"autoDeserialize\":\"yes\",\"allowUrlInLocalInfile\":\"true\"}}";
|
|
|
|
|
// + "im\",\"driverClassName\":\"com.mysql.cj.jdbc.Driver\",\"validationQuery\":\"select
|
|
|
|
|
// 1\",\"props\":{\"autoDeserialize\":\"yes\",\"allowUrlInLocalInfile\":\"true\"}}";
|
|
|
|
|
// Assertions.assertEquals(expected, JSONUtils.toJsonString(connectionParam));
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
@ -475,15 +497,12 @@ public class DataSourceServiceTest {
|
|
|
|
|
ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(postgreSqlDatasourceParam); |
|
|
|
|
|
|
|
|
|
PowerMockito.mockStatic(DataSourceUtils.class); |
|
|
|
|
PowerMockito.mockStatic(DataSourceClientProvider.class); |
|
|
|
|
DataSourceClientProvider clientProvider = PowerMockito.mock(DataSourceClientProvider.class); |
|
|
|
|
PowerMockito.when(DataSourceClientProvider.getInstance()).thenReturn(clientProvider); |
|
|
|
|
|
|
|
|
|
PowerMockito.when(DataSourceUtils.getConnection(Mockito.any(), Mockito.any())).thenReturn(null); |
|
|
|
|
Result result = dataSourceService.checkConnection(dataSourceType, connectionParam); |
|
|
|
|
Assert.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), result.getCode().intValue()); |
|
|
|
|
|
|
|
|
|
Connection connection = PowerMockito.mock(Connection.class); |
|
|
|
|
PowerMockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); |
|
|
|
|
PowerMockito.when(DataSourceUtils.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); |
|
|
|
|
result = dataSourceService.checkConnection(dataSourceType, connectionParam); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); |
|
|
|
|
|
|
|
|
|