Skip to content

Commit

Permalink
Improve DataSourcePreparer unit test (#21044)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandynz authored Sep 18, 2022
1 parent 66923e4 commit 023ba31
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 112 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@

package org.apache.shardingsphere.data.pipeline.core.prepare.datasource;

import org.apache.shardingsphere.data.pipeline.api.datasource.PipelineDataSourceManager;
import org.apache.shardingsphere.data.pipeline.api.datasource.config.PipelineDataSourceConfiguration;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;
import java.util.regex.Pattern;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public final class AbstractDataSourcePreparerTest {

Expand All @@ -38,6 +46,24 @@ public void prepareTargetTables(final PrepareTargetTablesParameter parameter) {
}
};

@Test
public void assertGetCachedDataSource() {
PipelineDataSourceConfiguration dataSourceConfig = mock(PipelineDataSourceConfiguration.class);
PipelineDataSourceManager dataSourceManager = mock(PipelineDataSourceManager.class);
preparer.getCachedDataSource(dataSourceConfig, dataSourceManager);
verify(dataSourceManager).getDataSource(dataSourceConfig);
}

@Test
public void assertExecuteTargetTableSQL() throws SQLException {
Statement statement = mock(Statement.class);
Connection targetConnection = mock(Connection.class);
when(targetConnection.createStatement()).thenReturn(statement);
String sql = "CREATE TABLE t (id int)";
preparer.executeTargetTableSQL(targetConnection, sql);
verify(statement).execute(sql);
}

@Test
public void assertAddIfNotExistsForCreateTableSQL() {
Collection<String> createTableSQLs = Arrays.asList("CREATE TABLE IF NOT EXISTS t (id int)", "CREATE TABLE t (id int)",
Expand Down

0 comments on commit 023ba31

Please sign in to comment.