@ -87,7 +87,7 @@ public class DataSourceServiceTest {
// data source exits
// data source exits
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName . trim ( ) ) ) . thenReturn ( null ) ;
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.when(dataSourceService.checkConnection(dataSourceType, parameter)).thenReturn(connectionResult);
PowerMockito . doReturn ( connectionResult ) . when ( dataSourceService ) . checkConnection ( dataSourceType , parameter ) ;
PowerMockito . doReturn ( connectionResult ) . when ( dataSourceService ) . checkConnection ( dataSourceType , parameter ) ;
Result connectFailedResult = dataSourceService . createDataSource ( loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Result connectFailedResult = dataSourceService . createDataSource ( loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
@ -95,7 +95,7 @@ public class DataSourceServiceTest {
// data source exits
// data source exits
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName . trim ( ) ) ) . thenReturn ( null ) ;
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName . trim ( ) ) ) . thenReturn ( null ) ;
connectionResult = new Result ( Status . SUCCESS . getCode ( ) , Status . SUCCESS . getMsg ( ) ) ;
connectionResult = new Result ( Status . SUCCESS . getCode ( ) , Status . SUCCESS . getMsg ( ) ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
PowerMockito . when ( DataSourceFactory . getDatasource ( dataSourceType , parameter ) ) . thenReturn ( null ) ;
PowerMockito . when ( DataSourceFactory . getDatasource ( dataSourceType , parameter ) ) . thenReturn ( null ) ;
Result notValidError = dataSourceService . createDataSource ( loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Result notValidError = dataSourceService . createDataSource ( loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
@ -141,7 +141,7 @@ public class DataSourceServiceTest {
// data source connect failed
// data source connect failed
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( dataSource ) ;
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( dataSource ) ;
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName ) ) . thenReturn ( null ) ;
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName ) ) . thenReturn ( null ) ;
Result connectionResult = new Result ( Status . SUCCESS . getCode ( ) , Status . SUCCESS . getMsg ( ) ) ;
Result connectionResult = new Result ( Status . SUCCESS . getCode ( ) , Status . SUCCESS . getMsg ( ) ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
Result connectFailed = dataSourceService . updateDataSource ( dataSourceId , loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Result connectFailed = dataSourceService . updateDataSource ( dataSourceId , loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Assert . assertEquals ( Status . DATASOURCE_CONNECT_FAILED . getCode ( ) , connectFailed . getCode ( ) . intValue ( ) ) ;
Assert . assertEquals ( Status . DATASOURCE_CONNECT_FAILED . getCode ( ) , connectFailed . getCode ( ) . intValue ( ) ) ;
@ -149,7 +149,7 @@ public class DataSourceServiceTest {
//success
//success
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( dataSource ) ;
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( dataSource ) ;
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName ) ) . thenReturn ( null ) ;
PowerMockito . when ( dataSourceMapper . queryDataSourceByName ( dataSourceName ) ) . thenReturn ( null ) ;
connectionResult = new Result ( Status . DATASOURCE_CONNECT_FAILED . getCode ( ) , Status . DATASOURCE_CONNECT_FAILED . getMsg ( ) ) ;
connectionResult = new Result ( Status . DATASOURCE_CONNECT_FAILED . getCode ( ) , Status . DATASOURCE_CONNECT_FAILED . getMsg ( ) ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
PowerMockito . when ( dataSourceService . checkConnection ( dataSourceType , parameter ) ) . thenReturn ( connectionResult ) ;
Result success = dataSourceService . updateDataSource ( dataSourceId , loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Result success = dataSourceService . updateDataSource ( dataSourceId , loginUser , dataSourceName , dataSourceDesc , dataSourceType , parameter ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , success . getCode ( ) . intValue ( ) ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , success . getCode ( ) . intValue ( ) ) ;
@ -171,7 +171,7 @@ public class DataSourceServiceTest {
int dataSourceId = - 1 ;
int dataSourceId = - 1 ;
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( null ) ;
PowerMockito . when ( dataSourceMapper . selectById ( dataSourceId ) ) . thenReturn ( null ) ;
Result result = dataSourceService . connectionTest ( dataSourceId ) ;
Result result = dataSourceService . connectionTest ( dataSourceId ) ;
Assert . assertEquals ( Status . RESOURCE_NOT_EXIST . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
Assert . assertEquals ( Status . RESOURCE_NOT_EXIST . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
}
}
@Test
@Test
@ -280,7 +280,7 @@ public class DataSourceServiceTest {
@Test
@Test
public void buildParameter ( ) {
public void buildParameter ( ) {
String param = dataSourceService . buildParameter ( DbType . ORACLE , "192.168.9.1" , "1521" , "im"
String param = dataSourceService . buildParameter ( DbType . ORACLE , "192.168.9.1" , "1521" , "im"
, "" , "test" , "test" , DbConnectType . ORACLE_SERVICE_NAME , "" , "" , "" , "" ) ;
, "" , "test" , "test" , DbConnectType . ORACLE_SERVICE_NAME , "" , "" , "" , "" ) ;
String expected = "{\"connectType\":\"ORACLE_SERVICE_NAME\",\"type\":\"ORACLE_SERVICE_NAME\",\"address\":\"jdbc:oracle:thin:@//192.168.9.1:1521\",\"database\":\"im\","
String expected = "{\"connectType\":\"ORACLE_SERVICE_NAME\",\"type\":\"ORACLE_SERVICE_NAME\",\"address\":\"jdbc:oracle:thin:@//192.168.9.1:1521\",\"database\":\"im\","
+ "\"jdbcUrl\":\"jdbc:oracle:thin:@//192.168.9.1:1521/im\",\"user\":\"test\",\"password\":\"test\"}" ;
+ "\"jdbcUrl\":\"jdbc:oracle:thin:@//192.168.9.1:1521/im\",\"user\":\"test\",\"password\":\"test\"}" ;
Assert . assertEquals ( expected , param ) ;
Assert . assertEquals ( expected , param ) ;
@ -300,8 +300,9 @@ public class DataSourceServiceTest {
@Test
@Test
public void buildParameterWithDecodePassword ( ) {
public void buildParameterWithDecodePassword ( ) {
PropertyUtils . setValue ( Constants . DATASOURCE_ENCRYPTION_ENABLE , "true" ) ;
PropertyUtils . setValue ( Constants . DATASOURCE_ENCRYPTION_ENABLE , "true" ) ;
String other = "{\"autoDeserialize\":\"yes\",\"allowUrlInLocalInfile\":\"true\"}" ;
String param = dataSourceService . buildParameter ( DbType . MYSQL , "192.168.9.1" , "1521" , "im"
String param = dataSourceService . buildParameter ( DbType . MYSQL , "192.168.9.1" , "1521" , "im"
, "" , "test" , "123456" , null , "" , "" , "" , "" ) ;
, "" , "test" , "123456" , null , other , "" , "" , "" ) ;
String expected = "{\"type\":null,\"address\":\"jdbc:mysql://192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:mysql://192.168.9.1:1521/im\","
String expected = "{\"type\":null,\"address\":\"jdbc:mysql://192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:mysql://192.168.9.1:1521/im\","
+ "\"user\":\"test\",\"password\":\"IUAjJCVeJipNVEl6TkRVMg==\"}" ;
+ "\"user\":\"test\",\"password\":\"IUAjJCVeJipNVEl6TkRVMg==\"}" ;
Assert . assertEquals ( expected , param ) ;
Assert . assertEquals ( expected , param ) ;
@ -309,7 +310,8 @@ public class DataSourceServiceTest {
PropertyUtils . setValue ( Constants . DATASOURCE_ENCRYPTION_ENABLE , "false" ) ;
PropertyUtils . setValue ( Constants . DATASOURCE_ENCRYPTION_ENABLE , "false" ) ;
param = dataSourceService . buildParameter ( DbType . MYSQL , "192.168.9.1" , "1521" , "im"
param = dataSourceService . buildParameter ( DbType . MYSQL , "192.168.9.1" , "1521" , "im"
, "" , "test" , "123456" , null , "" , "" , "" , "" ) ;
, "" , "test" , "123456" , null , "" , "" , "" , "" ) ;
expected = "{\"type\":null,\"address\":\"jdbc:mysql://192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:mysql://192.168.9.1:1521/im\",\"user\":\"test\",\"password\":\"123456\"}" ;
expected = "{\"type\":null,\"address\":\"jdbc:mysql://192.168.9.1:1521\",\"database\":\"im\",\"jdbcUrl\":\"jdbc:mysql://192.168.9.1:1521/im\","
+ "\"user\":\"test\",\"password\":\"123456\"}" ;
Assert . assertEquals ( expected , param ) ;
Assert . assertEquals ( expected , param ) ;
}
}
@ -328,7 +330,6 @@ public class DataSourceServiceTest {
/ * *
/ * *
* test check connection
* test check connection
* @throws Exception
* /
* /
@Test
@Test
public void testCheckConnection ( ) throws Exception {
public void testCheckConnection ( ) throws Exception {