Search in sources :

Example 11 with Statement

use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.

the class DefaultDatabaseClientUnitTests method executeShouldBindNullValues.

@Test
void executeShouldBindNullValues() {
    Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
    DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build();
    databaseClient.sql("SELECT * FROM table WHERE key = $1").bindNull(0, String.class).then().as(StepVerifier::create).verifyComplete();
    verify(statement).bindNull(0, String.class);
    databaseClient.sql("SELECT * FROM table WHERE key = $1").bindNull("$1", String.class).then().as(StepVerifier::create).verifyComplete();
    verify(statement).bindNull("$1", String.class);
}
Also used : Statement(io.r2dbc.spi.Statement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 12 with Statement

use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.

the class DefaultDatabaseClientUnitTests method shouldApplyExecuteFunction.

@Test
void shouldApplyExecuteFunction() {
    Statement statement = mockStatement();
    MockResult result = mockSingleColumnResult(MockRow.builder().identified(0, Object.class, "Walter"));
    DatabaseClient databaseClient = databaseClientBuilder.executeFunction(stmnt -> Mono.just(result)).build();
    databaseClient.sql("SELECT").fetch().all().as(StepVerifier::create).expectNextCount(1).verifyComplete();
    verifyNoInteractions(statement);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) StepVerifier(reactor.test.StepVerifier) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) BDDMockito.times(org.mockito.BDDMockito.times) BDDMockito.when(org.mockito.BDDMockito.when) CoreSubscriber(reactor.core.CoreSubscriber) BDDMockito.verify(org.mockito.BDDMockito.verify) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BindMarkersFactory(org.springframework.r2dbc.core.binding.BindMarkersFactory) Result(io.r2dbc.spi.Result) Nullable(org.springframework.lang.Nullable) BDDMockito.doReturn(org.mockito.BDDMockito.doReturn) BDDMockito.verifyNoInteractions(org.mockito.BDDMockito.verifyNoInteractions) MockRow(io.r2dbc.spi.test.MockRow) BindTarget(org.springframework.r2dbc.core.binding.BindTarget) MockResult(io.r2dbc.spi.test.MockResult) MockRowMetadata(io.r2dbc.spi.test.MockRowMetadata) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InOrder(org.mockito.InOrder) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) Subscription(org.reactivestreams.Subscription) MockColumnMetadata(io.r2dbc.spi.test.MockColumnMetadata) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockResult(io.r2dbc.spi.test.MockResult) Statement(io.r2dbc.spi.Statement) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

Statement (io.r2dbc.spi.Statement)12 Test (org.junit.jupiter.api.Test)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 StepVerifier (reactor.test.StepVerifier)5 MockResult (io.r2dbc.spi.test.MockResult)4 BindTarget (org.springframework.r2dbc.core.binding.BindTarget)4 Connection (io.r2dbc.spi.Connection)3 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)3 Result (io.r2dbc.spi.Result)3 MockColumnMetadata (io.r2dbc.spi.test.MockColumnMetadata)3 MockRow (io.r2dbc.spi.test.MockRow)3 MockRowMetadata (io.r2dbc.spi.test.MockRowMetadata)3 Arrays (java.util.Arrays)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 BDDMockito.doReturn (org.mockito.BDDMockito.doReturn)3 BDDMockito.inOrder (org.mockito.BDDMockito.inOrder)3 BDDMockito.mock (org.mockito.BDDMockito.mock)3