Search in sources :

Example 1 with MockDataSource

use of io.seata.rm.datasource.mock.MockDataSource in project seata by seata.

the class DataSourceProxyTest method test_constructor.

@Test
public void test_constructor() {
    DataSource dataSource = new MockDataSource();
    DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
    Assertions.assertEquals(dataSourceProxy.getTargetDataSource(), dataSource);
    DataSourceProxy dataSourceProxy2 = new DataSourceProxy(dataSourceProxy);
    Assertions.assertEquals(dataSourceProxy2.getTargetDataSource(), dataSource);
}
Also used : MockDataSource(io.seata.rm.datasource.mock.MockDataSource) MockDataSource(io.seata.rm.datasource.mock.MockDataSource) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 2 with MockDataSource

use of io.seata.rm.datasource.mock.MockDataSource in project seata by seata.

the class MySQLInsertExecutorTest method init.

@BeforeEach
public void init() throws SQLException {
    ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
    when(connectionProxy.getDbType()).thenReturn(JdbcConstants.MYSQL);
    DataSourceProxy dataSourceProxy = new DataSourceProxy(new MockDataSource());
    when(connectionProxy.getDataSourceProxy()).thenReturn(dataSourceProxy);
    statementProxy = mock(PreparedStatementProxy.class);
    when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
    when(statementProxy.getTargetStatement()).thenReturn(statementProxy);
    MockResultSet resultSet = new MockResultSet(statementProxy);
    resultSet.mockResultSet(Arrays.asList("Variable_name", "Value"), new Object[][] { { "auto_increment_increment", "1" } });
    when(statementProxy.getTargetStatement().executeQuery("SHOW VARIABLES LIKE 'auto_increment_increment'")).thenReturn(resultSet);
    StatementCallback statementCallback = mock(StatementCallback.class);
    sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
    tableMeta = mock(TableMeta.class);
    insertExecutor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
    pkIndexMap = new HashMap<String, Integer>() {

        {
            put(ID_COLUMN, pkIndex);
        }
    };
}
Also used : DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) MySQLInsertExecutor(io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor) MockDataSource(io.seata.rm.datasource.mock.MockDataSource) MockResultSet(io.seata.rm.datasource.mock.MockResultSet) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) Mockito.anyString(org.mockito.Mockito.anyString) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with MockDataSource

use of io.seata.rm.datasource.mock.MockDataSource in project seata by seata.

the class DataSourceProxyXATest method test_constructor.

@Test
public void test_constructor() {
    DataSource dataSource = new MockDataSource();
    DataSourceProxyXA dataSourceProxy = new DataSourceProxyXA(dataSource);
    Assertions.assertEquals(dataSourceProxy.getTargetDataSource(), dataSource);
    DataSourceProxyXA dataSourceProxy2 = new DataSourceProxyXA(dataSourceProxy);
    Assertions.assertEquals(dataSourceProxy2.getTargetDataSource(), dataSource);
}
Also used : DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) MockDataSource(io.seata.rm.datasource.mock.MockDataSource) MockDataSource(io.seata.rm.datasource.mock.MockDataSource) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Aggregations

MockDataSource (io.seata.rm.datasource.mock.MockDataSource)3 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)2 DataSource (javax.sql.DataSource)2 Test (org.junit.jupiter.api.Test)2 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)1 DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)1 PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)1 MySQLInsertExecutor (io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor)1 MockResultSet (io.seata.rm.datasource.mock.MockResultSet)1 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)1 DataSourceProxyXA (io.seata.rm.datasource.xa.DataSourceProxyXA)1 SQLInsertRecognizer (io.seata.sqlparser.SQLInsertRecognizer)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Mockito.anyString (org.mockito.Mockito.anyString)1