Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve]Source skip check #12900

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ public Result<Object> createDataSource(User loginUser, BaseDataSourceParamDTO da
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
return result;
}
// check connect
ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(datasourceParam);
Result<Object> isConnection = checkConnection(datasourceParam.getType(), connectionParam);
if (Status.SUCCESS.getCode() != isConnection.getCode()) {
putMsg(result, Status.DATASOURCE_CONNECT_FAILED);
return result;
}

// build datasource
DataSource dataSource = new DataSource();
Expand Down Expand Up @@ -202,11 +196,6 @@ public Result<Object> updateDataSource(int id, User loginUser, BaseDataSourcePar
connectionParam.setPassword(oldParams.path(Constants.PASSWORD).asText());
}

Result<Object> isConnection = checkConnection(dataSource.getType(), connectionParam);
if (isConnection.isFailed()) {
return isConnection;
}

Date now = new Date();

dataSource.setName(dataSourceParam.getName().trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,12 @@ public void createDataSourceTest() throws ExecutionException {
try (
MockedStatic<DataSourceClientProvider> mockedStaticDataSourceClientProvider =
Mockito.mockStatic(DataSourceClientProvider.class)) {
// DATASOURCE_CONNECT_FAILED
DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class);
mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider);

Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null);
Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(null);
Result connectFailedResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam);
Assertions.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(),
connectFailedResult.getCode().intValue());

// SUCCESS
Connection connection = Mockito.mock(Connection.class);
Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection);
Result success = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam);
Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue());
}
Expand Down Expand Up @@ -204,15 +197,9 @@ public void updateDataSourceTest() throws ExecutionException {
DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class);
mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider);

Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(null);
Mockito.when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName())).thenReturn(null);
Result connectFailed =
dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
Assertions.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), connectFailed.getCode().intValue());

// SUCCESS
Connection connection = Mockito.mock(Connection.class);
Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection);
Result success = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam);
Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue());
}
Expand Down