Search in sources :

Example 6 with ConnectionProxy

use of cn.taketoday.jdbc.datasource.ConnectionProxy in project today-infrastructure by TAKETODAY.

the class JdbcTemplateTests method testConnectionCallback.

@Test
public void testConnectionCallback() throws Exception {
    String result = this.template.execute(new ConnectionCallback<String>() {

        @Override
        public String doInConnection(Connection con) {
            assertThat(con instanceof ConnectionProxy).isTrue();
            assertThat(((ConnectionProxy) con).getTargetConnection()).isSameAs(JdbcTemplateTests.this.connection);
            return "test";
        }
    });
    assertThat(result).isEqualTo("test");
}
Also used : Connection(java.sql.Connection) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ConnectionProxy(cn.taketoday.jdbc.datasource.ConnectionProxy) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionProxy (cn.taketoday.jdbc.datasource.ConnectionProxy)6 Test (org.junit.jupiter.api.Test)6 UncategorizedSQLException (cn.taketoday.jdbc.UncategorizedSQLException)4 TransactionAwareDataSourceProxy (cn.taketoday.jdbc.datasource.TransactionAwareDataSourceProxy)4 TransactionStatus (cn.taketoday.transaction.TransactionStatus)4 TransactionCallbackWithoutResult (cn.taketoday.transaction.support.TransactionCallbackWithoutResult)4 TransactionTemplate (cn.taketoday.transaction.support.TransactionTemplate)4 SQLException (java.sql.SQLException)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InOrder (org.mockito.InOrder)4 Connection (java.sql.Connection)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2